Installing PostgreSQL from apt.postgresql.org for Debian and Ubuntu servers
The PostgreSQL Global Development Group (PGDG) apt repository gives Debian and Ubuntu servers current PostgreSQL major versions that the distribution's own archive often lags behind. Platform and DBA teams use it when they need a supported release, a specific major version chosen for an application or upgrade plan, or several majors on one host. Before choosing a version, check the support window. The supported majors covered by the researched facts are 18 (final release November 14, 2030), 17 (to November 8, 2029), 16 (to November 9, 2028), 15 (to November 11, 2027) and 14 (to November 12, 2026). Major versions 13 and earlier are unsupported, so new builds should not start on them.
Plan the support dates into your operating calendar. PostgreSQL releases one major version about once a year and supports each for five years after its initial release. Minor releases arrive at least once every three months, and they never change the on-disk storage format, so patching is an executable replacement followed by a restart. Schedule that routine as a recurring task, and confirm with your change board how quickly a minor release must be applied to meet your own patch policy. Major versions need a planned upgrade, which the upgrade section covers. Also confirm the license terms with your legal team. PostgreSQL uses the PostgreSQL License, a permissive license similar to the BSD or MIT licenses, so the software itself carries no licensing fee, but any commercial extensions or tooling you add may carry their own terms.
Use the PostgreSQL versioning policy as the reference for dates and the PostgreSQL license page for license wording. Record which major version each server runs and its end-of-support date in your asset inventory. A fleet that mixes 14 and 18 will need two upgrade tracks, and the older track will reach end of support first. Confirm the dates against the current policy before you commit a timeline, since the page reflects the researched facts at the time of writing.
Which install path fits your servers
The packages shipped with your Debian or Ubuntu release are the simplest path and the one your existing patch tooling already covers. The major version is fixed by the release you run, so you get whatever PostgreSQL the distribution maintainers chose for that cycle, and you cannot pick a newer major version from the same repository without changing the operating system or adding another source. This suits a single host where the application team has already validated the version the distribution provides.
- Version currency: the major version is tied to the OS release and may lag the newest PostgreSQL releases.
- Patching: security and minor updates arrive through the normal
apt upgradecycle, which keeps the process familiar for operations staff. - Side by side versions: running a second major version on the same host is possible but adds packaging work that you must plan yourself.
- Support horizon: check the PostgreSQL support window for the version you receive against your own retirement schedule.
- Upgrades: a major upgrade usually means moving to a new OS release or a second cluster, so plan that work before you commit.
Before you choose this path, confirm with your distribution which PostgreSQL major version each release ships and whether it is still within the PostgreSQL support window.
The PostgreSQL Global Development Group (PGDG) repository at apt.postgresql.org publishes current major versions for Debian and Ubuntu. The automated script configures the signing key and the repository source for you, and then you install the major version you need by package name. This path gives you a choice of major version independent of the OS release, which is the usual choice for a single host that needs a version newer than its distribution provides.
- Version currency: you pick the major version and can move to a newer one when your planning requires it.
- Patching: minor releases come from the PGDG repository, so add it to your patch scope and confirm your tooling pulls from it.
- Repository trust: verify the signing key and source file the script creates against the instructions on the repository site.
- Coexistence: the repository is designed so several major versions can be installed, with
postgresql-commonmanaging clusters. - Ownership: someone must watch for end of support dates and schedule the move to the next major version.
After running the script, confirm which source each installed package comes from before you rely on the version for production.
A manual setup adds the PGDG repository by hand: you write the source file, import the signing key and set the pinning yourself instead of running the automated script. Teams choose this when their hosts are built from a standard image, when security policy requires each repository and key to be reviewed before it is added, or when the same configuration must be written into tooling. The result is the same repository, but your team owns each step and must reproduce it consistently on every host.
- Control: every key, source entry and pin is visible and reviewable in your change records.
- Consistency: the configuration must match exactly across hosts, so drift between servers is the main risk.
- Patching: the repository must stay in your scheduled update scope, or hosts silently stop receiving minor releases.
- Key rotation: the signing key and source file need an owner who tracks changes to the repository.
- Documentation: record the steps so a rebuilt host can be brought to the same state.
Compare your manual steps with the script's output on a test host to confirm nothing is missing before you roll the change out.
When you run more than one major version on the same host, for example during a staged upgrade or for applications that need different versions, the repository path matters more. The postgresql-common tooling lets each major version run its own cluster, with its own data directory, port and service unit, and it provides commands for creating and managing those clusters. The design choice is less about the install and more about how long each version stays on the host and who owns its lifecycle.
- Version currency: each major version has its own support end date, so track them separately.
- Ports and clusters: assign distinct ports and confirm which cluster each application connects to.
- Patching: minor updates apply to each installed major version, so each one must be in the patch plan.
- Retirement: remove a retired major version only after its cluster is migrated and verified.
- Resource use: each running cluster consumes memory and disk, which affects host sizing.
Before you run two versions on one host, write down which cluster is primary for each application and when the older one will be retired.
A fleet of servers is usually built and kept in step by configuration tooling such as Ansible, Puppet or a similar system. For this situation, the install path should be a declared state: the same repository source, key and package versions applied to every host, with changes reviewed and rolled out in order. The advantage is repeatability and an audit trail, but the tooling itself becomes a dependency that must be maintained with the database.
- Repeatability: one role or manifest defines the repository and package set for every host.
- Version pinning: decide whether the fleet follows the newest minor release automatically or waits for a tested window.
- Drift control: manual changes on hosts should be brought back into the code, or the next run overwrites them.
- Staged rollout: update replicas or a canary host before the primary when minor releases arrive.
- Ownership: name the team that merges and approves changes to the repository configuration.
Before you standardize a fleet on one path, test the role against a host that matches your production image and confirm it applies cleanly twice in a row.
Configuration options and when each fits
This table compares the pg_createcluster choices that postgresql-common makes on Debian and Ubuntu, with the file locations and service names each one produces. Read it before creating the first cluster, because several of these settings are expensive to change once data is loaded.
| Option | What it controls | When it fits | What is hard to change later |
|---|---|---|---|
| Major version argument | Which PostgreSQL major version binaries and configuration template the cluster uses | Pin the version you intend to run in production, such as the currently supported majors listed in the versioning policy | Moving to another major needs a dump and restore, pg_upgrade, or logical replication |
| Cluster name argument | Names the cluster, which sets the service name, the data path and the config path together | Use a clear name such as main for a single cluster, or a descriptive name when one host runs several clusters | Renaming means recreating the cluster or editing several paths and service references by hand |
| Data directory option | Where the data files live, often a dedicated mount for WAL and data separate from the OS disk | Choose it when storage is provisioned in advance, so data sits on the volume your storage plan describes | Moving data later requires stopping the cluster and copying files or reconfiguring the path |
| Port option | The TCP port the cluster listens on | Assign a distinct port per cluster when several major versions run side by side on one host | Changing the port is simple, but clients, pooler configs and firewall rules must be updated together |
| Data checksums (--data-checksums) | Whether page checksums are written at initdb so corruption is detected on read | Enable it for new clusters where corruption detection matters; confirm the setting with your storage team | Checksums are set at cluster creation and cannot be turned on later without rebuilding or an offline procedure |
| Locale and encoding | Collation and character encoding used for text sorting and storage | Set the locale your application data and sort order require, typically UTF-8 for new deployments | Changing collation or encoding later affects indexes and sorting and generally means a dump and reload |
| postgresql.conf and pg_hba.conf paths | Server settings and client authentication rules, stored under the per-cluster config directory | Edit these per cluster, so each major version keeps its own settings during parallel running | Settings migrate only if you copy them; authentication rules need review after any upgrade |
| Service naming per version | Systemd unit names such as the postgresql service combined with the version and cluster name | Use the versioned service names in scripts and monitoring so each cluster is controlled separately | Automation, backup jobs and monitoring that reference old unit names break silently after a change |
How to add the repository and create a cluster
This sequence takes a Debian or Ubuntu server from a confirmed OS release to a running PostgreSQL cluster that starts on boot and accepts a local connection. Each step ends with a check, so the team knows the repository, package and cluster are in place before anything depends on them.
Confirm the OS release and PostgreSQL version
The platform engineer records the distribution and release with
lsb_release -aor by reading/etc/os-release, then checks the PostgreSQL versioning policy to choose a supported major version. As of the researched facts, versions 14 through 18 are supported, with 14 ending November 12, 2026, so a new build should normally start on 17 or 18. Confirm the release codename against the PGDG instructions before continuing. The step is complete when the team has written down the OS codename, the chosen major version and its end-of-life date.Install the PGDG repository with the automated script
Run the apt.postgresql.org automated repository script as root, which installs the signing key and the source list for the PGDG repository. Confirm the exact script name and command for your release on the PGDG Debian and Ubuntu page before running it, because the script location can change. Then run
apt updateand check that the PostgreSQL repository appears in the output withapt-cache policy postgresql-18or the version you chose. The step is done when the candidate version for your chosen package is listed from the PGDG source rather than only from the distribution archive.Install the chosen postgresql-NN package
Install the server package for the major version you selected, for example
apt install postgresql-17, which pulls in thepostgresql-commontooling that manages clusters. The installer normally creates a default cluster on first install, so the operator should check the output and then list clusters withpg_lsclustersbefore creating another one. Confirm the package name and any extra client packages on the PGDG page for your release. The step is complete whenpg_lsclustersshows the expected version and the installed binaries report the same major version withpostgres --version.Create and start a named cluster
Use
pg_createclusterto build a cluster with a name that describes its purpose and environment, and pass the data directory and port only if your storage layout requires it. Start it withpg_ctlclusterorsystemctl start postgresql@NN-name. Naming the cluster explicitly matters once several major versions run on one host, since each cluster keeps its own configuration under/etc/postgresqland data under/var/lib/postgresql. The step is done whenpg_lsclustersreports the cluster with status online and the expected port.Set authentication and test a local connection
Before any application connects, the administrator sets the password for the postgres role or creates a named administrative role, and confirms that
password_encryptionisscram-sha-256in the cluster configuration. Reviewpg_hba.confso that only the intended local and network sources are allowed. Then connect withpsqlas the administrative role and runSELECT version();to confirm the server responds. The step is complete when the query returns the expected major version and a failed connection from an unlisted source is refused.Enable the service and confirm it survives a restart
Confirm the systemd unit for the cluster is enabled so it starts after a reboot, which the postgresql-common packaging normally handles for clusters with the autostart setting. Check that setting in the cluster configuration, then run
systemctl is-enabledon the unit. Restart the host in a maintenance window, or restart the unit alone in a test environment, and rerunpg_lsclustersand thepsqlcheck. The step is done when the cluster returns online without manual action and the same connection test passes.Record the layout for later upgrades and patching
Write down the installed packages, the cluster names, the data directories and the owning change record so later minor updates and major upgrades start from known facts. Minor releases do not change the storage format, but a major upgrade still needs the old and new binaries side by side, so the record should name every installed major version. Ask the PostgreSQL upgrade documentation owner or your own runbook owner to confirm the procedure for your chosen path before the first upgrade is scheduled. The step is complete when the record matches
pg_lsclustersanddpkg -l | grep postgresqloutput from the host.
How postgresql-common runs several major versions side by side
The package layout is what makes side-by-side versions workable. Each major version installs its server binaries under /usr/lib/postgresql/<version>/bin. Each cluster keeps its data directory under /var/lib/postgresql/<version>/<cluster> and its configuration under /etc/postgresql/<version>/<cluster>, where postgresql.conf, pg_hba.conf and pg_ident.conf live. Because binaries, data and configuration are separated by major version and cluster name, clusters of different majors can run on one host without sharing files. The wrapper commands in postgresql-common select the correct binary and paths for each cluster. Confirm these paths for your package version by reading the file list of the installed package and the output of pg_lsclusters on a test host before you script anything against them.
Day-to-day management goes through a small set of commands. pg_lsclusters lists each cluster with its version, name, port, status, owner and data directory, which makes it the first check on any host. pg_createcluster creates a cluster, and pg_ctlcluster starts, stops, restarts, reloads and promotes a named cluster by version and name. pg_upgradecluster moves an existing cluster to a newer major version using the pg_upgrade method. Test it on a copy of a production cluster first, and confirm in your package version whether the old cluster is kept for rollback, how it handles the new cluster's configuration, and which systemd unit names the clusters use. The rules for choosing an upgrade method still come from the PostgreSQL upgrade documentation, not from the wrapper.
Port and resource conflicts are the problems most likely to appear once a second cluster is added. Each cluster listens on the port set by port in its own postgresql.conf. postgresql-common assigns ports at creation, but a port can still collide with another service or be set by hand to a value already in use, so check pg_lsclusters after every create and record port assignments in your change log. Resource conflicts matter more. Each running cluster allocates its own shared memory, shared_buffers, max_connections and background workers, and the total must fit within host memory and the kernel's shared memory limits. An upgrade also needs free disk space on the same filesystem, and the amount depends on the copy method you choose, so confirm it against the upgrade documentation before the window opens.
How the repository, packages and clusters fit together
The diagram starts at the PGDG apt repository, which the setup script configures on the host. Packages named postgresql-NN install the binaries for each major version, and postgresql-common manages the cluster directories that sit on top of them. The upgrade path runs from an older cluster to a newer one through pg_upgradecluster, pg_upgrade or logical replication. Check that each side of an upgrade has its own binaries installed and that the old cluster is stopped or quiesced before you start.
Repository, packages, clusters and the three upgrade routes on one host.
Security and operational considerations for apt-installed PostgreSQL
Packages from the PostgreSQL apt repository are only as safe as the trust chain, access rules and patch routine around them. The cards below cover the decisions that shape a Debian or Ubuntu host after the first install, from verifying signing keys to controlling who can log in and how minor releases reach production.
Verify repository trust and signing keys
Before adding the repository, confirm that the signing key on the host matches the key the PostgreSQL project publishes, and record its fingerprint in your build notes. The repository setup script adds the key and source entry for you, so check the resulting files under /etc/apt rather than trusting the first run. Pin the source to the hosts you intend to manage, and confirm with your security team how key rotation will be tracked. A key you cannot name is a key you cannot audit.
Choose authentication methods in pg_hba.conf
Every connection is decided by pg_hba.conf, which maps host, database, user and method to an allow or reject. Use scram-sha-256 for password logins and reserve trust for nothing outside a closed lab. PostgreSQL 18 deprecates MD5 password authentication in favor of SCRAM, so audit existing roles and md5 rules before upgrading. Review the file after each change, because rule order decides the result.
Patch minor releases by replacing executables
Minor releases do not change the on-disk storage format, so applying one means installing the new packages and restarting the server, not dumping and restoring data. Plan a maintenance window for each restart and confirm which clusters on the host depend on the binaries being updated. Keep a record of the running minor version on every host so a missed patch shows up in your inventory, not in an incident.
Upgrading docsLimit unattended upgrades on production hosts
Unattended upgrades can install a new PostgreSQL package and restart a service at an hour nobody planned. On production database hosts, consider excluding PostgreSQL packages from automatic updates and applying them through change control. Confirm that a package update never runs a major version switch on an existing cluster, and test the restart path in staging before each minor release reaches production.
Versioning policySet file permissions and data directory ownership
The data directory must belong to the postgres operating system user and should not be readable by other local accounts. Check ownership and mode after every restore, copy or volume change, because a wrong owner causes startup failures that look like configuration errors. Restrict access to configuration files that hold connection details, and confirm who has sudo or root on the database host, since that access reads the data files directly.
Map directory-based login to pg_hba
The PostgreSQL authentication methods list includes GSSAPI, SSPI, LDAP, RADIUS, certificate, PAM and OAuth, so directory-backed login is a supported design rather than a workaround. Decide which identity source is authoritative for each role, how removed staff lose access, and what happens when the directory is unreachable. Test one account through each method before you rely on it, and confirm the chosen method's options against your directory team's setup.
Authentication methods docsUpgrading clusters installed from apt without losing data
Choose the upgrade route before you touch the cluster, because the three documented routes trade downtime, rollback options and preparation work differently. Dump and restore with pg_dumpall is the simplest to reason about but needs the most downtime, since the whole dataset is exported and reloaded. pg_upgrade converts the data directory in place or by link, which is much faster on large clusters. PostgreSQL 18 adds parallel jobs to pg_upgrade, retains planner statistics across the upgrade so the new server does not start cold, and adds a --swap option that is worth testing on a copy first. Logical replication works between different major versions and, according to the PostgreSQL upgrading documentation, allows a major upgrade with only several seconds of downtime, at the cost of more setup, replication slot monitoring and a sequence and schema check before cutover.
On Debian and Ubuntu installed through apt.postgresql.org, the postgresql-common package provides pg_upgradecluster, which wraps pg_upgrade for clusters created with pg_createcluster. It keeps the old cluster directory and port layout consistent, so the new version appears under /etc/postgresql and /var/lib/postgresql with the same cluster name. Confirm with your own environment what the helper changes in postgresql.conf, pg_hba.conf and the systemd unit, and whether it leaves the old cluster in a state you can restart. Rehearse the upgrade on a restored copy of production, time it, and run the application's test suite against the result. Take a base backup with pg_basebackup and confirm it restores before any cutover, because that backup is your only clean rollback if the upgrade fails midway.
Before cutover, verify the data and the workload, not only that the service starts. Compare row counts or checksums for the critical tables, run ANALYZE on the new cluster if you are not relying on retained statistics, and check extensions, locale settings and the output of the upgrade log for warnings. Confirm which PostgreSQL minor release you land on and whether it is inside the support window in the PostgreSQL versioning policy, since your target major version sets the date by which you must upgrade again. Agree in writing who signs off on the rollback decision, how long the old cluster is kept, and when it is removed. Ask your DeployOpen or internal team to document these checks so the next upgrade repeats them rather than reinventing them.
Questions teams ask before installing PostgreSQL from apt
What drives the effort of a repository install compared with a full platform build?
A repository install is mostly package work: adding the apt.postgresql.org source, choosing major versions, initializing clusters and setting service files. A full platform build adds the parts around the database that take most of the time: replication, failover, backups with tested restores, connection pooling, monitoring, access control and a documented upgrade path. The main effort drivers are the number of hosts, how many major versions run side by side, whether high availability is in scope, and how many recovery and compliance requirements must be evidenced. Ask the partner to split the quote into install, configuration, testing and handover so you can see which parts you would otherwise carry yourself.
Can an in-house DBA team install and run PostgreSQL from apt alone?
Often yes for a single server or a small fleet, because the install steps are documented and the packages come from the PostgreSQL project's own repository. The harder part is ongoing ownership. Your team needs to track the supported majors, which currently run until dates the PostgreSQL versioning policy publishes for each release, apply minor releases at least every three months, and plan major upgrades. Check whether your DBAs have time for failover testing, restore drills and upgrade rehearsals. If they do not, a retainer or a scoped handover may fill the gap.
What does the client need to provide before work starts on PostgreSQL hosts?
Plan to provide the inputs that the work cannot run without:
- Hosts with the Debian or Ubuntu release you intend to standardize on, plus root or sudo access for the installer
- Network access from the hosts to the PostgreSQL repository, or an internal mirror if the hosts are isolated
- Named change windows for installs, restarts and any major upgrade, with rollback approval
- Backup targets and retention requirements, including where WAL archives and base backups will be stored
- Named owners for application connection settings, monitoring endpoints and access approvals
Confirm each item with your platform team before the scope is signed, since storage and network rules often decide the schedule.
How long do a first install and upgrade planning take for a given fleet size?
No duration can be given here without the scope. The time depends on the number of hosts, the number of major versions to run, whether replication and backups are included, how many applications connect, and how much testing your change process requires. A single-host install with a standard configuration is much shorter than a fleet with failover, pooling and monitoring. For upgrade planning, the main variable is the method: the PostgreSQL upgrading documentation describes dump and restore, pg_upgrade, and logical replication, and each has different downtime and rehearsal needs. Ask for a timeline with milestones tied to your change windows, not a single total.
Which PostgreSQL major versions should a new Debian or Ubuntu install target?
Target a version that is still supported for the life of the system. The PostgreSQL versioning policy lists 18 as the newest major, first released September 25, 2025, with final support on November 14, 2030, and lists 14 as supported until November 12, 2026. Versions 13 and earlier are no longer supported. Running several majors side by side with postgresql-common is possible, but each extra cluster adds patching, monitoring and backup work. Confirm which majors your applications certify against before choosing, and record the end-of-life date in your asset register.
How do I ask for a quote from a written scope for a PostgreSQL install?
Start with a written scope that lists the hosts, OS versions, PostgreSQL majors, whether replication, pooling, backups and monitoring are included, the upgrade work, the handover items and the acceptance tests. DeployOpen works from written scope, deliverables and timelines agreed before work starts, and it does not publish a price list, so the quote follows from that document. Ask the provider to state what is one-time, such as the build and handover, and what recurs, such as retainer support and continuous testing. Ask what is excluded, who pays for licenses or hardware, and how change requests are priced.
Does the install need a security review or compliance evidence afterward?
It depends on the controls your auditors will test. An apt install alone does not configure authentication, TLS or audit logging, so those settings need explicit design. Authentication methods, including SCRAM, certificate and directory-based options, are documented by the PostgreSQL project and should be chosen against your policy. DeployOpen prepares systems, controls and evidence for compliance assessments but does not issue audit reports or certifications; independent auditors and certification bodies do that. Ask the provider which configuration records and test results they will hand over for your assessor.
How DeployOpen scopes and delivers PostgreSQL installs
DeployOpen approaches an apt.postgresql.org install as a written, fixed-scope piece of work inside your own Debian or Ubuntu estate. We agree which major versions, cluster layout and tooling are in scope before any host is touched, then deliver the install, the side-by-side version plan and the operating runbook as documented deliverables.
How we scope
- We confirm which Debian or Ubuntu releases, hosts and architectures the install must cover before work starts.
- We record which PostgreSQL major versions run side by side, and their planned end-of-life dates, in the written scope.
- We agree whether the scope includes repository mirroring, pgBouncer, backups or only the base install and cluster management.
How we build
- We add the apt.postgresql.org repository using the documented setup script and pin the packages we agreed on.
- We create clusters with postgresql-common, set data directories, and verify each version starts, stops and reports correctly.
- We test a major upgrade path on a copy of your data using pg_upgrade or logical replication before any production change.
How we hand over
- You receive a written runbook covering pg_lsclusters, pg_ctlcluster, pg_createcluster and the upgrade steps we tested.
- You receive a version inventory listing each cluster, its major version, its support end date and its configuration files.
- We walk your platform and database administrators through the handover and record any open items in the scope document.
How we support
- Ongoing support, minor release patching and major upgrade planning are available as a retainer after handover.
- Continuous testing of restores and upgrades can be added to a retainer so your team sees evidence, not assumptions.
- Any change to the agreed scope, such as a new major version or a new host group, is quoted as a written change to the scope.

