PostgreSQL single-server installation (production-ready)
PostgreSQLLevel: BeginnerDuration: 30–45 minProduction-ready PostgreSQL installation on a single server from the PGDG repository: separate data directory, data checksums, settings calculated from RAM/CPU, secure access (peer + scram-sha-256), logging, pg_stat_statements, firewall and SELinux. At the end you have a running, verified cluster and a backup/monitoring checklist.
In streaming replication the primary is installed with this guide; on the standbys only "Operating system preparation" is done, the rest is in pg-streaming. Do not create a cluster with this guide on Patroni nodes (Patroni runs initdb itself) → pg-patroni.
Topology: 1 server
Before you start
- The server runs a supported operating system and is up to date. Time zone and NTP (chrony) are correct.
- RAM and CPU match the values in the form (the settings are calculated from them).
- A separate disk/LV is mounted for …, persistently (fstab), with enough free space. …The separate disk for WAL is mounted at … as well.… The file system is XFS or ext4.
- Hostname … is set and resolves to its own IP; the application network (…) is reachable.
- The server can reach the PostgreSQL repository (download.postgresql.org…, apt.postgresql.org…) over HTTPS, or an internal mirror is configured.
- Port … is free (no other service uses it).
- The operating system's own PostgreSQL package is not installed (it conflicts with PGDG).
- You are logged in as root or with sudo rights; the maintenance window and fallback plan (server snapshot) are ready.
Phases of the guide
- Operating system preparation — Hostname and system update · Locale check · Kernel settings (sysctl) · Apply the sysctl settings · Disable Transparent Huge Pages
- Installing the PostgreSQL software — Add the PGDG repository · Add the PGDG repository · Install the PostgreSQL server software
- Creating the data directory and the cluster — Create the directories and set permissions · Define the SELinux labels · Create the cluster (initdb) · Create the cluster (pg_createcluster)
- Configuration — Write the settings file · Enable the conf.d directory · Access rules (pg_hba.conf)
- Starting the service — Reserve huge pages · Enable and start the service · Open the port in the firewall
- Users and database — Set a password for the postgres user · Application user and database · Set a password for the application user · pg_stat_statements extension
- Verification — Check that the settings are applied · Remote connection test · Check the log file
- Post-installation — Set up backups (mandatory) · Connect monitoring