PostgreSQL Scripts for Database Administration
Inspect PostgreSQL Sequences with the pg_sequences View
Jun 20, 2026 / · 6 min read · postgresql database administration sql queries sequences pg_sequences catalogs postgres dba ·Inspect PostgreSQL Sequences with the pg_sequences View pg_sequences is the catalog-backed view that exposes every sequence in the current database in one readable row each — start_value, min_value, max_value, increment_by, cache_size, cycle, and the all-important last_value. It turns a scattered set of per-sequence …
Read MoreTrack Two-Phase Commit State with pg_prepared_xacts
Jun 19, 2026 / · 7 min read · postgresql database administration sql queries transactions two-phase commit pg_prepared_xacts postgres dba ·Track Two-Phase Commit State with pg_prepared_xacts A prepared transaction that never gets committed or rolled back is one of the quieter ways a PostgreSQL database degrades. It keeps holding locks, it pins the transaction-ID horizon so VACUUM cannot reclaim dead rows, and nothing in normal monitoring screams about it. …
Read MoreMonitor PostgreSQL ANALYZE Progress with pg_stat_progress_analyze
Jun 18, 2026 / · 6 min read · postgresql database administration sql queries statistics progress reporting pg_stat_progress_analyze postgres dba ·Monitor PostgreSQL ANALYZE Progress with pg_stat_progress_analyze Running ANALYZE on a multi-hundred-gigabyte table and wondering whether it is halfway done or barely started is a common operational question with, until recently, no good answer. pg_stat_progress_analyze answers it: a live view that reports the current …
Read MoreQuery PostgreSQL I/O Statistics with pg_stat_io
Jun 17, 2026 / · 6 min read · postgresql database administration sql queries statistics io pg_stat_io postgres dba ·Query PostgreSQL I/O Statistics with pg_stat_io An I/O spike that nobody can attribute is a frustrating thing to chase. Was it autovacuum, a checkpoint, a bulk load, or ordinary client queries? Before PostgreSQL 16 the answer required stitching together several partial views; pg_stat_io gives a single cluster-wide …
Read MoreTRUNCATE vs DELETE vs DROP: Remove Rows Fast in PostgreSQL
Jun 16, 2026 / · 7 min read · postgresql database administration sql queries truncate delete maintenance postgres dba ·TRUNCATE vs DELETE vs DROP: Remove Rows Fast in PostgreSQL Where DELETE removes rows one logical version at a time and leaves the cleanup to vacuum, TRUNCATE discards an entire table's contents almost instantly and reclaims the space immediately, and DROP removes the table itself. Picking the wrong one for "empty this …
Read Moretimestamptz and tzdata: Avoid Shifted PostgreSQL Timestamps
Jun 15, 2026 / · 7 min read · postgresql database administration sql queries data types time zones timestamptz postgres dba ·timestamptz and tzdata: Avoid Shifted PostgreSQL Timestamps PostgreSQL stores every timestamptz value as UTC and converts it to the session's time zone only at display time. That design is correct and elegant — until a tzdata update changes the offset rules for a region, at which point timestamps inserted under the old …
Read MoreBack Up All PostgreSQL Databases with pg_dumpall
Jun 9, 2026 / · 6 min read · pg_dumpall backup and recovery cluster backup global objects administration ·Back Up All PostgreSQL Databases with pg_dumpall Before a major-version upgrade or a disaster-recovery rehearsal, a DBA needs a single artifact that captures the whole cluster: every database, plus the global objects that live outside any one database. pg_dumpall produces exactly that — one plain-SQL script that …
Read MorePostgreSQL Advisory Locks with pg_advisory_lock
PostgreSQL Advisory Locks with pg_advisory_lock Two scheduled jobs fire at the same minute and both try to process the same nightly batch. Nothing in the data stops them — there is no single row to lock, because the work has not produced rows yet. Row and table locks are the wrong tool here. What you want is a named …
Read MoreList All PostgreSQL Triggers with Their State
List All PostgreSQL Triggers with Their State A disabled trigger is invisible until something it should have done goes missing. The audit row that never got written, the derived column that stopped updating, the constraint check that silently stopped firing — each traces back to a trigger left in the disabled state …
Read MorePostgreSQL Column-Level Permissions Audit Query
Jun 6, 2026 / · 6 min read · column_privileges information_schema permissions security audit administration ·PostgreSQL Column-Level Permissions Audit Query Which roles can read which columns? Table-level grants are easy to list, but they hide a finer layer of access. A role denied SELECT on a table can still hold SELECT on two of its columns, and that is exactly where personal data quietly stays reachable after a wider grant …
Read More