Home

Awesome

Useful DBA tools by Data Egret

83compat.sql

check_are_all_subscribed.sql

check_missing_grants.sql

check_strange_fk.sql

check_uniq_indexes.sql

List all tables which do not have UNIQUE CONSTRAINTs.

check_config.sql

This query is used for getting non default configuration parameters in PostgreSQL. For user/client sessions you can see modified parameters, but reset_val will contain value from configuration file (I hope). If you see (*) before config name it means that parameter has default value. If you see (c) after config name it means that parameter was changed for client session or by another reason (database, user, etc). If you see !!! after config name it means that parameter were changed in file but still not apllied. All fields in report are aligned by width for simplifying a compare procedures.

create_db_activity_view.sql

Creates more convenient VIEW around pg_stat_activity pg_catalog view. Shows all non idle queries running more then 100ms (optionally 500ms - see a comment in view DDL). Requires track_activities=enabled in postgresql.conf to display processes states correctly.

This view works with PostgreSQL version < 9.2, to use the view with 9.2 or higher please refer create_db_activity_view9.2.sql

Columns:

create_db_activity_view9.2.sql

Does the same for 9.2 and higher

create_query_stat_cpu_time_view.sql

Creates query_stat_cpu_time VIEW to display queries running >= 0.02 seconds (IO time is not taking into account). Require pg_stat_statements extension enabled and optionally track_io_timings enabled in postgresql.conf.

Columns:

Note: all queries which runtime less 0.02 seconds, accounts into dedicated 'other' query.

create_query_stat_io_time_view.sql

Creating query_stat_io_time VIEW for viewing queries with IO time more or equal 0.02 seconds. Also require pg_stat_statements and track_io_timings in postgresql.conf.

Columns:

Note: all queries which runtime less 0.02 seconds, accounts into dedicated 'other' query.

create_query_stat_log.sql

create_query_stat_time_view.sql

Creating query_stat_time VIEW for viewing queries with total runtime more or equal 0.02 seconds (time spent on block IO also included). Require enabled pg_stat_statements and track_io_timings in postgresql.conf.

Columns:

Note: all queries which runtime less 0.02 seconds, accounts into dedicated 'other' query.

create_slonik_set_full.sql

create slonik_set_incremental.sql

create_xlog_math_procedures.sql

This snippets create following funtions:

Usage: ???

db_activity.sql and db_activity9.2.sql

dirty_to_read_stat.sql

Some statistics for "dirty" buffers. Require pg_buffercache extensions.

Columns: relation - object name and schema which object belongs;

Udage: ???

generate_drop_items.sql

index_candidates_from_ssd.sql and index_candidates_to_ssd.sql

Display indexes which should be moved from/to SSD.

Columns:

Low d_w_rat value shows low disk reads with relatively high amount of changes inside relation (this behaviour influnces to the index permanent rebuilding, more changes in table, more changes in index). For displaing indexes which recommended move from SSD, a following conditions are used: display indexes with d_w_rat < 25 and tblsp = "ssd". High d_w_rat value shows high disk reads (bad) with relatively low amount of changes in the table. For displaing indexes which are recommended move on SSD, used following conditions: d_w_rat > 10, disk > 1000 and tblsp != "ssd".

index_disk_activity.sql

Display indexes disk reads statistics.

Columns:

Displaing only those indexes which total amount of disk blocks reads (disk column) more than 100 blocks.

indexes_with_null.sql

Show indexes with NULL data.

Columns:

Shows only indexes with statnullfrac > 0.5 and_size > 81920 bytes.

low_used_indexes.sql

Show indexes which low or not used.

Columns:

Show indexes with following conditions: (idx_scan / write_activity) < 0.01 and write_activity > 10000.

master_wal_position.sql

query_stat_counts.sql

Display query useful statistics: queries, number of calls, runtime, averages.

Columns:

All queries with following condition: (calls / sum(calls)) >= 0.01, are displaing in dedicated query whic named 'other'.

query_stat_cpu_time.sql, query_stat_io_time.sql, query_stat_rows.sql, query_stat_time.sql

Queries similar to query_stat_cpu_time, query_stat_io_time, query_stat_time VIEWS and displaing queries runtime with cpu and block IO accounting. Require pg_stat_statement and track_io_timings enabled in postgresql.conf.

Columns:

Note: all queries which runtime less 0.02 seconds, accounts into dedicated 'other' query.

redundant_indexes.sql

Show redundant indexes - indexes which are built with common column which is present in both indexes.

Columns:

seq_scan_tables.sql

Show tables with high amount of sequential scans.

Columns:

Only following tables are shown: with seq_scan > 0 and seq_tup_read > 100000

set_default_grants.sql

Setup DEFAUlT PRIVILEGES for all new object created by postgres for role_ro and role_rw roles.

role_ro: select on sequences; select on tables.

role_rw: select,usage on sequences; select,insert,update,delete on tables.

set_missing_grants.sql

Setup appropriate GRANTs for role_ro (SELECT) and role_rw (SELECT,INSERT,UPDATE,DELETE,USAGE) on tables, views and sequences in case when acl of these objecta are null or not appropriate by this snippet.

slave_wal_position.sql

Shows current WAL state: position received from master and replayed at this moment.

slony_tables.sql

Show tables list from _slony.sl_table

sync_tablespaces.sql

Find indexes which stored in different tablespace then their tables and move on indexes (ALTER INDEX indexname SET TABLESPACE tablespace) into tablespace where the parent table is stored.

table_candidates_from_ssd.sql and table_candidates_to_ssd.sql

Show tables which should be moved from SSD (high writes, low reads) or to SSD (low writes, high reads).

Columns:

Tables which should be moved from SSD: tblsp="ssd" and ratio < 20 (high amount pf writes and low reads)

Tables which should be moved to SSD: tblsp != "ssd" and ratio > 10 (low amount of writes, and high reads)

table_disk_activity.sql

Show disk activity for tables.

Columns:

Only that tables are displayed: with pg_stat_get_tuples_fetched > 100 and write > 10

table_index_write_activity.sql and table_write_activity.sql

Shows amount of index writes (table_index_write_activity.sql) and table writes (table_write_activity.sql).

Columns:

Conditions for table_index_write_activity.sql: total > 100

Conditions for table_write_activity.sql: total > 0