PostgreSQL Scripts for Database Administration
Scrubbing 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 MorePostgreSQL Database Statistics with pg_stat_database
Apr 15, 2026 / · 4 min read · postgresql administration monitoring database performance pg_stat_database ·Monitor PostgreSQL Databases with pg_stat_database PostgreSQL tracks activity at the database level in the pg_stat_database view. Every database on the server has a row, and each row contains counters for commits, rollbacks, cache hits, disk reads, deadlocks, temp file usage, and more. This is one of the first places …
Read MoreCancel vs Terminate PostgreSQL Backends Explained
Cancel vs Terminate PostgreSQL Backends: What Every DBA Should Know PostgreSQL gives you two tools for dealing with problem backends: pg_cancel_backend() and pg_terminate_backend(). They sound similar but behave very differently. Using the wrong one can disrupt users unnecessarily, or leave a problematic connection in …
Read MoreList All Schemas in Your PostgreSQL Database
How to List All Schemas in a PostgreSQL Database A PostgreSQL database can contain multiple schemas. Schemas act as namespaces that group tables, views, functions, and other objects. In a fresh database you will find public and a set of system schemas. In a larger application database you may find dozens of application …
Read MoreList PostgreSQL Partitioned Tables with SQL
Apr 9, 2026 / · 4 min read · postgresql administration partitioning database pg_class pg_namespace information_schema pg_inherits ·How to List PostgreSQL Partitioned Tables PostgreSQL table partitioning splits a large table into smaller physical pieces called child partitions. This improves query performance and simplifies data lifecycle management. But as a DBA, you need a quick way to see which tables in your database use partitioning — and …
Read MoreFind PostgreSQL Tables Without a Primary Key
How to Find PostgreSQL Tables Without a Primary Key A missing primary key is one of the most common and damaging database design oversights. Without a primary key, PostgreSQL has no reliable way to uniquely identify a row. This causes problems with logical replication, ORM frameworks, and application-level updates or …
Read MoreList All Views in a PostgreSQL Database with SQL
Apr 7, 2026 / · 3 min read · postgresql administration schema database information_schema pg_views pg_matviews pg_depend ·How to List All Views in a PostgreSQL Database Views are saved SQL queries stored in the database. A production database can accumulate dozens or hundreds of views over time — many created by developers, some by tools, and some that are no longer used. Knowing what views exist, which schema they belong to, and what …
Read MoreList PostgreSQL Enum Types and Their Values with SQL
Apr 6, 2026 / · 4 min read · postgresql administration schema database data types pg_type pg_enum information_schema pg_namespace ·How to List All Enum Types in a PostgreSQL Database PostgreSQL supports user-defined enum types — a fixed ordered set of string values stored efficiently as integers. Enums are common in application schemas for columns like status, role, or priority. Once created, their allowed values are managed in the database …
Read MoreList Foreign Key Constraints in PostgreSQL
Apr 5, 2026 / · 4 min read · postgresql administration schema database pg_constraint information_schema ·List Foreign Key Constraints in PostgreSQL Foreign key constraints enforce referential integrity between tables. They guarantee that a value in one table's column always has a matching row in another table. Knowing which foreign keys exist — and how they are defined — is essential before dropping tables, renaming …
Read More