PostgreSQL checklist¶
Copy this list into a pull request, design review or project kickoff and tick what applies. Rules are grouped by level and sorted by score (criteria). Each links to the file that explains it and cites its sources. Automatable names tools that can check the rule in CI (see the file's "How to enforce" section).
Also apply the general checklist.
This file is generated by python3 scripts/rank.py fix from the guidelines. Don't edit it by hand.
Strongly recommended (9–10)¶
-
PG-11(9) Test restores regularly, and check that the restored database works and contains the correct data. (specific/postgres) Automatable: pg_verifybackup, pgBackRestcheck. -
PG-16(9) Run a supported major version, apply each minor release soon after it ships, and upgrade to a newer major version before the current one reaches end of life. (specific/postgres)
Recommended (6–8)¶
-
PG-1(8) Declare integrity rules as constraints in the database: a primary key on every table,NOT NULLon most columns, and foreign key, unique and check constraints where the data needs them. (specific/postgres) -
PG-6(8) Create and drop indexes on tables in use withCREATE INDEX CONCURRENTLYandDROP INDEX CONCURRENTLY. (specific/postgres) Automatable: Squawk. -
PG-12(8) Back up production databases with continuous archiving, base backups plus archived WAL, so that you can restore to any point in time, not only to the last dump. (specific/postgres) Automatable: pgBackRestcheck. -
PG-13(8) Connect the application as a role that isn't a superuser and doesn't own the tables, and grant it only the privileges it needs; run migrations as a separate owner role. (specific/postgres) -
PG-2(7) Store points in time astimestamptz, nottimestamp. (specific/postgres) Automatable: Squawk. -
PG-5(7) Add indexes for the queries the application actually runs: find the costly ones withpg_stat_statements, check their plans withEXPLAIN ANALYZEon realistic data, and drop indexes that are never used. (specific/postgres) -
PG-7(7) Set a shortlock_timeoutat the start of each migration, and retry the migration when it times out. (specific/postgres) Automatable: Squawk. -
PG-8(7) Add foreign key and check constraints to existing tables asNOT VALID, then runVALIDATE CONSTRAINTin a separate transaction. (specific/postgres) Automatable: Squawk. -
PG-9(7) Put a connection pooler such as PgBouncer between the database and large numbers of clients, such as many app instances or serverless functions, instead of raisingmax_connections. (specific/postgres) -
PG-10(7) Keep transactions short, setidle_in_transaction_session_timeoutto end abandoned ones, and leave autovacuum on. (specific/postgres) -
PG-14(7) Usescram-sha-256password authentication over TLS, and have clients verify the server withsslmode=verify-full. (specific/postgres) -
PG-3(6) Generate keys with identity columns, such asid bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, instead ofserial. (specific/postgres) Automatable: Squawk. -
PG-4(6) Usetextfor strings, rather thanchar(n)or avarchar(n)with an arbitrary limit. (specific/postgres) Automatable: Squawk.
Conditional (1–5)¶
-
PG-15(5) When tenants share tables, isolate their rows with row security policies, and make sure the application role isn't the table owner or useFORCE ROW LEVEL SECURITY. (specific/postgres)