psql Best Practices
Safe habits for interactive SQL, GUI clients, and scripted checks against production PostgreSQL.
Search across all documentation pages
Safe habits for interactive SQL, GUI clients, and scripted checks against production PostgreSQL.
app_ro) for exploration. No INSERT/UPDATE/DELETE on production human paths.application_name to identify humans. PGAPPNAME=psql-alice in jump box profiles.sslmode=verify-full when CA is manageable.~/.pgpass with 600 perms or a vault CLI.LIMIT unbounded exploratory SELECTs. Pair with ORDER BY when order matters.\timing for performance investigations. Follow with EXPLAIN on staging before prod ANALYZE.SELECT * on wide tables in prod. Name columns explicitly; JSONB rows are expensive.BEGIN READ ONLY for multi-statement exploration. Prevents accidental writes in same session.statement_timeout on human roles. 30s-120s typical for ad-hoc SQL.-v ON_ERROR_STOP=1 in all CI psql scripts. Partial success is worse than loud failure.\copy over server path COPY for operators. Fewer superuser file privileges.CREATE INDEX CONCURRENTLY cannot.PGAPPNAME. Appears in pg_stat_activity during deploy smoke tests.fix.sql on laptop is not a runbook.idle_in_transaction_session_timeout mandatory.\d, \conninfo, \timing reduce magic clicks.pg_dump from prod to laptop is a data breach path.Through controlled migration pipelines and approved break-glass roles - not default GUI or psql profiles.
psql for automation and precise control; GUI for schema visualization. SMEs should excel at both with same safety rules.
Stack versions: This page was written for PostgreSQL 18.4 (stable 18, maintenance 17), pgvector 0.8+, PgBouncer 1.x, Patroni 3.x, and PostGIS 3.5+.
Reviewed by Chris St. John·Last updated Jul 18, 2026