SQL-scripts

100+ SQL Scripts - PostgreSQL, MySQL, Google BigQuery, MariaDB, AWS Athena. DBA, Analytics, DevOps, performance engineering. Google BigQuery ML machine learning classification.

MIT License

Stars
387
Committers
2

SQL Scripts

git.io/SQL

Useful SQL scripts, split from DevOps Bash tools, for which this is now a submodule.

Hari Sekhon

Cloud & Big Data Contractor, United Kingdom

(you're welcome to connect with me on LinkedIn)

Inventory

DevOps / DBA

  • aws_athena_cloudtrail_ddl.sql - AWS Athena DDL to setup up integration to query CloudTrail logs from Athena
  • bigquery_*.sql - Google BigQuery scripts:
    • bigquery_billing_*.sql - billing queries for GCP usage eg. highest cost services, most used GCP products, recent charges etc.
    • bigquery_info_*.sql - information schema queries for datasets, tables, columns, partitioning, clustering etc.
  • mysql_*.sql:
    • MySQL / MariaDB queries for DBA investigating + performance tuning
    • mysql_info.sql - summary overview, useful to debug your mysql.user table auth effects
      • (shows intended USER() vs actual CURRENT_USER())
    • tested on MySQL 5.5, 5.6, 5.7, 8.0 and MariaDB 5.5, 10.x
  • postgres_*.sql:
    • PostgreSQL queries for DBA investigating + performance tuning
    • postgres_info.sql - big summary overview, recommend you start here
    • tested on PostgreSQL 8.4, 9.x, 10.x, 11.x, 12.x, 13.x

Analytics

  • bigquery_*.sql - Google BigQuery scripts:
    • bigquery_billing_*.sql - billing queries for GCP usage eg. highest cost services, most used GCP products, recent charges etc.
    • bigquery_info_*.sql - information schema queries for datasets, tables, columns, partitioning, clustering etc.
    • analytics/bigquery_*.sql - ecommerce queries and BigQuery ML machine learning classification logistic regression models and purchasing predictions
    • for more BigQuery examples, see Data Engineering demos

DevOps SQL tooling

You can quickly test the PostgreSQL / MySQL scripts using postgres.sh / mysqld.sh / mariadb.sh in the DevOps Bash tools repo, which boots a docker container and drops straight in to a mysql / psql shell with this directory mounted at /sql and used as $PWD for fast easy sourcing eg.

postgres:

\i /sql/postgres_query_times.sql
\i postgres_query_times.sql

mysql:

source /sql/mysql_sessions.sql
\. mysql_sessions.sql

Related scripts

Stargazers over time

git.io/SQL

More Core Repos

Knowledge

DevOps Code

Containerization

CI/CD

DBA - SQL

DevOps Reloaded

Templates

Misc

The rest of my original source repos are here.

Pre-built Docker images are available on my DockerHub.