psql is the interactive terminal client for PostgreSQL. You use it to run SQL, inspect schemas, and administer databases on local or remote servers. On Debian you do not need the full postgresql server package just to get psql—install postgresql-client when you only connect to databases elsewhere (RDS, a team server, Docker Postgres, etc.).
This guide covers install psql on Debian for Debian 11 (Bullseye), 12 (Bookworm), and 13 (Trixie): client-only install from Debian main, versioned postgresql-client-N packages, the official PostgreSQL Apt Repository (PGDG), verify with psql --version, connect with psql -h, and uninstall. For a local database server on the same host, see install PostgreSQL on Debian. I ran these steps on Debian 13—postgresql-client installed psql 17.10 without a server, and PGDG added postgresql-client-18 (18.4) alongside it.
Tested on: Debian 13 (trixie); kernel 6.12.94+deb13-amd64; amd64; psql 17.10 (Debian main), psql 18.4 (PGDG).
apt install postgresql installs the server and starts a local cluster. For psql only, use postgresql-client or postgresql-client-N—not the unversioned postgresql meta package unless you want both client and server.
Choose an install method
| Method | Best for | Installs server? |
|---|---|---|
postgresql-client (Debian main) |
Quick client matching your Debian release | No |
postgresql-client-N (Debian main, when available) |
Pin client major to Debian’s shipped branch | No |
PGDG (apt.postgresql.org) |
PostgreSQL 18, 15, or any supported major on any Debian release | No (client packages only in this guide) |
postgresql / postgresql-N |
Local dev database on the same machine | Yes |
Most readers who only need psql should start with sudo apt install postgresql-client. Add PGDG when you need a newer or specific major than Debian main provides.
Default PostgreSQL branch by Debian release
| Debian | Codename | Default postgresql-client major |
|---|---|---|
| Debian 13 | trixie |
17 |
| Debian 12 | bookworm |
15 |
| Debian 11 | bullseye |
13 |
On Debian 12, postgresql-client-15 is in main without PGDG. On Debian 13 or 11, install PostgreSQL 15 client via PGDG (postgresql-client-15), not from default archives alone.
Prerequisites
- Debian 11, 12, or 13 on amd64, arm64, or ppc64el (PGDG architectures).
- sudo for package installation.
- APT mirrors configured in
/etc/apt/sources.listorsources.list.d/. - cURL or wget when setting up PGDG manually.
Check your environment:
. /etc/os-release && printf '%s (%s)\n' "$PRETTY_NAME" "$VERSION_CODENAME"
dpkg --print-architecture
sudo apt updateOn the test host:
Debian GNU/Linux 13 (trixie) (trixie)
amd64Method 1: Install psql from Debian main (client only)
This is the answer to “install psql without Postgres”: the postgresql-client metapackage pulls psql, pg_dump, pg_restore, and pg_isready without postgresql-N server binaries.
sudo apt install -y postgresql-clientVerify the client and confirm no server package installed:
psql --version
which psql
dpkg -l 'postgresql-[0-9]*' 2>/dev/null | grep '^ii' || echo 'no postgresql-N server package'On Debian 13 after install:
psql (PostgreSQL) 17.10 (Debian 17.10-0+deb13u1)
/usr/bin/psql
no postgresql-N server packageAlso installed: pg_dump (PostgreSQL) 17.10.
Trying to connect without a local server shows the expected error:
psql -h 127.0.0.1 -U postgres -d postgres -c 'SELECT 1;'psql: error: connection to server at "127.0.0.1", port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?That is normal for a client-only install—you still need a running PostgreSQL instance somewhere to execute queries.
Pin a specific major from Debian (when available)
On Debian 12, install the Bookworm default client explicitly:
sudo apt install -y postgresql-client-15On Debian 13:
sudo apt install -y postgresql-client-17Use postgresql-client-N, not postgresql-N, when you want tools without the server.
Method 2: Install psql from the PostgreSQL Apt Repository (PGDG)
When you need PostgreSQL 18, an older 15 on Trixie, or the latest minor from PostgreSQL’s own packaging track, use PGDG.
Option A: Automated repository setup (recommended)
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.shThe script writes /etc/apt/sources.list.d/pgdg.sources and runs apt update. On Debian 13:
Writing /etc/apt/sources.list.d/pgdg.sources ...
Get:5 https://apt.postgresql.org/pub/repos/apt trixie-pgdg InRelease [230 kB]Option B: Manual deb822 configuration
Match the official manual steps:
sudo apt install -y curl ca-certificates
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail \
https://www.postgresql.org/media/keys/ACCC4CF8.ascCreate /etc/apt/sources.list.d/pgdg.sources (replace trixie with your codename):
sudo tee /etc/apt/sources.list.d/pgdg.sources <<EOF
Types: deb deb-src
URIs: https://apt.postgresql.org/pub/repos/apt
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")-pgdg
Architectures: $(dpkg --print-architecture)
Components: main
Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
EOF
sudo apt updateKey fingerprint after automated setup:
pub rsa4096 2011-10-13 [SC]
B97B 0AFC AA1A 47F0 44F2 44A0 7FCC 7D46 ACCC 4CF8
uid PostgreSQL Debian RepositoryInstall a versioned client from PGDG
List candidates, then install the major you need:
apt-cache policy postgresql-client-18 postgresql-client-15
sudo apt install -y postgresql-client-18On Debian 13:
postgresql-client-18:
Candidate: 18.4-1.pgdg13+1
postgresql-client-15:
Candidate: 15.18-1.pgdg13+1After install, the default psql points at the highest-priority alternative:
psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg13+1)Older clients remain on disk:
/usr/lib/postgresql/17/bin/psql --version
/usr/lib/postgresql/18/bin/psql --versionpsql (PostgreSQL) 17.10 (Debian 17.10-0+deb13u1)
psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg13+1)Use the versioned path when a remote server requires a matching major client.
Method 3: Install a local PostgreSQL server (optional)
Install a server only when you want a database on the same Debian machine—for example local app development:
sudo apt install -y postgresqlOr pin the major:
sudo apt install -y postgresql-17 postgresql-client-17Debian creates a cluster and enables postgresql.service. Check status:
sudo systemctl status postgresql --no-pager
pg_lsclustersCreate a Linux user matching your login for peer authentication, or set a password for postgres. For the full Debian server walkthrough—clusters, roles, PGDG, and uninstall—see install PostgreSQL on Debian.
Connect with psql
Remote server (typical for client-only installs)
psql -h db.example.com -p 5432 -U myuser -d mydbAdd -W to prompt for a password. For TLS:
psql "postgresql://[email protected]:5432/mydb?sslmode=verify-full"Use sslmode=verify-full in production—not require, which encrypts but does not verify the server certificate (PostgreSQL SSL docs).
Local server (after Method 3)
sudo -u postgres psqlOr as your user when peer auth is configured:
psql -d mydbInside psql, useful meta-commands:
| Command | Purpose |
|---|---|
\l |
List databases |
\dt |
List tables |
\du |
List roles |
\q |
Quit |
Upgrade psql
From Debian main:
sudo apt update && sudo apt install --only-upgrade postgresql-clientWith PGDG versioned clients:
sudo apt install --only-upgrade postgresql-client-18List all available versions before pinning:
apt list --all-versions postgresql-client-18 | headAudit installed packages with list installed packages on Debian:
dpkg -l 'postgresql-client*' | grep '^ii'Uninstall psql
Remove client packages:
sudo apt purge -y postgresql-client postgresql-client-17 postgresql-client-18
sudo apt autoremove -yIf you added PGDG and no longer need it:
sudo rm -f /etc/apt/sources.list.d/pgdg.sources
sudo apt updateRemoving a local server is separate—stop clusters, then purge server packages:
sudo pg_dropcluster --stop 17 main 2>/dev/null || true
sudo apt purge -y postgresql-17Confirm removal:
command -v psql || echo 'psql removed'Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Connection refused on localhost |
Client only—no server running | Install postgresql-N locally or point -h at a remote host |
psql: command not found |
Client not installed or wrong PATH | sudo apt install postgresql-client; check which psql |
no installation candidate for postgresql-client-15 on Trixie |
Wrong repo—15 not in Debian main on 13 | Add PGDG and install postgresql-client-15 from trixie-pgdg |
FATAL: password authentication failed |
Wrong user/password | Reset role password as admin or use correct -U / URI |
SSL error connecting to cloud DB |
Corporate proxy or missing CA | Install proxy CA; use sslmode=verify-full with correct sslrootcert |
Two psql versions—wrong default |
update-alternatives priority |
Run /usr/lib/postgresql/N/bin/psql or sudo update-alternatives --config psql |
PGDG vs Debian package versions
After PGDG is enabled, apt-cache policy postgresql-client-17 may show both Debian security and PGDG candidates. Debian’s 17.10-0+deb13u1 and PGDG’s 17.10-1.pgdg13+1 are both PostgreSQL 17.10—pick one track and upgrade through that source.
References
- PostgreSQL Linux downloads (Debian) — PGDG setup and supported releases
- PostgreSQL Apt Repository FAQ
- psql documentation
- APT command in Linux
- Install curl on Debian
- Install PostgreSQL on Debian — full server install, clusters, and PGDG
- Install PostgreSQL on Rocky Linux — related server setup on another distro
Summary
To install psql on Debian without a database server, run sudo apt install postgresql-client and check psql --version. Debian 13 ships PostgreSQL 17, 12 ships 15, and 11 ships 13 in main archives. When you need another major—18 on Trixie, 15 on Bullseye—add PGDG with apt.postgresql.org.sh and install postgresql-client-N. Connect with psql -h HOST -U USER -d DB, use versioned binaries under /usr/lib/postgresql/N/bin/ when multiple clients coexist, and install postgresql-N only when you want a local server on the same host. I verified client-only install (17.10) and PGDG 18.4 on Debian 13; Connection refused on localhost is expected until a server is running somewhere.

