PostgreSQL is the open-source relational database behind many web apps, analytics stacks, and GIS workloads. On Debian, the postgresql metapackage installs the server, creates a local cluster, starts systemd service postgresql, and includes psql for administration.
This guide covers install PostgreSQL on Debian for Debian 11 (Bullseye), 12 (Bookworm), and 13 (Trixie): install from Debian main, verify with systemctl and psql, create roles and databases, add the PostgreSQL Apt Repository (PGDG) for other majors, update, and uninstall. I ran these steps on Debian 13 and kept real terminal output below. For client tools only (no local server), see install psql on Debian.
Tested on: Debian 13 (trixie); kernel 6.12.94+deb13-amd64; amd64; PostgreSQL 17.10; port 5432; data at
/var/lib/postgresql/17/main.
apt install postgresql installs a running database server on your machine. Use postgresql-client or postgresql-client-N when you only need psql to reach a remote instance—see install psql on Debian.
Choose an install method
| Method | Best for | Installs server? |
|---|---|---|
apt install postgresql |
Default Debian server matching your release | Yes (17 on Trixie) |
apt install postgresql-N |
Pin a specific major from Debian main | Yes |
| PGDG | PostgreSQL 18, 16, or latest minors from PostgreSQL.org | Yes (per postgresql-N package) |
postgresql-client only |
Connect to RDS, Docker, or remote Postgres | No — psql guide |
Most readers should start with sudo apt install postgresql when they want a local database on Debian.
Default PostgreSQL major by Debian release
| Debian | Codename | Default server package |
|---|---|---|
| 13 | trixie |
postgresql-17 |
| 12 | bookworm |
postgresql-15 |
| 11 | bullseye |
postgresql-13 |
Confirm on your host:
apt-cache policy postgresql postgresql-17 2>/dev/null | head -12On Trixie before install:
postgresql:
Candidate: 17+278
postgresql-17:
Candidate: 17.10-0+deb13u1Prerequisites
- Debian 11, 12, or 13 on amd64, arm64, or other PGDG architectures.
- sudo for package installation.
- Disk space for the data directory (default cluster uses 128MB
shared_buffersand grows with your data). - APT mirrors configured.
. /etc/os-release && echo "$PRETTY_NAME ($VERSION_CODENAME)"
command -v psql || echo "psql: not installed"Install PostgreSQL from Debian apt
Per Debian Wiki — PostgreSQL and postgresql.org Debian download, the supported path on current Debian is postgresql from main:
sudo apt update
sudo apt install -y postgresqlCluster initialization (excerpt from install output):
selecting default time zone ... America/New_York
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Setting up postgresql (17+278) ...Packages installed on Trixie:
ii postgresql 17+278
ii postgresql-17 17.10-0+deb13u1
ii postgresql-client-17 17.10-0+deb13u1
ii postgresql-client-common 278
ii postgresql-common 278Verify the server
Service status
sudo systemctl status postgresql --no-pager | head -10
pg_lsclusters● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (...; enabled; preset: enabled)
Active: active (exited) since Mon 2026-06-29 09:52:21 EDT
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.logVersion and port
psql --version
sudo -u postgres psql -c "SELECT version();"
sudo -u postgres psql -c "SHOW port;"
sudo -u postgres psql -c "SHOW data_directory;"psql (PostgreSQL) 17.10 (Debian 17.10-0+deb13u1)
PostgreSQL 17.10 (Debian 17.10-0+deb13u1) on x86_64-pc-linux-gnu, compiled by gcc ...
port
------
5432
data_directory
---------------------------
/var/lib/postgresql/17/mainList databases:
sudo -u postgres psql -c "\l"postgres | postgres | UTF8 | libc | en_US.UTF-8 | ...
template0 | postgres | UTF8 | libc | en_US.UTF-8 | ...
template1 | postgres | UTF8 | libc | en_US.UTF-8 | ...Create a role and database
As the postgres system user (peer authentication on local sockets):
sudo -u postgres psql -c "CREATE USER appuser WITH PASSWORD 'your_password';"
sudo -u postgres createdb appdb -O appuser
sudo -u postgres psql -c "\du"Role name | Attributes
-----------+------------------------------------------------------------
appuser |
postgres | Superuser, Create role, Create DB, Replication, Bypass RLSConnect to the new database:
sudo -u postgres psql -d appdb -c "SELECT current_database(), current_user;"From an interactive login shell you can also use createuser and createdb. In non-interactive environments, createuser --interactive may block waiting for a TTY—prefer psql -c "CREATE USER ..." in scripts.
Install another major from PGDG
When you need PostgreSQL 18, an older 15 on Trixie, or packages ahead of Debian security, add PGDG.
Automated setup (recommended)
sudo apt install -y postgresql-common curl ca-certificates
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt update
apt-cache policy postgresql-17 | head -10Manual one-line alternative:
sudo apt install -y curl ca-certificates gnupg
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| sudo gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] https://apt.postgresql.org/pub/repos/apt \
$(. /etc/os-release && echo "$VERSION_CODENAME")-pgdg main" \
| sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt updateAfter adding PGDG on Trixie:
Get:8 https://apt.postgresql.org/pub/repos/apt trixie-pgdg InRelease
postgresql-17:
Candidate: 17.10-1.pgdg13+1
*** 17.10-0+deb13u1 (installed from Debian security)Install a specific major (example 18):
sudo apt install -y postgresql-18
pg_lsclustersMultiple majors can coexist—each gets its own port if configured. Full PGDG client/server matrix is documented in install psql on Debian.
apt.postgresql.org on production systems.
Connect with psql
Local socket (as postgres):
sudo -u postgres psqlTCP to localhost:
psql -h 127.0.0.1 -U postgres -d postgresRemote server:
psql -h db.example.com -p 5432 -U appuser -d appdbFor connection flags, SSL, and pg_dump, see install psql on Debian.
Update PostgreSQL
sudo apt update
sudo apt install --only-upgrade postgresql postgresql-17
sudo systemctl restart postgresql
psql --versionMajor upgrades between PostgreSQL versions require pg_upgradecluster or dump/restore—apt upgrade applies minor/security updates within the same major. Read Debian Wiki — PostgreSQL before jumping majors on production data.
Uninstall PostgreSQL
Remove Debian default cluster
sudo systemctl stop postgresql
sudo pg_dropcluster 17 main --stop
sudo apt purge postgresql-17 postgresql-client-17 postgresql
sudo apt autoremove --purgeDry-run removing only the metapackage:
REMOVING:
postgresql
Remv postgresql [17+278]That removes the metapackage only—postgresql-17 and data remain until you purge versioned packages and drop clusters.
Remove PGDG repository
sudo rm -f /etc/apt/sources.list.d/pgdg.list /etc/apt/sources.list.d/pgdg.sources
sudo apt updateTroubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
psql: command not found |
Server not installed | sudo apt install postgresql or client guide |
Connection refused on 127.0.0.1 |
Server not running or wrong port | pg_lsclusters; sudo systemctl start postgresql |
peer authentication failed |
Wrong OS user for socket auth | Use sudo -u postgres psql or configure pg_hba.conf |
createuser hangs in scripts |
Interactive password prompt | Use psql -c "CREATE USER ..." |
| Two versions after PGDG | Multiple clusters | pg_lsclusters; connect with psql -p PORT |
apt install postgresql pulls wrong major |
Suite default | Install explicit postgresql-N or use PGDG |
References
- PostgreSQL — Linux downloads (Debian)
- PostgreSQL — Linux download overview
- Debian Wiki — PostgreSQL
- postgresql package on Debian
- On-site: install psql on Debian, install sudo on Debian, apt command, list installed packages
Summary
Install PostgreSQL on Debian with sudo apt install postgresql to get the suite default server (17.10 on Trixie), systemd service postgresql, and psql. Confirm with pg_lsclusters, SHOW port, and SELECT version(). Create roles and databases as postgres, add PGDG when you need another major, and remove clusters with pg_dropcluster before apt purge. For client-only installs, use install psql on Debian.

