PostgreSQL Scripts for Database Administration
List 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 MoreHow 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 MoreFind Missing Indexes in PostgreSQL with SQL
Apr 4, 2026 / · 3 min read · postgresql performance optimization indexing database pg_stat_user_tables pg_stat_all_tables ·How to Find Missing Indexes in PostgreSQL A missing index means PostgreSQL reads every row in a table to find what it needs. This is called a sequential scan. For small tables, that is fine. For large tables, it is slow and wastes CPU and I/O. PostgreSQL tracks sequential scans in the pg_stat_all_tables view. You can …
Read MoreList PostgreSQL Object Comments with SQL
Apr 4, 2026 / · 4 min read · postgresql administration schema database pg_description pg_statio_all_tables information_schema pg_class pg_index pg_namespace pg_proc ·List PostgreSQL Object Comments with SQL PostgreSQL allows you to attach plain-text comments to tables, columns, indexes, functions, and other database objects using the COMMENT ON command. These comments are stored in the system catalog and are visible in psql, pgAdmin, and any tool that reads pg_description. They are …
Read MoreDetect PostgreSQL Transaction ID Wraparound Risk
Apr 3, 2026 / · 4 min read · postgresql administration vacuum monitoring database pg_class pg_database pg_settings pg_stat_activity pg_stat_user_tables ·Detect PostgreSQL Transaction ID Wraparound Before It Causes Downtime PostgreSQL assigns a transaction ID (XID) to every write transaction. These IDs are 32-bit integers, which means they can only count up to about 2 billion. When the counter gets close to the limit, PostgreSQL must freeze old transaction IDs to …
Read MoreDetect Soft Delete Patterns in PostgreSQL
Apr 3, 2026 / · 5 min read · postgresql database administration performance autovacuum bloat information_schema pg_stat_user_tables ·Detecting Soft Delete Patterns in PostgreSQL Soft deletes are a common application pattern. Instead of removing a row with a DELETE statement, the application marks it as deleted by setting a column — typically deleted_at — to a non-null timestamp. The row stays in the table forever. The application simply filters it …
Read MoreFind PostgreSQL Tables That Need VACUUM FREEZE
Apr 2, 2026 / · 3 min read · postgresql administration vacuum maintenance database pg_class pg_settings pg_stat_activity ·Find PostgreSQL Tables That Need VACUUM FREEZE PostgreSQL uses transaction IDs (XIDs) to track which rows are visible to which transactions. Over time, these IDs age. When a table's oldest unfrozen XID gets too old, PostgreSQL triggers an aggressive autovacuum to freeze it. This is controlled by the …
Read More