Databases

Install PostgreSQL 14 on Debian 13 / 12 and Plan the Upgrade

PostgreSQL 14 reached end of life on November 12, 2026. PGDG still serves it for Debian 13 and Debian 12, and the build it serves is the last one the project will ship. If a vendor still certifies only 14, you can install PostgreSQL 14 on Debian today. The hard part is keeping apt from replacing it, because the plain postgresql package from the same repository now resolves to 19.

Original content from computingforgeeks.com - post 107654

We install the 14 server from PGDG, add an APT pin that blocks every newer major, check the defaults 14 ships with, and then walk the way off 14 with pg_upgradecluster. On our test boxes, PostgreSQL 14.25 (installed November 2026 on Debian 13 and 12 GCP VMs) took 55.6 seconds to install on Debian 13 and 21.6 seconds on Debian 12. If nothing forces you onto 14, use PostgreSQL 18 on Debian 13 and 12 instead; the general repository walkthrough and the postgres password steps live in the PostgreSQL 16 on Debian guide and are not repeated here.

What Debian and PGDG install for PostgreSQL 14

Neither Debian release carries 14 in its own archive. Debian 13 ships 17 and Debian 12 ships 15, and once the PGDG source is added the postgresql metapackage jumps to 19 on both. The only way to get 14 is to ask for postgresql-14 by name. These are the candidates apt-cache policy reported on the two test VMs:

Package sourceDebian 13 (trixie)Debian 12 (bookworm)
Debian archive, postgresql17+278+deb13u115+248+deb12u2
PGDG, postgresql metapackage19+297.pgdg13+119+297.pgdg12+1
PGDG, postgresql-1414.25-1.pgdg13+114.25-1.pgdg12+1
Older 14 builds still listed14.24, 14.2314.24, 14.23
libpq5 pulled in19.0-2.pgdg13+119.0-2.pgdg12+1

Three facts behind that table decide how you run 14 from here.

  • 14.25 is final: the 14.25 release notes call it the last 14.X release and ask you to reindex indexes hit by the corruption fixes it carries. A CVE published after November 12, 2026 stays open on 14.
  • Three builds kept: PGDG has kept three versions of each package since April 2026, so 14.23 to 14.25 stay installable; older ones move to apt-archive.postgresql.org.
  • Debian 11 is gone: the PGDG wiki records bullseye as archived on August 31, 2026, which is why this page covers Debian 13 and 12 only.

Most people do not expect the libpq5 row. PGDG ships the client library from the newest server branch in its main component, and the PGDG apt FAQ states that libpq5 is backward compatible, so a 14 server with a 19 libpq is the normal, supported pairing.

Step 1: Add the PGDG apt repository

PGDG publishes a setup script on the PostgreSQL download page, and it works unchanged on both releases because it reads the codename itself. We prefer it over a hand-written source file, since the PGDG signing key ships inside postgresql-common and the script points the source at it. Install that package from the Debian archive first; a minimal image may also need ca-certificates, because the repository is served over HTTPS.

sudo apt update
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y

A deb822 source file comes out of the run, followed by apt-get update. On Debian 13 it picked trixie-pgdg and on Debian 12 bookworm-pgdg, with the signing key stored under /usr/share/postgresql-common/pgdg/. Check the file it wrote:

cat /etc/apt/sources.list.d/pgdg.sources

On the Debian 13 box it contains a single suite, so no other PostgreSQL source is involved.

Types: deb
URIs: https://apt.postgresql.org/pub/repos/apt
Suites: trixie-pgdg
Components: main
Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.gpg

Before installing anything, confirm that 14 is visible and see what the metapackage would pull. We run this before every install, because it shows why the pin in the next step matters.

apt-cache madison postgresql-14
apt-cache policy postgresql | grep Candidate

Three 14 builds came back from trixie-pgdg, while postgresql resolved to 19 ahead of the 17 build in the Debian archive.

apt-cache output on Debian 13 showing postgresql-14 14.25 from PGDG while the postgresql metapackage candidate is 19

Debian 12 showed the same three 14 builds with the pgdg12 suffix, and the same 19 candidate for the metapackage. So on either release, a bare apt install postgresql at this point would give you a 19 server, which is exactly what an application pinned to 14 cannot use.

Step 2: Pin apt to PostgreSQL 14

Leave the repository at its default priority and block the packages that would bring a second server major instead. A later apt install postgresql, or a tool whose dependencies name the metapackage, would otherwise put the 19 binaries next to 14. No second cluster appears, but 19 becomes the newest installed major, so pg_upgradecluster picks it as the default target and the 19 client tools land beside the 14 ones. The pin below gives the metapackage and every 15 to 19 server and client package a priority of -1, which apt treats as “never install”. Create the preferences file:

sudo vim /etc/apt/preferences.d/postgresql-14-only

Add these three lines. Because the package field is a regular expression, one stanza covers the metapackage, the 15 to 19 servers and their client packages.

Package: /^postgresql(-1[5-9]|-client-1[5-9])?$/
Pin: release *
Pin-Priority: -1

None of the 14 packages match the expression, and neither does the client library, so a normal apt upgrade still moves you between 14 point releases. Test the pin by asking apt for the metapackage.

apt-cache policy postgresql postgresql-18 | grep -E '^[a-z]|Candidate'
sudo apt-get install -y postgresql

Both packages lost their candidate, and the install attempt failed instead of quietly pulling 19.

APT preferences file pinning Debian to PostgreSQL 14 with postgresql and postgresql-18 showing no install candidate

An error here is the result we want. The metapackage stays blocked whatever its version, but postgresql-20 would not match, so when 20 lands in PGDG change the first line to Package: /^postgresql(-(1[5-9]|2[0-9])|-client-(1[5-9]|2[0-9]))?$/ before someone installs it by name. Keep the pin under configuration management for the same reason, so a rebuilt server gets it before its first install.

Step 3: Install the PostgreSQL 14 server

Name the server and client packages explicitly. The server package already depends on the client, but listing both makes the intent obvious in shell history and in configuration management.

sudo apt install -y postgresql-14 postgresql-client-14

Our two releases did not do the same amount of work, and the time difference comes from that, not from PostgreSQL. We timed both runs on e2-medium VMs (2 vCPU, 4 GB) with time.

MeasurementDebian 13Debian 12
Wall time55.6 s21.6 s
Newly installed packages1511
Packages upgraded on the way2 (libc6, libc-bin)0
Installed server build14.25-1.pgdg13+114.25-1.pgdg12+1
Cluster created14/main, port 543214/main, port 5432

On Debian 13 the 14 server pulled a newer libc6 from the point release and brought in ICU and libgcrypt as extra new packages. User CPU time was almost the same on both (14.9 s against 14.6 s), so the extra 34 seconds went to downloads and disk writes. Run sudo apt full-upgrade before the install on a production box, so the libc upgrade happens in a window you chose rather than inside a database install.

Step 4: Verify the 14/main cluster

On Debian, postgresql-common creates a cluster named main on the first server install and runs it as the postgresql@14-main systemd unit. List clusters and check the unit:

pg_lsclusters
systemctl status postgresql@14-main --no-pager

Port 5432 belongs to the 14 cluster, with its data in /var/lib/postgresql/14/main and its configuration in /etc/postgresql/14/main. Memory after start measured 17.4 MB on Debian 13.

pg_lsclusters and systemctl status showing the PostgreSQL 14 main cluster online on port 5432 on Debian 13

Ask the server for its version as well. We never skip it on a box that had PostgreSQL before, because a leftover cluster from an earlier install can hold 5432 and push the new one to 5433.

sudo -u postgres psql -c "SELECT version();"

Debian 13 reports 14.25 built with GCC 14.2.

SELECT version() returning PostgreSQL 14.25 built with gcc 14 on Debian 13

Debian 12 reports the same 14.25 source, built with GCC 12.2 from bookworm.

SELECT version() returning PostgreSQL 14.25 built with gcc 12 on Debian 12

Only the compiler string differs between the two. On Debian 13, running sudo -u postgres psql from your home directory also printed could not change directory to "/home/klinsmann": Permission denied. The home directory on that VM was not readable by other users, so postgres could not enter it. The query still runs, and starting it from /tmp silences the message.

Step 5: Check the defaults PostgreSQL 14 ships with

An application certified on 14 usually assumes the defaults of 14, and two of them break older client stacks. PostgreSQL 14 was the first release to hash new passwords with SCRAM-SHA-256 by default, and the Debian cluster listens on localhost only. We read the settings straight from the server rather than from the config file, since an include or a conf.d drop-in can override what the file shows.

for s in password_encryption data_directory listen_addresses max_connections shared_buffers; do printf "%s = " $s; sudo -u postgres psql -Atc "SHOW $s;"; done
sudo grep -vE "^\s*(#|$)" /etc/postgresql/14/main/pg_hba.conf

Both releases returned identical values, and the shipped pg_hba.conf uses peer for local sockets and scram-sha-256 for TCP on loopback.

PostgreSQL 14 default settings on Debian with scram-sha-256 password encryption and the default pg_hba.conf rules

Each of those values has a consequence for an application that needs 14.

  • password_encryption = scram-sha-256: a client library too old to speak SCRAM cannot log in with a password set on this cluster. Upgrade the driver rather than downgrading the server to md5.
  • listen_addresses = localhost: an application on another host gets connection refused until you change it and add a host line to pg_hba.conf.
  • shared_buffers = 128MB, max_connections = 100: initdb defaults, sized for nothing in particular. Size them for the VM before load testing the application.

Opening remote access works the same on 14 as on 16: change listen_addresses, add a pg_hba.conf rule and open the firewall port. Follow the authentication section of the PostgreSQL 16 install guide for Debian and swap 16 for 14 in the paths.

Step 6: Create the application role and database

Give the application its own login role that owns its database, so it never connects as postgres. Replace the password with your own.

sudo -u postgres psql -c "CREATE ROLE appuser WITH LOGIN PASSWORD 'Str0ngPassw0rd';" -c "CREATE DATABASE appdb OWNER appuser;"

Then connect over TCP as that role, the way the application will, and load some rows. Going through 127.0.0.1 instead of the socket exercises the scram-sha-256 rule rather than peer, so a driver problem shows up now instead of on deploy day.

PGPASSWORD=Str0ngPassw0rd psql -h 127.0.0.1 -U appuser -d appdb -c "CREATE TABLE orders (id serial PRIMARY KEY, item text, qty int);" -c "INSERT INTO orders (item, qty) SELECT 'widget-' || g, g FROM generate_series(1,5000) g;" -c "SELECT count(*), current_user, inet_server_addr(), version() ~ '14.25' AS is_14 FROM orders;"

The login worked over loopback, the table holds 5,000 rows, and the stored hash starts with SCRAM-SHA-256$. The screenshot below ends with this query, which you can run to confirm the hash type yourself:

sudo -u postgres psql -c "SELECT rolname, left(rolpassword,14) AS hash FROM pg_authid WHERE rolname='appuser';"

An md5 prefix there means the role was created after someone switched password_encryption back to the older method, usually to suit an old driver.

Creating an application role and database on PostgreSQL 14 and confirming a SCRAM-SHA-256 password hash

That 5,000-row appdb is the dataset both upgrade runs below carried to 18, so the row count doubles as the check that nothing was lost. Take a dump of it before any upgrade; the PostgreSQL backup and point-in-time recovery guide covers more than a single pg_dump.

Step 7: Upgrade off PostgreSQL 14 with pg_upgradecluster

Running 14 past November 2026 is a decision to accept unpatched bugs, so plan the move while the application is being certified on a newer major. On Debian the move is pg_upgradecluster, which wraps either a dump and restore or pg_upgrade and also carries over the configuration files of the old cluster. We upgraded to 18 rather than 19, because 18 is on its seventh point release while 19 had been out for ten days. Remove the pin first, then install the new server next to 14.

sudo rm /etc/apt/preferences.d/postgresql-14-only
sudo apt install -y postgresql-18 postgresql-client-18
pg_lsclusters

On both releases pg_lsclusters still listed only 14 main after the install. The Debian packaging did not create an empty 18/main, so there was no cluster to drop before upgrading, which older guides tell you to do. If your pg_lsclusters shows an empty 18 cluster, run sudo pg_dropcluster 18 main --stop before the next command.

According to the pg_upgradecluster man page on our test box, the default method is dump. It keeps 14 intact and restores into a fresh 18 cluster, so it is the safe choice whenever the database fits a maintenance window. We ran it on the Debian 13 box.

sudo pg_upgradecluster 14 main

Port 5432 went to the new 18 cluster, the 14 cluster moved to 5433 with automatic startup disabled, and the whole run took 12.3 seconds.

pg_upgradecluster upgrading PostgreSQL 14 main to 18 main with the default dump method on Debian 13

Dump time grows with data size, so a multi-hundred-gigabyte database is better served by pg_upgrade in link mode, which hard-links the data files instead of copying them. We ran that variant on the Debian 12 box.

sudo pg_upgradecluster -m upgrade --link 14 main

It finished in 9.3 seconds and the application login returned the same 5,000 rows from an 18.7 server.

pg_upgradecluster in pg_upgrade link mode moving PostgreSQL 14 to 18 on Debian 12 in 9.3 seconds

Unlike the dump run, the link run ran no analyze pass afterwards. The 18 release of pg_upgrade carries most planner statistics across, but not extended statistics, and it printed the two follow-up commands below. Run the first as postgres once 18 is up to fill the gaps, and the second when you have a quiet hour:

Some statistics are not transferred by pg_upgrade.
Once you start the new server, consider running these two commands:
    /usr/lib/postgresql/18/bin/vacuumdb --all --analyze-in-stages --missing-stats-only
    /usr/lib/postgresql/18/bin/vacuumdb --all --analyze-only

Plain vacuumdb from /usr/bin would also reach the 18 cluster on port 5432 through the Debian wrapper, but the full path guarantees the 18 binary while the 14 packages are still installed.

Both methods ended with the same rows, yet they left different clusters behind, and the difference is easy to miss in the output.

Measured on the 5,000-row appdbdump (default), Debian 13upgrade –link, Debian 12
Wall time12.3 s9.3 s
Data page checksums on 18enableddisabled
Old 14 cluster afterwardsintact, port 5433not safe to start: 18 was already running when the command returned
Row count after upgrade5000 on 18.75000 on 18.7

Initdb on 18 enables data checksums by default, so the dump run gained them. The link run passed --no-data-checksums because pg_upgrade needs the new cluster to match the old one, and 14 had none. If checksums matter to you, accept the longer dump or enable them afterwards with /usr/lib/postgresql/18/bin/pg_checksums --enable -D /var/lib/postgresql/18/main, run as postgres after a clean shutdown of the cluster. Pick link mode only when you have a tested backup, because there is no falling back to 14 after 18 starts. The PostgreSQL 14 to 18 upgrade guide covers extension checks and the same move on Ubuntu and Rocky Linux.

Step 8: Remove PostgreSQL 14 after the upgrade

Keep the stopped 14 cluster until the application has run against 18 for a full business cycle, since it is the fastest rollback you have after a dump-mode upgrade. Once you trust 18, drop the old cluster and purge the 14 packages:

sudo pg_dropcluster 14 main
sudo apt purge -y postgresql-14 postgresql-client-14
pg_lsclusters

On the Debian 13 box only the 18 cluster remained, and /usr/lib/postgresql held a single 18 directory.

Ver Cluster Port Status Owner    Data directory              Log file
18  main    5432 online postgres /var/lib/postgresql/18/main /var/log/postgresql/postgresql-18-main.log

From here the server follows the 18 release line, which had its own security release in November; the PostgreSQL 18.7 security update lists what it fixed. Teams that skip straight to the newest major can follow installing PostgreSQL 19 on Debian and Ubuntu and point pg_upgradecluster at 19 instead.

Keep reading

Install Samba on Debian 13 / 12 and Create a File Share Debian Install Samba on Debian 13 / 12 and Create a File Share Backup and Restore Linux Systems with Timeshift Debian Backup and Restore Linux Systems with Timeshift Install KVM on Debian 13 / Debian 12: Complete Guide KVM Install KVM on Debian 13 / Debian 12: Complete Guide Migrate Kafka from ZooKeeper to KRaft and Upgrade to 4.x Databases Migrate Kafka from ZooKeeper to KRaft and Upgrade to 4.x Install PocketBase on Ubuntu with Nginx and HTTPS (New URL) Databases Install PocketBase on Ubuntu with Nginx and HTTPS (New URL) Install PostgreSQL 17 on Arch|Manjaro|Garuda Databases Install PostgreSQL 17 on Arch|Manjaro|Garuda

Leave a Comment

Press ESC to close