PostgreSQL Scripts for Database Administration
Monitor PostgreSQL Wait Events Using pg_stat_activity
May 17, 2026 / · 3 min read · pg_stat_activity wait events performance monitoring session monitoring administration ·Understanding PostgreSQL Wait Events for Performance Analysis Every active PostgreSQL backend is either executing work or waiting. When a session waits, PostgreSQL records the reason in pg_stat_activity using two columns: wait_event_type and wait_event. Aggregating these across all sessions gives a clear picture of …
Read MoreMonitor PostgreSQL Vacuum Progress with pg_stat_progress_vacuum
May 16, 2026 · 4 min read · pg_stat_progress_vacuum vacuum autovacuum performance monitoring administration ·Tracking Active Vacuum and Autovacuum Workers in PostgreSQL PostgreSQL vacuum is the maintenance process that removes dead tuples left behind by updates and deletes, reclaims storage, and prevents transaction ID wraparound. On active databases, autovacuum runs continuously in the background, but knowing whether it is …
Read MorePostgreSQL Physical Backups with pg_basebackup pg_basebackup takes a physical, binary-level snapshot of a running PostgreSQL cluster. Unlike pg_dump, which produces a logical export of one database at a time, pg_basebackup captures the entire data directory — all databases, configuration files, and enough WAL to make …
Read MoreMonitor PostgreSQL Table Cache Hit Ratio with SQL
May 14, 2026 / · 4 min read · pg_statio_user_tables cache performance shared_buffers administration ·Measuring PostgreSQL Table Cache Efficiency with pg_statio_user_tables PostgreSQL keeps frequently accessed data pages in shared_buffers to avoid hitting disk. When a backend reads a data block, PostgreSQL first checks shared_buffers; if the block is there, it counts as a heap hit. If it is not, PostgreSQL reads from …
Read MoreCheck Replica Identity Settings in PostgreSQL Logical replication in PostgreSQL requires each replicated table to have a replica identity. The replica identity tells PostgreSQL which columns to include in the WAL record for UPDATE and DELETE operations so the subscriber can identify the row being changed. If replica …
Read MoreHow to List Collations Available in PostgreSQL A collation defines the rules for sorting and comparing text. It controls how ORDER BY handles strings, whether a and A compare as equal, and how accented characters rank relative to unaccented ones. Every text column in PostgreSQL has a collation, either inherited from …
Read MoreHow to List Installed Extensions in PostgreSQL PostgreSQL extensions package additional functionality — data types, functions, operators, and index methods — that can be installed into a database with CREATE EXTENSION. Common examples include pg_stat_statements for query performance tracking, uuid-ossp for UUID …
Read MoreHow to List PostgreSQL Roles and Privileges PostgreSQL uses roles for both users and groups. A role with the LOGIN attribute is a user account. A role without LOGIN is typically a group role used to collect privileges that are then granted to login roles. Understanding which roles exist, what privileges they have, and …
Read MoreScrubbing Email PII from Your PostgreSQL Database When you copy a production database to a development or test environment, you must remove or anonymize personally identifiable information (PII). Email addresses are among the most common PII fields that need to be scrubbed. Leaving real email addresses in …
Read MoreAudit Single vs Multi-Column Indexes in PostgreSQL
Apr 16, 2026 / · 4 min read · postgresql administration indexing database pg_index pg_class pg_namespace ·Audit Single vs Multi-Column Indexes in PostgreSQL Not all indexes are created equal. A single-column index covers one column and is simple to reason about. A multi-column (composite) index covers two or more columns and can serve a wider range of queries — but only when the leading columns match the query filter. As a …
Read More