How to Install PostgreSQL 15 on Debian 13, 12 and 11

Install PostgreSQL 15 on Debian 13, 12, and 11 using Debian's repo or PGDG. Includes setup, verification, updates, and removal.

Last updatedAuthorJoshua JamesRead time8 minGuide typeDebian

PostgreSQL 15 remains useful on Debian when an application stack depends on that major branch for extension compatibility, tested SQL behavior, or a slower database-upgrade schedule. To install PostgreSQL 15 on Debian, the package source matters more than the command itself: Debian 12 (Bookworm) ships PostgreSQL 15 in its default package sources, while Debian 13 (Trixie) and Debian 11 (Bullseye) need the PostgreSQL Apt Repository, commonly called PGDG.

Debian 13, Debian 12, and Debian 11 use the same versioned package names once the right source is available. The important distinction is whether you want the local server package, the client tools only, or the release-default postgresql meta package, which follows the default branch for your enabled repositories instead of staying pinned to PostgreSQL 15.

Install PostgreSQL 15 on Debian

Choose the PostgreSQL 15 Package Source on Debian

The fixed package name postgresql-15 installs the PostgreSQL 15 server, and postgresql-client-15 installs matching client tools such as psql, pg_dump, and pg_restore. Avoid the unversioned postgresql meta package when you specifically need PostgreSQL 15, because that package follows the default branch for the active source.

Debian releaseDefault PostgreSQL branchpostgresql-15 in Debian sourcesRecommended PostgreSQL 15 sourceWhat this means
Debian 13 (Trixie)17.xNoPGDG repositoryUse PGDG and install the versioned postgresql-15 packages.
Debian 12 (Bookworm)15.xYesDebian default repositoryUse Debian’s package unless you deliberately want PGDG’s newer 15.x package track.
Debian 11 (Bullseye)13.xNoPGDG repositoryUse PGDG because Bullseye’s default archive does not provide PostgreSQL 15.

On Debian 12, the default repository is the simplest path because PostgreSQL 15 receives Debian security updates without adding a third-party source. On Debian 13 and Debian 11, PGDG is the practical path for this fixed major. PGDG also works on Debian 12, but it moves update ownership for PostgreSQL 15 from Debian’s archive to PostgreSQL’s own Apt repository.

APT and service changes need root privileges. If your account cannot use sudo, set up administrator access first with the Debian sudoers walkthrough for adding a user to sudoers on Debian.

Refresh Debian Package Metadata

Refresh APT before installing PostgreSQL so dependency resolution uses current package metadata. A full system upgrade is optional for this workflow; if APT reports important security updates, apply them according to your normal maintenance window.

sudo apt update

Install PostgreSQL 15 from the Debian 12 Repository

Use this method on Debian 12 (Bookworm) when you want PostgreSQL 15 from Debian’s default package sources. APT may install supporting packages such as postgresql-common, postgresql-client-common, libpq5, and sysstat; the exact download and installed-size numbers vary by system state and enabled repositories.

sudo apt install postgresql-15 postgresql-client-15

The server package creates the default 15/main cluster during installation. Verify both the installed branch and the Debian cluster state:

psql --version
pg_lsclusters
psql (PostgreSQL) 15.18 (Debian 15.18-0+deb12u1)

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

The online status is the key success signal. Debian’s pg_lsclusters output also shows the port, cluster owner, data directory, and log path, which are the details you need before troubleshooting service startup or editing PostgreSQL configuration.

Install PostgreSQL 15 from the PostgreSQL APT Repository

Use this method on Debian 13 or Debian 11, or on Debian 12 when you intentionally want PGDG packages for PostgreSQL 15. The PostgreSQL project lists the supported Debian releases and repository setup on its official Debian download page; the manual setup here keeps the source in DEB822 format and stores the signing key beside PostgreSQL’s documented Apt repository path.

Install the small tools needed to download the signing key over HTTPS:

sudo apt install ca-certificates curl

Create the key directory and download the PGDG signing key. The curl flags make the download fail on HTTP errors, show errors if something breaks, follow redirects, and save the file to the exact path APT will use. For a deeper flag reference, see the Linux curl command guide.

sudo install -d -m 0755 /usr/share/postgresql-common/pgdg
sudo curl -fsSLo /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc

Create the PGDG source file for the current Debian codename and architecture. The subshell stops before writing anything if the release or architecture is not part of the supported set documented for this workflow.

(
    . /etc/os-release
    arch=$(dpkg --print-architecture)

    case "$VERSION_CODENAME" in
        trixie|bookworm|bullseye) ;;
        *) printf 'This PGDG setup is documented here for Debian 13, 12, and 11.\n'; exit 1 ;;
    esac

    case "$arch" in
        amd64|arm64|ppc64el) ;;
        *) printf 'PGDG does not publish this Debian repository for architecture: %s\n' "$arch"; exit 1 ;;
    esac

    printf '%s\n' \
        'Types: deb' \
        'URIs: https://apt.postgresql.org/pub/repos/apt' \
        "Suites: ${VERSION_CODENAME}-pgdg" \
        'Components: main' \
        "Architectures: ${arch}" \
        'Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc' | sudo tee /etc/apt/sources.list.d/pgdg.sources > /dev/null
)

Refresh APT and confirm that postgresql-15 resolves from PGDG. This check matters because the unversioned postgresql package will follow the newest default branch from the enabled source, while postgresql-15 stays pinned to the 15.x major.

sudo apt update
apt-cache policy postgresql-15

On Debian 13, the relevant lines should point to trixie-pgdg and the PGDG package:

postgresql-15:
  Installed: (none)
  Candidate: 15.18-1.pgdg13+1
  Version table:
     15.18-1.pgdg13+1 500
        500 https://apt.postgresql.org/pub/repos/apt trixie-pgdg/main amd64 Packages

On Debian 12, the PGDG candidate appears as 15.18-1.pgdg12+1. On Debian 11, it appears as 15.18-1.pgdg11+1. Older 15.x entries can also appear because the repository keeps several package revisions available, but APT chooses the newest candidate by default.

Install the PostgreSQL 15 server and matching client tools from the enabled repository:

sudo apt install postgresql-15 postgresql-client-15

Verify the PGDG build and the cluster state:

psql --version
pg_lsclusters
psql (PostgreSQL) 15.18 (Debian 15.18-1.pgdg13+1)

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

If you later add PGDG on a Debian 12 system that already installed PostgreSQL 15 from Debian’s archive, APT will see the PGDG build as the higher candidate for the same major. That is still a PostgreSQL 15 minor update path, not a major-version upgrade, but update ownership changes to PGDG while the repository remains enabled.

Install Only the PostgreSQL 15 Client Tools on Debian

Install only postgresql-client-15 when the database server runs elsewhere and the Debian machine only needs client commands such as psql, pg_dump, pg_restore, and createdb. Choose the Debian 12 default source or the PGDG source first, depending on your release.

sudo apt install postgresql-client-15

Verify the client package with psql:

psql --version
psql (PostgreSQL) 15.18 (Debian 15.18-1.pgdg13+1)

A client-only install does not create a local 15/main cluster or a postgresql@15-main service. On a clean client-only machine, pg_lsclusters may also be unavailable because it belongs to postgresql-common, not postgresql-client-common. That is expected when the machine installed only postgresql-client-15.

Check the PostgreSQL 15 Service and Cluster on Debian

Debian manages PostgreSQL through postgresql-common. The generic postgresql.service wrapper can be active even though the real database work happens inside versioned cluster units such as postgresql@15-main.service. Use pg_lsclusters for the clearest cluster view, then use the versioned unit when you restart, stop, or inspect logs for only PostgreSQL 15.

pg_lsclusters
systemctl is-active postgresql@15-main
Ver Cluster Port Status Owner    Data directory              Log file
15  main    5432 online postgres /var/lib/postgresql/15/main /var/log/postgresql/postgresql-15-main.log
active
TaskCommandWhen to use it
List PostgreSQL clusterspg_lsclustersConfirm version, cluster name, port, state, data path, and log path.
Check only the 15/main unitsystemctl is-active postgresql@15-mainVerify that the PostgreSQL 15 cluster service is active.
Restart PostgreSQL 15sudo systemctl restart postgresql@15-mainApply configuration changes that require a restart.
Reload PostgreSQL 15sudo systemctl reload postgresql@15-mainReload compatible configuration changes without a full restart.
View recent PostgreSQL 15 logssudo journalctl -u postgresql@15-main --no-pager -n 30Check startup errors, authentication failures, or shutdown messages.

If you run several PostgreSQL majors side by side, keep using versioned cluster commands. A restart of postgresql@15-main affects the PostgreSQL 15 cluster, while a broad wrapper restart can touch every installed cluster.

Get Started with PostgreSQL 15 on Debian

The packaged server is ready for local administration after the cluster is online. Debian’s default local setup lets the Linux postgres account administer PostgreSQL through peer authentication, so initial database work normally starts from that account rather than from a password typed into a shell command.

Open the PostgreSQL Shell as the postgres User

Open an interactive psql session as the local PostgreSQL administrator:

sudo -iu postgres psql

Inside psql, list databases, list roles, or leave the shell with these meta-commands:

\l
\du
\q

The \l command shows databases, \du shows roles, and \q exits back to your normal terminal. These are psql commands, not Linux shell commands, so run them only after the postgres=# prompt appears.

Create an Application Role and Database

For an application, create a separate login role and a database owned by that role. The --pwprompt option asks for the password interactively, which keeps the password out of your shell history and process list.

sudo -iu postgres createuser --pwprompt appuser
sudo -iu postgres createdb -O appuser appdb
Enter password for new role:
Enter it again:

Replace appuser and appdb with names that match your application. For local services, keep the connection on the local Unix socket or 127.0.0.1 unless you have a specific remote-access plan.

Verify the role with a normal password-authenticated connection. Enter the password you created when psql prompts for it:

psql -h 127.0.0.1 -U appuser -d appdb -c '\conninfo'
Password for user appuser:
You are connected to database "appdb" as user "appuser" on host "127.0.0.1" at port "5432".
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)

Keep Remote Access Deliberate

A fresh Debian PostgreSQL cluster is safest as a local service. Remote clients require more than opening port 5432: you must decide which address PostgreSQL listens on, which clients are allowed in pg_hba.conf, which authentication method they use, and which firewall or network control limits access. If you expose the server beyond localhost, restrict the source addresses and manage the firewall carefully with a tool such as UFW on Debian.

Update PostgreSQL 15 on Debian

PostgreSQL 15 minor releases arrive through the package source you chose. Debian 12 default installs follow Debian’s 15.x package stream, while PGDG installs follow PostgreSQL’s upstream 15.x packages for the enabled Debian release.

sudo apt update
sudo apt install --only-upgrade postgresql-15 postgresql-client-15

The --only-upgrade option upgrades the packages only when they are already installed. It does not install a missing server on a client-only machine, and it avoids turning a targeted minor update into a broader package operation.

PostgreSQL 15 is a supported major version through November 11, 2027, and PostgreSQL’s versioning policy lists 15.18 as the current minor release at the time of this refresh. Major-version upgrades, such as moving from PostgreSQL 15 to PostgreSQL 18, are migration projects that need backups, compatibility checks, and either pg_upgrade or dump/restore planning.

Troubleshoot PostgreSQL 15 on Debian

Fix Unable to Locate Package postgresql-15 on Debian

On Debian 13 or Debian 11, sudo apt install postgresql-15 fails before PGDG is enabled because the default archive does not provide that versioned package:

E: Unable to locate package postgresql-15

Check both the release-default meta package and the fixed PostgreSQL 15 package:

apt-cache policy postgresql postgresql-15
postgresql:
  Installed: (none)
  Candidate: 17+278
  Version table:
     17+278 500
        500 http://deb.debian.org/debian trixie/main amd64 Packages
postgresql-15:
  Installed: (none)
  Candidate: (none)
  Version table:

On Debian 13, the default postgresql package points to PostgreSQL 17. On Debian 11, it points to PostgreSQL 13. Add PGDG, run sudo apt update, and repeat apt-cache policy postgresql-15; a usable fix shows a candidate from apt.postgresql.org with your release suffix ending in -pgdg.

Fix PGDG Source or Signing Key Problems

If sudo apt update fails after adding PGDG, inspect the source file before reinstalling packages. The release codename must match your Debian release, and Signed-By must point to the key file you downloaded.

cat /etc/apt/sources.list.d/pgdg.sources
Types: deb
URIs: https://apt.postgresql.org/pub/repos/apt
Suites: trixie-pgdg
Components: main
Architectures: amd64
Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc

For Debian 12, Suites should be bookworm-pgdg. For Debian 11, it should be bullseye-pgdg. If APT reports a missing public key or cannot read the key path, recreate the directory, download the key again, then run sudo apt update.

sudo install -d -m 0755 /usr/share/postgresql-common/pgdg
sudo curl -fsSLo /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
sudo apt update

Check Whether You Installed the Server or Only the Client

A working psql command does not always mean the local database server is installed. The client package is enough for remote administration, but a local PostgreSQL 15 server also needs postgresql-15 and an online cluster.

dpkg -l postgresql-15 postgresql-client-15 | grep '^ii'

if command -v pg_lsclusters >/dev/null 2>&1; then
    pg_lsclusters
else
    echo "pg_lsclusters is not installed; the local server package is not present."
fi

If only postgresql-client-15 appears, install postgresql-15 for a local server. If pg_lsclusters is missing, the machine does not have Debian’s local cluster-management tools installed. If both packages are installed but pg_lsclusters does not show 15/main as online, inspect the versioned unit and recent logs with systemctl is-active postgresql@15-main and sudo journalctl -u postgresql@15-main --no-pager -n 30.

Remove PostgreSQL 15 from Debian

Package removal and database removal are separate tasks. Removing postgresql-15 stops using the server binaries, but the cluster data and configuration can remain unless you deliberately drop the cluster.

Dropping the 15/main cluster permanently deletes that cluster’s PostgreSQL data directory and configuration. Back up databases first with pg_dump, pg_dumpall, filesystem snapshots, or your normal backup workflow.

When you want to remove the local PostgreSQL 15 cluster data, use Debian’s cluster tool instead of deleting directories by hand:

sudo pg_dropcluster --stop 15 main
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file

Remove the PostgreSQL 15 server and client packages:

sudo apt remove postgresql-15 postgresql-client-15

APT may report supporting packages as no longer required. Review the list before removing them, especially on systems that run multiple PostgreSQL versions or still need client tools.

sudo apt autoremove

If you added PGDG only for PostgreSQL 15, remove the source file and refresh APT. The key cleanup checks whether another APT source still references the same key before deleting it.

sudo rm -f /etc/apt/sources.list.d/pgdg.sources
sudo apt update

sources=()
for path in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do
    if [ -f "$path" ]; then
        sources+=("$path")
    fi
done

key_in_use=no
if [ "${#sources[@]}" -gt 0 ]; then
    if grep -Fq '/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc' "${sources[@]}"; then
        key_in_use=yes
    fi
fi

if [ "$key_in_use" = yes ]; then
    printf 'Another APT source still references the PGDG key; leaving it in place.\n'
else
    sudo rm -f /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
    sudo rmdir --ignore-fail-on-non-empty /usr/share/postgresql-common/pgdg
fi

Verify that the PostgreSQL 15 server and client packages are no longer installed:

dpkg -l postgresql-15 postgresql-client-15 | grep '^ii' || echo "PostgreSQL 15 packages are no longer installed."
PostgreSQL 15 packages are no longer installed.

On Debian 13 and Debian 11, apt-cache policy postgresql-15 should no longer show a PGDG candidate after the source is removed and APT metadata is refreshed. On Debian 12, Debian’s own postgresql-15 candidate can still appear because Bookworm ships that package in the default sources.

Conclusion

PostgreSQL 15 is installed on Debian with a verified package source, an online 15/main cluster when the server package is used, and a safer first-role workflow for local applications. Keep minor updates on the selected APT source, plan major upgrades as migrations, and make remote administration depend on restricted firewall rules plus reliable SSH access on Debian.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: