- Documented replication topology
- Documented network topology
- Documented interface topology - including users, passwords, connection estimates, load balancers, connection proxies
- Documented procedure, schedule for failover and testing
- Documented procedure, schedule for disaster recovery and testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Magic words:
psql -U postgres
Some interesting flags (to see all, use -h
or --help
depending on your psql version):
-E
: will describe the underlaying queries of the\
commands (cool for learning!)-l
: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
- Postico client for mac
- pgcli - Postgres CLI with autocompletion and syntax highlighting
- pghero - Server and query performance dashboard
- PEV - Query planning / Explain analyze visualisation
- PostgreSQL's explain analyze made readable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
now()-pg_postmaster_start_time() "Uptime", now()-stats_reset "Since stats reset", | |
round(100.0*checkpoints_req/total_checkpoints,1) "Forced checkpoint ratio (%)", | |
round(np.min_since_reset/total_checkpoints,2) "Minutes between checkpoints", | |
round(checkpoint_write_time::numeric/(total_checkpoints*1000),2) "Average write time per checkpoint (s)", | |
round(checkpoint_sync_time::numeric/(total_checkpoints*1000),2) "Average sync time per checkpoint (s)", | |
round(total_buffers/np.mp,1) "Total MB written", | |
round(buffers_checkpoint/(np.mp*total_checkpoints),2) "MB per checkpoint", | |
round(buffers_checkpoint/(np.mp*np.min_since_reset*60),2) "Checkpoint MBps", | |
round(buffers_clean/(np.mp*np.min_since_reset*60),2) "Bgwriter MBps", |