Guides 11792 Published by

Installing PostgreSQL on Debian 11 Bullseye is streamlined by adding the official PGDG repository, which lets you pick a newer major release such as 15 instead of the default 13 that ships with Debian. The process involves downloading and storing the signing key, creating a new source list entry that pins the key for security, updating apt’s package index, and then installing the chosen `postgresql-` package. After installation you can confirm the service is active with systemd, optionally edit `postgresql.conf` to listen on all interfaces and adjust `pg_hba.conf` for remote access, then reload PostgreSQL to apply those changes. If a “Failed to start Postgres” error occurs after an upgrade or purge, removing all old PostgreSQL packages and reinstalling the clean version usually resolves it, leaving you with a ready‑to‑query database.



How to Install PostgreSQL on Debian 11 Bullseye

You’ll learn the quickest way to get a solid, production‑ready PostgreSQL instance up and running on your Bullseye box – no unnecessary packages, just the essentials plus optional extras for when you need them.

Why the “official” repo isn’t always enough

Debian’s own repos ship PostgreSQL 13 by default. That’s fine if 13 satisfies every use case, but a lot of us are hunting for newer features (like generated columns or logical replication tweaks) that land in PostgreSQL 15 first. The Postgres Global Development Group (PGDG) provides an up‑to‑date repository that lets you choose the exact major version.

Step 1: Add the PGDG signing key
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /usr/share/keyrings/postgresql-keyring.gpg > /dev/null

Without the key, apt refuses to install anything from PGDG because it can’t verify authenticity. The command fetches the public key and stores it in a trusted location so later operations are safe.

Step 2: Add the PostgreSQL repository
echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list

This tells apt where to look for PostgreSQL packages. By pinning the key with signed‑by, you avoid the older apt-key deprecation warnings and keep your system tidy.

Step 3: Update package lists
sudo apt update

You need a fresh index that includes the new PGDG packages; otherwise, the installer won’t see the version you want.

Step 4: Install the desired PostgreSQL major release
# For the latest stable (as of writing, 15)
sudo apt install postgresql-15

# If you prefer the default Debian 13:
# sudo apt install postgresql

postgresql‑<major> pulls in server, contrib and the client libraries. Installing just postgresql would give you the Debian‑supplied version, but it’s usually behind the PGDG releases.

Step 5: Verify the service is running
sudo systemctl status postgresql

You should see a green “active (running)” line. If not, try:

sudo systemctl start postgresql
sudo systemctl enable postgresql

systemd keeps PostgreSQL alive across reboots and gives you quick diagnostic output if something went wrong during startup.

Optional: Enable remote connections

1. Edit /etc/postgresql/15/main/postgresql.conf (replace 15 with your version):

   sudo nano /etc/postgresql/15/main/postgresql.conf

2. Find listen_addresses and change it to:

   listen_addresses = '*'

3. Save and exit, then edit the client auth file:

   sudo nano /etc/postgresql/15/main/pg_hba.conf

4. Add a line like:

   host    all             all             0.0.0.0/0               md5

5. Reload PostgreSQL:

   sudo systemctl reload postgresql

By default, PostgreSQL only listens on localhost. If you’re running a dev server that needs to be accessed from other machines (or a container), this is the minimal change to make it reachable.

Common gotcha: “Failed to start Postgres” after upgrade

I’ve seen this happen after a bad driver update or an accidental apt purge postgresql-*. The culprit was usually leftover configuration files from an older version that conflicted with the new binaries. Running:

sudo apt remove --purge postgresql-*
sudo apt install postgresql-15

cleans up the mess and restores a fresh, working installation.

That’s all there is to it—no fancy Docker tricks or third‑party installers required.