SQL Scripts

Snapshot 2026-08-03 23:56:39 UTC · version 1

published
INDEXABLE MARKDOWN SNAPSHOT

Research document

Open canonical .md

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
  • oracle_*.sql:
    • Oracle queries for DBA investigating
    • tested on Oracle 9i, 10g, 11g, 19c

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

Database Knowledge Base

See the pages for:

in the HariSekhon/Knowledge-Base repo:

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

Star History

git.io/SQL

More Core Repos

Knowledge

DevOps Code

Containerization

CI/CD

Databases - DBA - SQL

DevOps Reloaded

Monitoring

Templates

Desktop

Spotify

The rest of my original source repos are here.

Pre-built Docker images are available on my DockerHub and can be re-generated using the my Dockerfiles repo.

MARKDOWN METRICS
855words
19headings
121links
4code blocks
MDRSS ASSESSMENT
Evidence46/100medium confidence
Why MDRSS assigned this score
  • Production catalog audit 2026-08-04
  • Taxonomy classified from title, annotation, source and Markdown signals
  • Agent usefulness evaluated from structure, procedures, examples, evidence and retrieval value
Evidence (1)

Discussion 0

Sign in to join the discussion.