PostgreSQL Scripts for Database Administration
Audit Row-Level Security Policies with pg_policies
Aug 31, 2026 / · 11 min read · postgresql database administration sql queries row-level security pg_policies access control security catalogs postgres dba ·Audit Row-Level Security Policies with pg_policies pg_policies turns a table's row-level security setup — however many CREATE POLICY statements are scattered across migration files — into one queryable inventory: one row per policy, with the roles it binds to, the command it governs, and the boolean expressions doing …
Read MoreList PostgreSQL Materialized Views with pg_matviews
Aug 3, 2026 / · 9 min read · postgresql database administration sql queries materialized views pg_matviews refresh materialized view catalogs performance postgres dba ·List PostgreSQL Materialized Views with pg_matviews A materialized view carries no built-in warning label for staleness. Nothing about the row itself changes when the underlying tables mutate underneath it — a sales dashboard or a cached report join keeps returning last week's numbers with the same confidence as this …
Read MoreAudit PostgreSQL Authentication with pg_hba_file_rules
Jul 20, 2026 / · 8 min read · postgresql database administration sql queries authentication pg_hba_file_rules pg_hba.conf security catalogs postgres dba ·Audit PostgreSQL Authentication with pg_hba_file_rules Validating a pg_hba.conf edit before trusting it in production usually means reading the raw file line by line and hoping the parser interprets every rule the way it looks on screen. pg_hba_file_rules skips that guesswork — it is a system view that shows exactly …
Read MoreMonitor Last VACUUM Runs with pg_stat_user_tables
Jul 12, 2026 / · 8 min read · postgresql database administration sql queries vacuum autovacuum pg_stat_user_tables dead tuples postgres dba ·Monitor Last VACUUM Runs with pg_stat_user_tables A table's dead tuple count climbing while last_autovacuum stays weeks old isn't noise — it's the clearest sign autovacuum is falling behind, and pg_stat_user_tables is where that gap becomes visible in a single query, without tailing logs or guessing at a schedule. …
Read MoreQuery PostgreSQL Tablespace Info with pg_tablespace
Jul 3, 2026 / · 8 min read · postgresql database administration sql queries tablespaces pg_tablespace storage catalogs postgres dba ·Query PostgreSQL Tablespace Info with pg_tablespace What tablespaces exist in this cluster, who owns each one, and where do their files actually live on disk? pg_tablespace answers all three: it holds one row per tablespace with the owner OID, access control list, storage options, and — via pg_tablespace_location() — …
Read MoreList PostgreSQL Functions with pg_proc
Jul 2, 2026 / · 9 min read · postgresql database administration sql queries functions pg_proc catalogs postgres dba ·List PostgreSQL Functions with pg_proc Where information_schema.routines delivers a SQL-standard view of functions and procedures — portable across databases but deliberately incomplete — pg_proc gives the full PostgreSQL catalog row: language, source code, argument modes, cost estimates, and the prokind flag that …
Read MoreInspect 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 More