PostgreSQL 17 is not the default on any current Ubuntu LTS release. Ubuntu 26.04 already moved to PostgreSQL 18, while Ubuntu 24.04 and 22.04 stay on older branches. If you need to install PostgreSQL 17 on Ubuntu for application compatibility or staged upgrades, the official PGDG repository is the clean path that keeps the 17.x series available on all three releases.
The PGDG repository is a better fit than downloading individual .deb files because APT keeps the server and client tools on the 17.x update track. PostgreSQL 17 was released on September 26, 2024 and stays supported through November 8, 2029, so the rest of the guide covers local access, remote connections, firewall rules, troubleshooting, and clean removal.
Install PostgreSQL 17 on Ubuntu
Ubuntu’s default repositories no longer provide PostgreSQL 17 on any current LTS release, so add PGDG first and then install the packages you need.
Compare Default PostgreSQL Versions on Ubuntu
The distro default changes by release, which is why PostgreSQL 17 needs the upstream repository everywhere in this guide.
| Ubuntu Release | Default PostgreSQL | Need PGDG for PostgreSQL 17? |
|---|---|---|
| Ubuntu 26.04 | PostgreSQL 18.x | Yes |
| Ubuntu 24.04 | PostgreSQL 16.x | Yes |
| Ubuntu 22.04 | PostgreSQL 14.x | Yes |
If your application can stay on Ubuntu 24.04’s default branch, use our guide to install PostgreSQL 16 on Ubuntu. If you need the older 15 series instead, install PostgreSQL 15 on Ubuntu with the same PGDG repository workflow.
Update Ubuntu Before Installing PostgreSQL 17
Refresh package metadata and apply pending upgrades before you add another repository. The -y flag accepts APT’s confirmation prompt automatically.
sudo apt update && sudo apt upgrade -y
This article uses
sudofor commands that need root privileges. If your account does not have sudo access yet, follow the guide to add a new user to sudoers on Ubuntu.
Install Required Packages for the PostgreSQL Repository on Ubuntu
Install the packages that fetch and verify the repository metadata. Desktop installs often already have some of them, but cloud and minimal Ubuntu images usually do not. The curl command downloads the signing key, gpg converts it to APT’s binary format, and lsb-release helps identify the Ubuntu codename.
sudo apt install -y curl ca-certificates gpg lsb-release
Import the PostgreSQL GPG Key on Ubuntu
PGDG signs its packages, so import the repository key before APT trusts that source.
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql.gpg
The gpg --dearmor step converts the ASCII-armored key into the binary format APT expects in a dedicated keyring file.
Add the PostgreSQL PGDG Repository on Ubuntu
Create a DEB822 source file for PGDG. This form is easier to read than the older one-line .list format and is more resilient when readers copy and paste it from the article.
printf '%s\n' \
"Types: deb" \
"URIs: https://apt.postgresql.org/pub/repos/apt" \
"Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")-pgdg" \
"Components: main" \
"Signed-By: /usr/share/keyrings/postgresql.gpg" \
| sudo tee /etc/apt/sources.list.d/postgresql.sources
The tee command writes the file with root privileges because a normal shell redirection would still run as your current user. The . /etc/os-release part reads Ubuntu’s VERSION_CODENAME automatically, so the same command writes resolute-pgdg, noble-pgdg, or jammy-pgdg as needed.
Types: deb URIs: https://apt.postgresql.org/pub/repos/apt Suites: resolute-pgdg Components: main Signed-By: /usr/share/keyrings/postgresql.gpg
Refresh APT so PostgreSQL 17 becomes available:
sudo apt update
Get:4 https://apt.postgresql.org/pub/repos/apt resolute-pgdg InRelease [180 kB] Get:5 https://apt.postgresql.org/pub/repos/apt resolute-pgdg/main amd64 Packages [379 kB] Reading package lists...
Verify the PostgreSQL 17 Package Source on Ubuntu
Before you install anything, confirm that APT sees the PostgreSQL 17 package from PGDG.
apt-cache policy postgresql-17
postgresql-17:
Installed: (none)
Candidate: 17.9-1.pgdg26.04+1
Version table:
17.9-1.pgdg26.04+1 500
500 https://apt.postgresql.org/pub/repos/apt resolute-pgdg/main amd64 Packages
On Ubuntu 24.04 and 22.04, the candidate line changes to 17.9-1.pgdg24.04+1 or 17.9-1.pgdg22.04+1. The important part is the source line from https://apt.postgresql.org/pub/repos/apt.
Install PostgreSQL 17 Server on Ubuntu
Install both packages on any host that will run the database locally. The client package also provides psql, pg_dump, and pg_restore.
sudo apt install -y postgresql-17 postgresql-client-17
Ubuntu creates the postgres system account, initializes the 17/main cluster, and enables local peer plus host scram-sha-256 authentication during the install.
Check the wrapper service first:
systemctl status postgresql --no-pager
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled)
Active: active (exited) since Wed 2026-03-11 13:43:08 AWST; 9s ago
Main PID: 28363 (code=exited, status=0/SUCCESS)
The active (exited) state is normal. postgresql.service is a wrapper that manages the cluster-specific unit, which runs as postgresql@17-main.service underneath it.
Verify the installed server version:
sudo -u postgres psql -c "SELECT version();"
version ------------------------------------------------------------------------------------------------------------------------------ PostgreSQL 17.9 (Ubuntu 17.9-1.pgdg26.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 15.2.0-12ubuntu1) 15.2.0, 64-bit (1 row)
On Ubuntu 24.04 and 22.04, the package suffix changes to pgdg24.04+1 or pgdg22.04+1, but the PostgreSQL major and minor release stays on the same 17.9 branch.
If the service did not start automatically, enable it explicitly:
sudo systemctl enable postgresql --now
Install Only the PostgreSQL 17 Client Tools on Ubuntu
If the server lives elsewhere and you only need the admin utilities on this machine, install the client package on its own.
sudo apt install -y postgresql-client-17
Verify that the client binaries are on your PATH:
command -v psql pg_dump pg_restore
/usr/bin/psql /usr/bin/pg_dump /usr/bin/pg_restore
This client-only path fits admin workstations, CI runners, and backup hosts that connect to a different PostgreSQL server.
Manage PostgreSQL 17 Service on Ubuntu
Ubuntu manages PostgreSQL through systemd. These are the service commands you will use most often.
sudo systemctl stop postgresql
sudo systemctl start postgresql
sudo systemctl restart postgresql
sudo systemctl reload postgresql
systemctl status postgresql --no-pager
Use reload for changes such as pg_hba.conf updates that PostgreSQL can apply without dropping active sessions. Use restart after startup-only changes such as listen_addresses, shared_buffers, or max_connections.
Configure PostgreSQL 17 on Ubuntu
A fresh install gives you the postgres superuser and the default 17/main cluster. The next steps cover the common first-run admin tasks.
Open the PostgreSQL Shell on Ubuntu
Use the postgres system account for local admin access.
sudo -u postgres psql
Inside psql, confirm how you are connected:
\conninfo
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
Exit the shell when you are finished:
\q
Create a PostgreSQL User on Ubuntu
Create a dedicated application role instead of using the postgres superuser from your app.
sudo -u postgres createuser --interactive <username>
Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n
Answer n to all three prompts for a typical application account. Then set a password for that role.
sudo -u postgres psql -c "ALTER USER <username> WITH PASSWORD 'your_secure_password';"
ALTER ROLE
Create a PostgreSQL Database on Ubuntu
Create the database, then grant the application role access to it.
sudo -u postgres createdb <database_name>
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE <database_name> TO <username>;"
GRANT
Use that role for your application connections so the postgres account stays reserved for administration.
Enable Remote Access to PostgreSQL 17 on Ubuntu
Local applications can stay on the Unix socket and skip this section. If another host needs PostgreSQL over TCP, change the listening address, add a matching pg_hba.conf rule, and then verify that port 5432 is open on the correct interface.
Edit postgresql.conf for PostgreSQL 17 on Ubuntu
Open the main server configuration file:
sudo nano /etc/postgresql/17/main/postgresql.conf
Use a specific address when only one interface should accept connections:
listen_addresses = 'localhost, 192.168.1.50'
Use all interfaces only when the firewall and pg_hba.conf will narrow access:
listen_addresses = '*'
Edit pg_hba.conf for PostgreSQL 17 on Ubuntu
Now add a host rule that matches the clients you want to allow.
sudo nano /etc/postgresql/17/main/pg_hba.conf
A common subnet rule looks like this:
# TYPE DATABASE USER ADDRESS METHOD host all all 192.168.1.0/24 scram-sha-256
The all values allow any database and role to match this line, while 192.168.1.0/24 limits access to that subnet. Tighten those fields when you know the exact database, user, or client address that should connect.
Restart PostgreSQL 17 and Verify Port 5432 on Ubuntu
Restart PostgreSQL after a listen_addresses change so the socket binding is rebuilt.
sudo systemctl restart postgresql
Use the grep command to isolate the PostgreSQL listener from the rest of the socket list:
ss -tlnp | grep 5432
LISTEN 0 200 0.0.0.0:5432 0.0.0.0:* LISTEN 0 200 [::]:5432 [::]:*
If you set a single IPv4 address, ss shows that address instead of 0.0.0.0. If the output still shows only 127.0.0.1:5432, PostgreSQL is still restricted to local access.
Configure UFW for PostgreSQL 17 on Ubuntu
If PostgreSQL will accept remote connections, tighten access with UFW rather than opening port 5432 broadly. The broader firewall workflow is covered in our guide to configure UFW firewall on Ubuntu.
Allow SSH before you enable UFW on a remote Ubuntu system. Otherwise the firewall can cut off the current session and leave you at the VM or cloud console.
If UFW is not installed yet, add it, allow SSH, and then enable the firewall. Ubuntu asks for confirmation the first time UFW starts.
sudo apt install -y ufw
sudo ufw allow 22/tcp
sudo ufw enable
Allow one client host with a single-IP rule:
sudo ufw allow from 192.168.1.100 to any port 5432
For a trusted subnet, use a CIDR range instead:
sudo ufw allow from 192.168.1.0/24 to any port 5432
Check the numbered rules after you add them:
sudo ufw status numbered
Status: active
To Action From
-- ------ ----
[ 1] 22/tcp ALLOW IN Anywhere
[ 2] 5432 ALLOW IN 192.168.1.0/24
[ 3] 22/tcp (v6) ALLOW IN Anywhere (v6)
If you later remove the PostgreSQL rule, use its number from that list:
sudo ufw delete 2
Troubleshoot PostgreSQL 17 on Ubuntu
These are the failure modes readers hit most often after the package install, especially when they are switching from local-only access to remote connections.
Fix Peer Authentication Failed for User postgres on Ubuntu
Ubuntu’s default local PostgreSQL setup uses peer authentication for the postgres role. Running psql -U postgres from your own Linux account usually fails with this error:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres"
Use the postgres system account for local admin work, or connect over TCP with a password-enabled role instead.
sudo -u postgres psql -c "SELECT current_user;"
current_user -------------- postgres (1 row)
Fix Connection Refused Errors for PostgreSQL 17 on Ubuntu
If a remote client cannot reach the server, PostgreSQL usually returns a plain connection refusal.
psql: error: connection to server at "192.168.1.50", port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?
This usually means PostgreSQL is still bound to localhost, the service is down, or UFW never opened port 5432 for the client address. Re-check the service state, the listening socket, the firewall rules, and the matching host line in pg_hba.conf. If ss still shows only 127.0.0.1:5432, return to the remote-access section and fix listen_addresses before you restart the service again.
Fix postgresql.service Not Found on Ubuntu
This message appears when the server package or the shared PostgreSQL service helpers are no longer installed.
Unit postgresql.service could not be found.
Re-add the PGDG repository if needed, then reinstall the server packages:
sudo apt install -y postgresql-17 postgresql-client-17
● postgresql.service - PostgreSQL RDBMS
Active: active (exited)
Update PostgreSQL 17 on Ubuntu
Minor PostgreSQL 17 releases arrive through the same PGDG repository. Use --only-upgrade so APT updates the package only when it is already installed.
sudo apt update
sudo apt install --only-upgrade -y postgresql-17 postgresql-client-17
Verify the running server version after the update:
sudo -u postgres psql -c "SELECT version();"
version ------------------------------------------------------------------------------------------------------------------------------ PostgreSQL 17.9 (Ubuntu 17.9-1.pgdg26.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 15.2.0-12ubuntu1) 15.2.0, 64-bit (1 row)
Remove PostgreSQL 17 from Ubuntu
Pick the removal path that matches whether you want to keep or delete the 17/main cluster.
Remove PostgreSQL 17 Packages but Keep Data on Ubuntu
This path removes the server and client binaries but keeps the PostgreSQL 17 data and configuration on disk for a later reinstall.
sudo apt remove -y postgresql-17 postgresql-client-17
sudo apt autoremove -y
The existing cluster stays in /var/lib/postgresql/17/main, the config stays in /etc/postgresql/17/main, and the version-specific log file stays in /var/log/postgresql/postgresql-17-main.log. If no other PostgreSQL major version is installed, apt autoremove also removes the shared postgresql-common helpers.
Remove PostgreSQL 17 Completely on Ubuntu
This path deletes the PostgreSQL 17 cluster itself. Back up anything important first with
pg_dumporpg_dumpall, because the data files do not come back after the cluster is dropped.
Drop the 17/main cluster before you purge the packages:
sudo pg_dropcluster --stop 17 main
Confirm that no PostgreSQL 17 cluster is left behind:
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
Once the cluster is gone, purge the packages and let APT clean up any now-unused shared helpers:
sudo apt purge -y postgresql-17 postgresql-client-17
sudo apt autoremove -y
This sequence removes the version-specific cluster directories instead of asking you to clean up /var/lib/postgresql/17, /etc/postgresql/17, and the matching log file by hand.
Remove the PGDG Repository from Ubuntu
If you no longer want PGDG packages on this machine, remove the source file and keyring, then refresh APT.
sudo rm -f /etc/apt/sources.list.d/postgresql.sources
sudo rm -f /usr/share/keyrings/postgresql.gpg
sudo apt update
Check that Ubuntu now falls back to its distro-default PostgreSQL branch:
apt-cache policy postgresql
postgresql:
Installed: (none)
Candidate: 16+257build1.1
Version table:
16+257build1.1 500
500 http://au.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages
16+257build1 500
500 http://au.archive.ubuntu.com/ubuntu noble/main amd64 Packages
On Ubuntu 26.04 the candidate becomes PostgreSQL 18 again, and on Ubuntu 22.04 it becomes PostgreSQL 14. If you query apt-cache policy postgresql-17 after removing PGDG, Ubuntu prints no package output because that major is no longer available from the configured sources.
PostgreSQL 17 on Ubuntu FAQ
Ubuntu 26.04 ships PostgreSQL 18, Ubuntu 24.04 ships PostgreSQL 16, and Ubuntu 22.04 ships PostgreSQL 14. PostgreSQL 17 is not the default on any current Ubuntu LTS, so the PGDG repository is required on all three releases.
Yes. Install postgresql-client-17 if you only need psql, pg_dump, and pg_restore on a workstation, CI runner, or backup host. You do not need the postgresql-17 server package unless this machine will run the database itself.
Yes. PostgreSQL 17 was released on September 26, 2024 and stays supported until November 8, 2029. The PostgreSQL project continues to publish minor updates such as 17.9 through the PGDG repository during that support window.
Ubuntu’s default local PostgreSQL setup uses peer authentication for the postgres role. That means the Linux account name must match the PostgreSQL role, so administrative local access usually works with sudo -u postgres psql instead of psql -U postgres.
Conclusion
PostgreSQL 17 is installed on Ubuntu through the PGDG repository, so the 17.x branch stays available on 26.04, 24.04, and 22.04 through normal APT updates. If you plan to expose it beyond localhost, configure UFW firewall on Ubuntu next, or install PostgreSQL 16 on Ubuntu if your stack can stay on the distro default on 24.04.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>