How to Install psql on Debian

Install psql on Debian 11, 12, or 13 with postgresql-client from main archives (no server), or add the PostgreSQL Apt Repository for postgresql-client-18 and other majors. Verify with psql --version, connect remotely, and uninstall cleanly.

Published

Updated

Read time 7 min read

Reviewed byDeepak Prasad

Install psql on Debian hero with DEBIAN GUIDE badge, PostgreSQL client graphics, and postgresql-client plus PGDG repository feature highlights

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).

NOTE
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.list or sources.list.d/.
  • cURL or wget when setting up PGDG manually.

Check your environment:

bash
. /etc/os-release && printf '%s (%s)\n' "$PRETTY_NAME" "$VERSION_CODENAME"
dpkg --print-architecture
sudo apt update

On the test host:

text
Debian GNU/Linux 13 (trixie) (trixie)
amd64

Method 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.

bash
sudo apt install -y postgresql-client

Verify the client and confirm no server package installed:

bash
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:

text
psql (PostgreSQL) 17.10 (Debian 17.10-0+deb13u1)
/usr/bin/psql
no postgresql-N server package

Also installed: pg_dump (PostgreSQL) 17.10.

Trying to connect without a local server shows the expected error:

bash
psql -h 127.0.0.1 -U postgres -d postgres -c 'SELECT 1;'
text
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:

bash
sudo apt install -y postgresql-client-15

On Debian 13:

bash
sudo apt install -y postgresql-client-17

Use 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.

bash
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

The script writes /etc/apt/sources.list.d/pgdg.sources and runs apt update. On Debian 13:

text
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:

bash
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.asc

Create /etc/apt/sources.list.d/pgdg.sources (replace trixie with your codename):

bash
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 update

Key fingerprint after automated setup:

text
pub   rsa4096 2011-10-13 [SC]
      B97B 0AFC AA1A 47F0 44F2  44A0 7FCC 7D46 ACCC 4CF8
uid                      PostgreSQL Debian Repository

Install a versioned client from PGDG

List candidates, then install the major you need:

bash
apt-cache policy postgresql-client-18 postgresql-client-15
sudo apt install -y postgresql-client-18

On Debian 13:

text
postgresql-client-18:
  Candidate: 18.4-1.pgdg13+1
postgresql-client-15:
  Candidate: 15.18-1.pgdg13+1

After install, the default psql points at the highest-priority alternative:

text
psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg13+1)

Older clients remain on disk:

bash
/usr/lib/postgresql/17/bin/psql --version
/usr/lib/postgresql/18/bin/psql --version
text
psql (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:

bash
sudo apt install -y postgresql

Or pin the major:

bash
sudo apt install -y postgresql-17 postgresql-client-17

Debian creates a cluster and enables postgresql.service. Check status:

bash
sudo systemctl status postgresql --no-pager
pg_lsclusters

Create 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)

bash
psql -h db.example.com -p 5432 -U myuser -d mydb

Add -W to prompt for a password. For TLS:

bash
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)

bash
sudo -u postgres psql

Or as your user when peer auth is configured:

bash
psql -d mydb

Inside psql, useful meta-commands:

Command Purpose
\l List databases
\dt List tables
\du List roles
\q Quit

Upgrade psql

From Debian main:

bash
sudo apt update && sudo apt install --only-upgrade postgresql-client

With PGDG versioned clients:

bash
sudo apt install --only-upgrade postgresql-client-18

List all available versions before pinning:

bash
apt list --all-versions postgresql-client-18 | head

Audit installed packages with list installed packages on Debian:

bash
dpkg -l 'postgresql-client*' | grep '^ii'

Uninstall psql

Remove client packages:

bash
sudo apt purge -y postgresql-client postgresql-client-17 postgresql-client-18
sudo apt autoremove -y

If you added PGDG and no longer need it:

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

Removing a local server is separate—stop clusters, then purge server packages:

bash
sudo pg_dropcluster --stop 17 main 2>/dev/null || true
sudo apt purge -y postgresql-17

Confirm removal:

bash
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


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.


Frequently Asked Questions

1. How do I install psql on Debian without the PostgreSQL server?

Run sudo apt install postgresql-client. Debian installs psql, pg_dump, and pg_restore from the client metapackage without postgresql-N server packages. Verify with psql --version and confirm no postgresql-N package is installed.

2. What is the difference between postgresql-client and postgresql on Debian?

postgresql-client installs command-line tools only (psql, pg_dump, pg_restore). postgresql or postgresql-N installs the database server, creates a local cluster, and starts the postgresql service. Use postgresql-client when you only connect to remote databases.

3. How do I install a specific psql version on Debian 13?

Add the PostgreSQL Apt Repository (PGDG), then sudo apt install postgresql-client-18 (or 15, 16, 17). PGDG publishes multiple majors on trixie-pgdg. Debian main ships postgresql-client-17 on Trixie by default.

4. Which Debian release ships which PostgreSQL version by default?

Debian 13 (trixie) defaults to PostgreSQL 17, Debian 12 (bookworm) to 15, and Debian 11 (bullseye) to 13. apt install postgresql-client follows that default. Use PGDG when you need a different major.

5. Should my psql client match the server version?

The client should be the same major version as the server or newer. An older psql against a newer server can mis-handle new features. When in doubt, install the latest postgresql-client-N from PGDG.

6. How do I connect to a remote PostgreSQL server with psql?

Run psql -h HOST -p 5432 -U USERNAME -d DATABASE. Add -W to prompt for a password, or pass a URI: psql "postgresql://user:pass@host:5432/dbname?sslmode=verify-full".

7. How do I add the official PostgreSQL Apt Repository on Debian?

Run sudo apt install postgresql-common, then sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh. Alternatively create /etc/apt/sources.list.d/pgdg.sources manually with suite CODENAME-pgdg per postgresql.org/download/linux/debian.

8. How do I uninstall psql from Debian?

sudo apt purge postgresql-client postgresql-client-17 postgresql-client-18 (and other versioned clients you installed). Remove /etc/apt/sources.list.d/pgdg.sources if you added PGDG. Server removal is separate: apt purge postgresql-N and pg_dropcluster if you installed a local server.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on …