Visualize PostGIS index using Gevel in Postgres 9.6:
git clone git://sigaev.ru/gevel
cd gevel
git checkout bd8b8b031a8049a6e7c18c00946bfbd99d75d27f
USE_PGXS=1 make
sudo USE_PGXS=1 make install
psql -f /usr/share/postgresql/9.6/contrib/gevel.sql
Visualize PostGIS index using Gevel in Postgres 9.6:
git clone git://sigaev.ru/gevel
cd gevel
git checkout bd8b8b031a8049a6e7c18c00946bfbd99d75d27f
USE_PGXS=1 make
sudo USE_PGXS=1 make install
psql -f /usr/share/postgresql/9.6/contrib/gevel.sql
| WITH | |
| write_adjust AS ( | |
| -- change the below to 1.0 if pg_stats goes back to | |
| -- the creation of the database | |
| SELECT 0.0 AS adjustment | |
| ), | |
| index_usage AS ( | |
| SELECT sut.relid, | |
| current_database() AS database, | |
| sut.schemaname::text as schema_name, |
| -- check for containment | |
| -- i.e. index A contains index B | |
| -- and both share the same first column | |
| -- but they are NOT identical | |
| WITH index_cols_ord as ( | |
| SELECT attrelid, attnum, attname | |
| FROM pg_attribute | |
| JOIN pg_index ON indexrelid = attrelid | |
| WHERE indkey[0] > 0 |
| -- check for exact matches | |
| WITH index_cols_ord as ( | |
| SELECT attrelid, attnum, attname | |
| FROM pg_attribute | |
| JOIN pg_index ON indexrelid = attrelid | |
| WHERE indkey[0] > 0 | |
| ORDER BY attrelid, attnum | |
| ), | |
| index_col_list AS ( | |
| SELECT attrelid, |
| WITH table_scans as ( | |
| SELECT relid, | |
| tables.idx_scan + tables.seq_scan as all_scans, | |
| ( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes, | |
| pg_relation_size(relid) as table_size | |
| FROM pg_stat_user_tables as tables | |
| ), | |
| all_writes as ( | |
| SELECT sum(writes) as total_writes | |
| FROM table_scans |
| WITH btree_index_atts AS ( | |
| SELECT nspname, relname, reltuples, relpages, indrelid, relam, | |
| regexp_split_to_table(indkey::text, ' ')::smallint AS attnum, | |
| indexrelid as index_oid | |
| FROM pg_index | |
| JOIN pg_class ON pg_class.oid=pg_index.indexrelid | |
| JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace | |
| JOIN pg_am ON pg_class.relam = pg_am.oid | |
| WHERE pg_am.amname = 'btree' | |
| ), |
| WITH btree_index_atts AS ( | |
| SELECT nspname, relname, reltuples, relpages, indrelid, relam, | |
| regexp_split_to_table(indkey::text, ' ')::smallint AS attnum, | |
| indexrelid as index_oid | |
| FROM pg_index | |
| JOIN pg_class ON pg_class.oid=pg_index.indexrelid | |
| JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace | |
| JOIN pg_am ON pg_class.relam = pg_am.oid | |
| WHERE pg_am.amname = 'btree' | |
| ), |