← Back to Blog

Install PostgreSQL on Debian 13: PostgreSQL 17 from Debian, 19 or 18 from apt.postgresql.org

Published · by Leo Gashi, RS Computers

PostgreSQL Debian 13 Databases

Debian 13 (trixie) packages PostgreSQL 17: on 3 December 2026, apt install postgresql on Debian 13.8 gave us postgresql-17 version 17.12-0+deb13u1. The newest upstream release is PostgreSQL 19.0, published on 19 November 2026, and you get it (or PostgreSQL 18.7) on trixie from the PostgreSQL project's own apt repository, apt.postgresql.org, where the package is postgresql-19 version 19.0-2.pgdg13+1.

This guide installs Debian's PostgreSQL 17, then PostgreSQL 19 from the PGDG repository next to it, moves the data across with pg_upgradecluster, and lists the errors you are most likely to paste into a search box, each with its exact text and the fix. Every command was run in a fresh Debian 13 container on 3 December 2026 and the outputs are copied from that run. RS Computers runs KVM servers in Amsterdam, Dublin and Prishtina, and every one of our VPS and VDS plans can be deployed with Debian 13 and full root access, so you can follow along on a clean server.

Quick answer

# as root: Debian's own PostgreSQL 17
apt update
apt install -y postgresql
pg_lsclusters

# as root: the newest major version from apt.postgresql.org instead
apt install -y postgresql-common
/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
apt install -y postgresql-19

Key facts, checked on 3 December 2026:

Which PostgreSQL version does Debian 13 ship?

Ask apt on the server. These commands only read package lists. Run them as root, or put sudo in front:

# as root
apt update
apt-cache policy postgresql postgresql-17 postgresql-common

Our Debian 13.8 container answered:

postgresql:
  Installed: (none)
  Candidate: 17+278+deb13u1
  Version table:
     17+278+deb13u1 500
        500 http://deb.debian.org/debian trixie/main amd64 Packages
postgresql-17:
  Installed: (none)
  Candidate: 17.12-0+deb13u1
  Version table:
     17.12-0+deb13u1 500
        500 http://deb.debian.org/debian trixie/main amd64 Packages
        500 http://deb.debian.org/debian-security trixie-security/main amd64 Packages
postgresql-common:
  Installed: (none)
  Candidate: 278+deb13u1
  ...

Read 17.12-0+deb13u1 from left to right: 17.12 is the upstream release, and +deb13u1 marks a build made as an update for Debian 13 stable. Debian stays on major version 17 for the whole life of Debian 13 and only moves the minor number. postgresql.org says the version Debian picks is "supported throughout the lifetime of that Debian version" (PostgreSQL downloads for Debian).

Source on Debian 13PackageVersion on 3 Dec 2026Upstream support ends
Debian trixie (main and security)postgresql-1717.12-0+deb13u18 November 2029
apt.postgresql.org, trixie-pgdgpostgresql-1919.0-2.pgdg13+119 November 2031
apt.postgresql.org, trixie-pgdgpostgresql-1818.7-1.pgdg13+514 November 2030
apt.postgresql.org, trixie-pgdgpostgresql-1717.12-1.pgdg13+18 November 2029

Install PostgreSQL 17 on Debian 13 from Debian's repository

# as root
apt install -y postgresql
pg_lsclusters
systemctl is-active postgresql@17-main
ss -ltnp | grep 5432
su - postgres -c "psql -c 'SELECT version();'"

The install creates and starts a database cluster by itself. Our output, trimmed:

Ver Cluster Port Status Owner    Data directory              Log file
17  main    5432 online postgres /var/lib/postgresql/17/main /var/log/postgresql/postgresql-17-main.log
active
LISTEN 0      200        127.0.0.1:5432      0.0.0.0:*    users:(("postgres",pid=4120,fd=7))
LISTEN 0      200            [::1]:5432         [::]:*    users:(("postgres",pid=4120,fd=6))
 PostgreSQL 17.12 (Debian 17.12-0+deb13u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit

Two things in there matter later. The server listens on the loopback addresses only, so nothing outside the machine can reach it yet. And the systemd unit that runs the database is postgresql@17-main. The plain postgresql unit is an umbrella that reported active (exited) on our server, so it tells you little about one cluster; check the versioned unit or pg_lsclusters. Our container had no sudo, so we switched user with su - postgres -c.

pg_lsclusters, pg_ctlcluster and where the config files live

Debian wraps PostgreSQL in "clusters", each named by major version and a name: 17/main. That is what lets two major versions run on one server. The tools come from postgresql-common:

CommandWhat it doesWhat we saw
pg_lsclustersLists every cluster with version, port, status and pathsthe output above
pg_ctlcluster 17 main stop (also start, reload, status)Controls one clusterstatus went to down, then back to online
pg_createcluster 19 reports --startCreates a second cluster on the next free port19 reports 5433 online
pg_dropcluster --stop 19 reportsStops a cluster and deletes its data and configcluster gone from the list
pg_upgradecluster 17 mainCopies a cluster to the newest installed major versionsee the upgrade section

systemctl restart and systemctl reload on postgresql@17-main work as well. The paths on Debian 13:

Peer and scram-sha-256: how pg_hba.conf decides who gets in

The first four active lines of Debian's default pg_hba.conf, without comments (three more cover replication the same way):

local   all             postgres                                peer
local   all             all                                     peer
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             ::1/128                 scram-sha-256

local lines cover the Unix socket, which is what psql uses when you give no -h. peer means no password at all: the server asks the kernel which Linux user is connecting and, in the words of the pg_hba.conf documentation, checks "if it matches the requested database user name". So the Linux user postgres can open psql as the role postgres, and root cannot. host lines cover TCP, here only from the machine itself, and scram-sha-256 asks for the role's password. New passwords are stored as SCRAM hashes: the stored value for our test role began with SCRAM-SHA-256$.

The first matching line is used and, as the documentation says, "There is no 'fall-through' or 'backup'": if the login fails on that line, PostgreSQL does not try the next one.

Create a role and a database

Give every application its own role and its own database, and leave the postgres superuser for administration. As root:

# as root
su - postgres -c "createuser --pwprompt appuser"
su - postgres -c "createdb -O appuser appdb"
su - postgres -c "psql -c '\du'"
Enter password for new role:
Enter it again:
                             List of roles
 Role name |                         Attributes
-----------+------------------------------------------------------------
 appuser   |
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS

The same in SQL, run as postgres, which also worked in our run:

CREATE ROLE reporter LOGIN PASSWORD 'choose-a-long-password';
CREATE DATABASE reports OWNER reporter;
ALTER ROLE appuser PASSWORD 'a-new-long-password';

Test the login the way the application will make it, over TCP with the password. psql asks for the password:

psql -h 127.0.0.1 -U appuser appdb -c 'select current_user, current_database();'
 current_user | current_database
--------------+------------------
 appuser      | appdb

The PHP side of a web application on the same server is covered in our guide to installing PHP on Debian 13.

Remote access: listen_addresses, pg_hba.conf and the firewall

A remote client needs three things: the server must listen on an address the client can reach, pg_hba.conf must have a line for that client, and the firewall must let that one client through. Put the listen setting in its own file. Replace 10.141.188.148, our lab address, with the server address your application connects to:

# as root
cat > /etc/postgresql/17/main/conf.d/10-listen.conf <<'EOF'
listen_addresses = 'localhost,10.141.188.148'
EOF
systemctl restart postgresql@17-main
ss -ltnp | grep 5432

We restarted rather than reloaded, because listen_addresses "can only be set at server start" (PostgreSQL documentation). Afterwards ss showed a third line, 10.141.188.148:5432. Then allow one role, one database and one client address, and reload:

# as root
echo "host    appdb    appuser    10.141.188.148/32    scram-sha-256" >> /etc/postgresql/17/main/pg_hba.conf
systemctl reload postgresql@17-main
su - postgres -c "psql -c 'select line_number, type, database, user_name, address, auth_method, error from pg_hba_file_rules;'"

The pg_hba_file_rules view shows the file as the server parsed it. Our new rule appeared as line 133 with an empty error column. In the lab the client was the container itself, so the address in the rule equals the server's; on a real setup you write the application server's address. A test connection reported ssl = t in pg_stat_ssl, because Debian's cluster starts with ssl = on.

Do not write 0.0.0.0/0 in that line and do not open 5432 to the whole internet: a database port that anyone can reach is a standing invitation to password guessing. With nftables, which our Debian 13 hardening guide sets up in full, the idea is three rules: allow the one client, allow loopback, drop the rest of port 5432. We loaded exactly this, with 203.0.113.10 standing in for the application server:

table inet pg_guard {
	chain input {
		type filter hook input priority filter; policy accept;
		tcp dport 5432 ip saddr 203.0.113.10 accept
		iifname "lo" accept
		tcp dport 5432 drop
	}
}

When the application runs on another server, a private tunnel such as WireGuard between the two servers keeps 5432 off the public address completely. More on exposing a database port is in our guide to running PostgreSQL, MySQL and Redis on a VPS.

Install PostgreSQL 19 or 18 on Debian 13 from apt.postgresql.org

The PostgreSQL project runs its own apt repository, usually called PGDG, and it supports trixie. Debian's postgresql-common package already contains the setup script and the signing key, so there is no key to download by hand. As root:

# as root
apt install -y postgresql-common
/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
cat /etc/apt/sources.list.d/pgdg.sources

We ran the script with -y, which skips its confirmation question. It writes one file and runs apt-get update. The file it wrote for us:

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

Signed-By ties the key to this one repository. Now ask apt what is on offer:

# as root
apt-cache policy postgresql-19 postgresql-18
apt-cache search --names-only '^postgresql-[0-9]+$' | sort -V

Candidates on 3 December 2026: postgresql-19 19.0-2.pgdg13+1 and postgresql-18 18.7-1.pgdg13+5. The search listed postgresql-10 through postgresql-19; only 15 and newer are still supported upstream.

The step to do before your next apt upgrade

If Debian's PostgreSQL 17 is already installed, run apt list --upgradable right after adding the repository. We did:

libpq5/trixie-pgdg 19.0-2.pgdg13+1 amd64 [upgradable from: 17.12-0+deb13u1]
postgresql-17/trixie-pgdg 17.12-1.pgdg13+1 amd64 [upgradable from: 17.12-0+deb13u1]
postgresql-client-17/trixie-pgdg 17.12-1.pgdg13+1 amd64 [upgradable from: 17.12-0+deb13u1]
postgresql-common/trixie-pgdg 297.pgdg13+1 all [upgradable from: 278+deb13u1]
postgresql/trixie-pgdg 19+297.pgdg13+1 all [upgradable from: 17+278+deb13u1]
...

Two things would happen without you asking. In a simulated apt-get upgrade, your 17.12 was swapped for the PGDG build of 17.12. In a simulated apt-get dist-upgrade, the postgresql metapackage moved to 19+297.pgdg13+1 and pulled in postgresql-19 and postgresql-client-19 as new packages. The PGDG FAQ confirms the repository has the same priority as Debian's by default. To keep Debian's 17 and the metapackage where they are, pin those three names. As root:

# as root
cat > /etc/apt/preferences.d/pgdg <<'EOF'
# Keep Debian's PostgreSQL 17 and the "postgresql" metapackage on Debian's builds
Package: postgresql postgresql-17 postgresql-client-17
Pin: origin apt.postgresql.org
Pin-Priority: 100
EOF
apt update
apt list --upgradable

After the pin the upgradable list shrank to libpq5, postgresql-common, postgresql-client-common and postgresql-common-dev, the shared helper packages. On a server with no PostgreSQL yet, skip the pin.

Install the new major version

# as root
apt install -y postgresql-19
pg_lsclusters
psql --version

Name the version: postgresql-19, or postgresql-18 if your application is not ready for 19. We installed 19 only. The result surprised us:

Ver Cluster Port Status Owner    Data directory              Log file
17  main    5432 online postgres /var/lib/postgresql/17/main /var/log/postgresql/postgresql-17-main.log
psql (PostgreSQL) 19.0 (Debian 19.0-2.pgdg13+1)

The 19 binaries were in /usr/lib/postgresql/19/, but there was no 19 cluster, so there was no empty 19/main to drop before upgrading. The reason is written in /etc/postgresql-common/createcluster.conf: a main cluster is created "when a new postgresql-NN server package is installed and no clusters exist yet". Our server already had one.

Run two PostgreSQL versions side by side

To test an application on 19 while 17 keeps serving, create a cluster by hand. It takes the next free port:

# as root
pg_createcluster 19 reports --start
pg_lsclusters
Ver Cluster Port Status Owner    Data directory                 Log file
17  main    5432 online postgres /var/lib/postgresql/17/main    /var/log/postgresql/postgresql-17-main.log
19  reports 5433 online postgres /var/lib/postgresql/19/reports /var/log/postgresql/postgresql-19-reports.log

Each cluster has its own port, data directory, log and config folder. Clients choose with the port, for example psql -p 5433. Afterwards pg_dropcluster --stop 19 reports removes it, data included, and it did not ask us to confirm.

Upgrade PostgreSQL 17 to 19 with pg_upgradecluster

Take a dump first (next section), make sure no 19/main cluster exists, then run one command as root:

# as root
pg_upgradecluster 17 main
pg_lsclusters
Success. Please check that the upgraded cluster works. If it does,
you can remove the old cluster with
    pg_dropcluster 17 main

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

The tool created 19/main, copied roles and databases into it, stopped the old cluster, switched off its automatic start and swapped the ports, so applications still find the database on 5432. The default method is dump and restore; the man page also documents -m upgrade with --link or --clone, which we did not run. Our test database, one table with 50,000 rows, took 10.4 seconds from start to finish. SELECT version() then returned PostgreSQL 19.0 (Debian 19.0-2.pgdg13+1), the row count was still 50,000, and the role's password still worked. Data checksums, off in our Debian 17 cluster, were on in the new one.

What did not survive: our remote access. The extra line in pg_hba.conf was carried over, but conf.d/10-listen.conf was not. The new cluster's conf.d folder was empty, listen_addresses was back to localhost, and the remote test failed with Connection refused. This was with postgresql-common 278+deb13u1. So after an upgrade, put your own conf.d files back before you drop the old cluster. We wrote ours again and restarted:

# as root
cat > /etc/postgresql/19/main/conf.d/10-listen.conf <<'EOF'
listen_addresses = 'localhost,10.141.188.148'
EOF
systemctl restart postgresql@19-main

The remote login worked right after the restart. Once the application has run on 19 for long enough, remove the old cluster and packages:

# as root
pg_dropcluster 17 main
apt purge -y postgresql-17 postgresql-client-17

The purge also removed the pinned postgresql metapackage, which is fine, because postgresql-19 is installed by name. A leftover /etc/postgresql/17 folder was still there afterwards; check it and delete it by hand. PGDG is not a Debian origin, so unattended-upgrades does not include it by default. After we added "origin=apt.postgresql.org"; to an Unattended-Upgrade::Origins-Pattern block, a dry run listed the origin as allowed.

Back up with pg_dump

# as root
su - postgres -c "pg_dump -Fc appdb -f /var/lib/postgresql/appdb.dump"
su - postgres -c "pg_dumpall --globals-only"

# restore test into a scratch database
su - postgres -c "createdb -O appuser appdb_restore"
su - postgres -c "pg_restore -d appdb_restore /var/lib/postgresql/appdb.dump"
su - postgres -c "psql -d appdb_restore -Atc 'select count(*) from orders'"

-Fc writes PostgreSQL's custom format, which pg_restore reads. Our 50,000-row table became a 259,172-byte file and the restored copy counted 50,000 rows again. pg_dump saves one database, which is why pg_dumpall --globals-only sits next to it: it prints the CREATE ROLE and ALTER ROLE statements for your roles, so redirect its output to a file and keep it with the dump. Copy both off the server, as in our offsite backup guide with restic; WAL archiving and restore tests are in the database VPS guide.

Six PostgreSQL errors on Debian 13 and their fixes

Each error text is copied from our terminal on Debian 13.

FATAL: Peer authentication failed for user "postgres"

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "appuser"

We got this as root with psql -U appuser appdb and again with psql -U postgres. You connected over the socket, where the rule is peer, and your Linux user name is not the role name. Fix: become that Linux user (su - postgres -c psql), or connect over TCP so the password rule applies: psql -h 127.0.0.1 -U appuser appdb. Do not change the postgres line to trust.

FATAL: password authentication failed for user "appuser"

psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "appuser"

Usually a wrong password; set a new one with ALTER ROLE appuser PASSWORD '...'; as postgres. But here is what the client does not tell you: we got the same words for a role that does not exist. For a made-up user, the server log said the rest:

nobody@appdb FATAL:  password authentication failed for user "nobody"
nobody@appdb DETAIL:  Role "nobody" does not exist.
	Connection matched file "/etc/postgresql/17/main/pg_hba.conf" line 125: "host    all             all             127.0.0.1/32            scram-sha-256"

So look at /var/log/postgresql/postgresql-17-main.log before resetting passwords. It names the real cause and the exact pg_hba.conf line that matched.

FATAL: role "root" does not exist

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "root" does not exist

Plain psql uses your Linux user name as the role name, and a new server has only the postgres role. Run su - postgres -c psql, or name a role with -U. A close cousin is FATAL: database "appuser" does not exist: with no database given, psql tried one named after the user. Put the database name at the end of the command.

Connection refused on port 5432

psql: error: connection to server at "10.141.188.148", port 5432 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?

Nothing listens on that address and port. Check pg_lsclusters for a cluster that is down or on port 5433, and ss -ltnp | grep 5432 for the addresses. On a new install the usual cause is listen_addresses, which is localhost until you change it; after pg_upgradecluster it can be the lost conf.d file described above. We got the same message on 127.0.0.1 with the cluster stopped.

No such file or directory on socket "/var/run/postgresql/.s.PGSQL.5432"

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
	Is the server running locally and accepting connections on that socket?

The cluster is not running, or it runs on another port and the socket file carries another number. We produced it with pg_ctlcluster 17 main stop. Fix: pg_lsclusters, then systemctl start postgresql@17-main, and read the log if it will not start. Older releases worded it "could not connect to server: No such file or directory", as shown in the PostgreSQL 13 documentation. Same cause, same fix.

FATAL: no pg_hba.conf entry for host

psql: error: connection to server at "10.141.188.148", port 5432 failed: FATAL:  no pg_hba.conf entry for host "10.141.188.148", user "appuser", database "appdb", SSL encryption

The server listens and answered, but no line in pg_hba.conf matches this client address, role and database. Add a host line for exactly those three, as in the remote access section, and reload. The address in the message is the one the server sees, so copy it from there.

How we tested

One fresh Debian 13.8 system container with 2 GB of RAM, on 3 December 2026. We ran every step above in order, from postgresql-17 17.12-0+deb13u1 to postgresql-19 19.0-2.pgdg13+1, and triggered each error on purpose. postgresql-common stayed at 278+deb13u1 throughout.

What we did not test: PostgreSQL 18 (we read its version from apt but installed 19), the pg_upgrade methods with --link or --clone, upgrading a large database, replication, extensions, and the firewall rules from a second machine. In the lab, client and server were the same container.

Frequently asked questions

What version of PostgreSQL is in Debian 13?

PostgreSQL 17. On 3 December 2026, Debian 13.8 installs postgresql-17 version 17.12-0+deb13u1, and the postgresql metapackage is 17+278+deb13u1. Debian 13 stays on major version 17 and receives minor updates.

How do I install PostgreSQL 18 on Debian 13?

Add the PostgreSQL apt repository with /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh, then run apt install postgresql-18. On 3 December 2026 the trixie-pgdg suite offered 18.7-1.pgdg13+5.

Is PostgreSQL 19 available for Debian 13?

Yes, from apt.postgresql.org, not from Debian. PostgreSQL 19.0 was released on 19 November 2026 and the trixie package on 3 December 2026 was postgresql-19 19.0-2.pgdg13+1. It is a .0 release, so test your application on it first.

Where is pg_hba.conf on Debian 13?

In /etc/postgresql/17/main/pg_hba.conf for the default cluster, next to postgresql.conf. SHOW hba_file; in psql prints the path, and systemctl reload postgresql@17-main applies changes.

How do I log in to PostgreSQL after installing it on Debian?

As the postgres Linux user: su - postgres -c psql from root, or sudo -u postgres psql where sudo is installed. There is no password, because the local socket uses peer authentication. For application roles with a password, connect over TCP with psql -h 127.0.0.1 -U role database.

Should I use Debian's PostgreSQL or the PGDG repository?

Debian's 17 is the simple choice: one repository, updates through Debian's own archives, and upstream support until 8 November 2029. Use apt.postgresql.org when you need features from 18 or 19, or a longer upstream support window. Both use the same cluster tools and the same paths.

Sources

All checked on 3 December 2026.

Need a hand?

PostgreSQL lives on disk speed and memory. For a small application or a test database, VPS Micro (2 vCPU, 2 GB RAM, 40 GB NVMe) or VPS Mini (4 vCPU, 4 GB, 80 GB) is a sensible start; these plans use shared vCPUs. For a production database, a VDS with dedicated vCPUs, from VDS Small (4 vCPU, 8 GB, 240 GB NVMe), is the better fit, and our pgbench sizing test shows how to pick between them.

← All articles

Chat on Telegram