Configuration & Cluster Basics
PostgreSQL runs as a database cluster — a single data directory (PGDATA) managed by one server instance that can host multiple databases.
Initializing and controlling a cluster#
Initialize a new cluster with initdb (with data checksums enabled for corruption detection):
initdb -D /var/lib/postgresql/data --data-checksums --encoding=UTF8
Manage the server process with pg_ctl (or systemctl when using OS packages):
pg_ctl -D /var/lib/postgresql/data status
pg_ctl -D /var/lib/postgresql/data reload
pg_ctl -D /var/lib/postgresql/data restart -m fast
Always prefer
-m fast(rolls back active transactions cleanly) over-m immediate(unclean shutdown requiring crash recovery).
Versioning#
PostgreSQL uses MAJOR.MINOR versioning (for example, 17.2):
- Minor releases (
17.1->17.2) are bug/security fixes only — binary drop-in upgrade, no data conversion needed. - Major releases (
16->17) change internal catalog/storage formats — requirepg_upgradeor logical dump/restore.
Check the running version:
SELECT version();
SHOW server_version;Configuration & parameter contexts#
Parameters can be set in postgresql.conf, via ALTER SYSTEM (written to postgresql.auto.conf), per database/role, or per session.
-- Persist a setting in postgresql.auto.conf and reload
ALTER SYSTEM SET shared_buffers = '4GB';
SELECT pg_reload_conf();
-- Reset a parameter back to default
ALTER SYSTEM RESET shared_buffers;
Every setting has a context that defines when changes take effect:
| Context | How to apply |
|---|---|
postmaster | Requires a full server restart (shared_buffers, max_connections). |
sighup | Takes effect on pg_reload_conf() (work_mem default, log_*, autovacuum_*). |
superuser / user | Can be changed per session (SET work_mem = '64MB';). |
Inspect modified settings and whether a restart is pending:
SELECT name, setting, unit, source, pending_restart
FROM pg_settings
WHERE source <> 'default'
ORDER BY name;