How to Install PostgreSQL on Debian 13 (Trixie)
Install PostgreSQL on Debian 13 from Debian’s repository or PGDG, choose PostgreSQL 18, create a database role, and verify the server.
On this page
Debian 13 (Trixie) is the current Debian stable release. Debian includes PostgreSQL in its own APT repository; the PostgreSQL Global Development Group (PGDG) repository is an alternative when you need to select a specific major version. The Debian release information lists current release details, and PostgreSQL’s Debian installation instructions show supported releases and architectures.
If PostgreSQL is already installed and contains data, make a verified backup before installing another major version. A new package does not upgrade an existing database cluster; follow PostgreSQL’s major version upgrade instructions when you need to move existing data.
Prerequisites
- Debian 13 (Trixie) with internet access.
- A user account with
sudoprivileges, or access to the root account. - A terminal and basic familiarity with Linux commands.
Install PostgreSQL from Debian’s Repository
Debian’s postgresql package installs the PostgreSQL major version selected for Debian 13. Check the available candidate, then install it:
sudo apt update
apt-cache policy postgresql
sudo apt install postgresql
The package version may change as Debian publishes updates. Use psql --version or query the server after installation to see the version on your system.
Install PostgreSQL 18 from the PostgreSQL APT Repository
Use PGDG’s repository when you need to choose a major version. The official instructions support Debian 13 (trixie) and list postgresql-18 as a server package. The repository supports amd64, arm64, loong64 on Trixie and newer, and ppc64el architectures.
Install the repository setup package and run its configuration script:
sudo apt update
sudo apt install -y postgresql-common ca-certificates
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
Refresh the package index and check that APT can see PostgreSQL 18 before installing it:
sudo apt update
apt-cache policy postgresql-18
The candidate should come from the PGDG repository. Install the versioned server package:
sudo apt install postgresql-18
The versioned package keeps the server on major version 18 while receiving package updates within that major version. See PostgreSQL’s Debian installation instructions for supported versions and repository setup details.
Verify the Installation
Check the client version and service status:
psql --version
sudo systemctl status postgresql --no-pager
Ask the server for its version:
sudo -u postgres psql -c 'SELECT version();'
Create an Application Role and Database
Open an interactive session as PostgreSQL’s administrative postgres account:
sudo -u postgres psql
Create a login role, set its password with \password so it is not written in the SQL command or shell history, and create a database owned by that role:
CREATE ROLE app_user LOGIN;
\password app_user
CREATE DATABASE appdb OWNER app_user;
\q
Connect as the application role and verify the database and user:
psql -h localhost -U app_user -d appdb -W
At the psql prompt, run:
SELECT current_database(), current_user;
The -W option prompts for the role password. Keep the database bound to local access unless remote clients need to connect; configure authentication and firewall rules for the intended hosts before opening network access.
Manage the PostgreSQL Service
Use systemctl to manage PostgreSQL:
sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql
sudo systemctl status postgresql --no-pager
Troubleshooting
- If
psqlcannot connect, checksudo systemctl status postgresqland review recent service logs withsudo journalctl -u postgresql -e --no-pager. - Debian can run multiple PostgreSQL clusters or major versions. Use
pg_lsclustersto see installed clusters, versions, ports, and status; connect to the intended cluster and port. - If
apt-cache policy postgresql-18has no candidate after running the setup script, runsudo apt updateand confirm the PGDG source uses thetrixie-pgdgsuite.
Conclusion
Debian’s postgresql package installs the version maintained for Debian 13. If you need to choose a specific major version, PGDG’s repository supports Trixie and provides versioned packages such as postgresql-18.
For PostgreSQL on Ubuntu 26.04, see our Ubuntu 26.04 installation guide. For Debian 12, see our Debian 12 installation guide. For more PostgreSQL material, visit our PostgreSQL tutorials and PostgreSQL Reference.