How to Install PostgreSQL 15 on Ubuntu 26.04, 24.04 and 22.04

Last updated Thursday, May 7, 2026 6:24 pm Joshua James 9 min read 5 comments

PostgreSQL 15 is available on Ubuntu 22.04, 24.04, and 26.04 through the official PGDG APT repository. Ubuntu’s default repositories ship different PostgreSQL branches (14 on 22.04, 16 on 24.04, and 18 on 26.04), so PGDG is the direct path when an application still needs the PostgreSQL 15 series instead of the default server package.

PostgreSQL 15 introduced the SQL-standard MERGE command, Zstandard backup compression, enhanced logical replication, JSON log output, and improved sort performance. You will install PostgreSQL 15.17 from PGDG, verify the service and client tools, and cover optional local users, remote access, firewall rules, updates, and removal.

Install PostgreSQL 15 on Ubuntu

Compare PostgreSQL Versions for Ubuntu

Start by confirming that PostgreSQL 15 is the branch you need. The default Ubuntu package may be simpler when your application supports the branch shipped with your Ubuntu release.

PostgreSQL VersionAvailability on UbuntuChoose It WhenTrade-offs
PostgreSQL 15PGDG repository on 22.04/24.04/26.04Your application depends on the 15 series, MERGE, logical replication behavior, or extension compatibility already tested on 15Requires the PGDG repository; final PostgreSQL project release is scheduled for November 11, 2027
PostgreSQL 16Ubuntu 24.04 default; PGDG on 22.04/26.04You want a newer branch while keeping close compatibility with PostgreSQL 15-era applicationsPGDG is still needed on Ubuntu 22.04 and 26.04
PostgreSQL 17PGDG on 22.04/24.04/26.04You need PostgreSQL 17 features such as incremental backup improvementsNot the default PostgreSQL branch on current Ubuntu LTS releases
PostgreSQL 18Ubuntu 26.04 default; PGDG on 22.04/24.04You want the newest stable PostgreSQL branch and your application stack supports itNewest branch; extensions, migrations, and vendor support may need extra compatibility checks

Choose PostgreSQL 15 when the application, extension set, migration plan, or vendor support matrix specifically calls for it. PostgreSQL 15 remains supported by the PostgreSQL project until November 11, 2027; plan a major-version upgrade before that date.

Update Ubuntu Before Installing PostgreSQL

Before adding any external repository, update your package index and upgrade any outdated packages:

sudo apt update && sudo apt upgrade

If you do not have sudo configured, see our guide on adding a user to sudoers on Ubuntu.

Install Required Packages for PostgreSQL

Install the packages needed to download the PostgreSQL repository key over HTTPS. The curl command fetches the key, and ca-certificates lets APT validate TLS certificates when it contacts the repository:

sudo apt install curl ca-certificates -y

Import the PostgreSQL GPG Key

The PostgreSQL team signs packages from the PGDG repository. Store the official ASCII-armored repository key in the path used by the PostgreSQL Ubuntu download instructions:

sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -fsSLo /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc

This stores the key at /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc, which the DEB822 source file references with Signed-By.

Add the PostgreSQL APT Repository

With the key in place, add the official PostgreSQL APT repository as a DEB822 source. This uses your Ubuntu codename from /etc/os-release and your system architecture from dpkg:

. /etc/os-release
printf '%s\n' \
'Types: deb' \
'URIs: https://apt.postgresql.org/pub/repos/apt' \
"Suites: ${VERSION_CODENAME}-pgdg" \
'Components: main' \
"Architectures: $(dpkg --print-architecture)" \
'Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc' \
| sudo tee /etc/apt/sources.list.d/pgdg.sources > /dev/null

Inspect the source file if you want to confirm the generated codename and architecture:

cat /etc/apt/sources.list.d/pgdg.sources

Relevant output on Ubuntu 26.04 includes:

Types: deb
URIs: https://apt.postgresql.org/pub/repos/apt
Suites: resolute-pgdg
Components: main
Architectures: amd64
Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc

The printf output pipes through sudo tee because normal shell redirection cannot write to /etc/apt/sources.list.d/ with elevated privileges. After adding the repository, refresh the package index:

sudo apt update

APT should now accept the PGDG source. Confirm the PostgreSQL 15 package candidate before installing:

apt-cache policy postgresql-15
postgresql-15:
  Installed: (none)
  Candidate: 15.17-1.pgdg26.04+2
  Version table:
     15.17-1.pgdg26.04+2 500
        500 https://apt.postgresql.org/pub/repos/apt resolute-pgdg/main amd64 Packages

This output confirms that postgresql-15 comes from the PostgreSQL APT repository rather than Ubuntu’s default repositories. Ubuntu 24.04 currently shows 15.17-1.pgdg24.04+1, and Ubuntu 22.04 shows 15.17-1.pgdg22.04+1.

Install PostgreSQL 15 Packages

Install PostgreSQL 15 along with its client utilities. The postgresql-15 package includes the database server, while postgresql-client-15 provides command-line tools like psql for interacting with databases:

sudo apt install postgresql-15 postgresql-client-15

APT downloads and installs PostgreSQL 15 along with all required dependencies. During installation, the package automatically creates a postgres system user, initializes a default database cluster, and configures the PostgreSQL service to start automatically on boot.

Verify the PostgreSQL 15 Installation

After installation completes, verify that the wrapper service is active and enabled:

systemctl is-active postgresql
systemctl is-enabled postgresql

A healthy install returns:

active
enabled

The main postgresql systemd unit is a wrapper that manages individual database clusters. Confirm that the PostgreSQL 15 cluster accepts local connections by querying the server version:

sudo -u postgres psql -c "SELECT version();"
                                                   version                                                   
-------------------------------------------------------------------------------------------------------------
 PostgreSQL 15.17 (Ubuntu 15.17-1.pgdg26.04+2) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 15.2.0-15ubuntu1) 15.2.0, 64-bit
(1 row)

Ubuntu 24.04 prints the same PostgreSQL 15.17 server release with a 15.17-1.pgdg24.04+1 package revision. Ubuntu 22.04 prints 15.17-1.pgdg22.04+1.

If PostgreSQL does not start automatically, enable and start it with the following command:

sudo systemctl enable postgresql --now

Install Only PostgreSQL 15 Client Tools

If you only need psql and the PostgreSQL client utilities for remote administration, install the client package after configuring the PGDG repository:

sudo apt install postgresql-client-15

Verify the client version:

psql --version
psql (PostgreSQL) 15.17 (Ubuntu 15.17-1.pgdg26.04+2)

The client-only package does not create a local database cluster or start the PostgreSQL server service.

Manage the PostgreSQL 15 Service on Ubuntu

PostgreSQL runs as a systemd service. Use these commands to control the database server:

sudo systemctl stop postgresql
sudo systemctl start postgresql
sudo systemctl restart postgresql
sudo systemctl reload postgresql
systemctl status postgresql

Use restart after changing PostgreSQL settings that require a new server process. Use reload only for changes PostgreSQL can apply without a full restart.

Configure PostgreSQL 15 on Ubuntu

Access the PostgreSQL 15 Shell

PostgreSQL uses role-based authentication. During installation, the system creates a superuser role named postgres along with a corresponding Linux system account. To access the PostgreSQL interactive shell, switch to the postgres user:

sudo -i -u postgres

Once logged in as the postgres user, start the interactive SQL shell:

psql

The terminal prompt changes to postgres=#, confirming the database connection:

psql (15.17 (Ubuntu 15.17-1.pgdg26.04+2))
Type "help" for help.

postgres=#

To exit the shell, type \q, then type exit to return to your regular user account.

Alternatively, access the PostgreSQL shell directly without switching users:

sudo -u postgres psql

This is faster for quick database operations when you do not need a persistent postgres session.

Create a PostgreSQL Database User

For security best practices, avoid using the postgres superuser for application connections. Create a dedicated user with appropriate privileges, replacing app_user with your preferred role name:

sudo -u postgres createuser --interactive app_user

The --interactive flag prompts you to specify whether the new user should have superuser, database creation, or role creation privileges:

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

For a standard application user, answer “no” to all prompts to follow the principle of least privilege.

Set a password for the new user by connecting to the database and running:

sudo -u postgres psql -c "ALTER USER app_user WITH PASSWORD 'your_secure_password';"
ALTER ROLE

Create a PostgreSQL Database

Once you create a user, create a database and grant access. Replace app_db with your database name:

sudo -u postgres createdb app_db

Grant the new user full privileges on this database:

sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE app_db TO app_user;"
GRANT

Verify the grant succeeded by listing all databases and their access privileges:

sudo -u postgres psql -c "\l"
                                                   List of databases
   Name    |  Owner   | Encoding | Collate |  Ctype  | ICU Locale | Locale Provider |   Access privileges   
-----------+----------+----------+---------+---------+------------+-----------------+-----------------------
 postgres  | postgres | UTF8     | C.UTF-8 | C.UTF-8 |            | libc            | 
 template0 | postgres | UTF8     | C.UTF-8 | C.UTF-8 |            | libc            | =c/postgres          +
           |          |          |         |         |            |                 | postgres=CTc/postgres
 template1 | postgres | UTF8     | C.UTF-8 | C.UTF-8 |            | libc            | =c/postgres          +
           |          |          |         |         |            |                 | postgres=CTc/postgres
 app_db    | postgres | UTF8     | C.UTF-8 | C.UTF-8 |            | libc            | =Tc/postgres         +
           |          |          |         |         |            |                 | postgres=CTc/postgres+
           |          |          |         |         |            |                 | app_user=CTc/postgres
(4 rows)

The Access privileges column shows that app_user has connect (c), temporary table (T), and create (C) privileges on the app_db database.

Configure UFW Firewall for PostgreSQL on Ubuntu

By default, PostgreSQL listens only on localhost (127.0.0.1), which means no firewall configuration is needed for local-only access. However, if you plan to allow remote connections, you must configure your firewall to permit traffic on PostgreSQL’s default port (5432). For more details, see our UFW firewall guide for Ubuntu.

Install UFW and allow SSH before enabling the firewall if you manage the server remotely:

Enabling UFW without an SSH allow rule can lock you out of a remote server. Confirm your access method before running sudo ufw enable.

sudo apt install ufw -y
sudo ufw allow OpenSSH
sudo ufw enable

To allow PostgreSQL connections from a specific IP address (recommended):

sudo ufw allow from 192.168.1.100 to any port 5432

Similarly, to allow connections from an entire subnet:

sudo ufw allow from 192.168.1.0/24 to any port 5432

After adding rules, verify your firewall configuration:

sudo ufw status numbered
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] OpenSSH                    ALLOW IN    Anywhere
[ 2] 5432                       ALLOW IN    192.168.1.0/24

To remove a rule, use the rule number from the output above:

sudo ufw delete 2

Replace the IP addresses and subnet examples with your actual network configuration. Avoid opening port 5432 to the entire internet (ufw allow 5432) unless you implement additional security measures like SSL/TLS encryption and strong authentication.

Enable Remote Access for PostgreSQL 15 on Ubuntu

By default, PostgreSQL only accepts connections from the local machine. To allow remote connections, you must modify two configuration files: postgresql.conf to change the listening address, and pg_hba.conf to configure client authentication.

Configure the PostgreSQL Listening Address

First, identify the PostgreSQL configuration directory for your installation:

ls /etc/postgresql/
15

This output confirms PostgreSQL 15 installation. Open the main configuration file:

sudo nano /etc/postgresql/15/main/postgresql.conf

Locate the listen_addresses setting. By default, PostgreSQL 15 listens on localhost. Change it to allow connections from specific addresses or all interfaces:

For a specific IP address (more secure):

listen_addresses = 'localhost, 192.168.1.50'

For all network interfaces (use with caution):

listen_addresses = '*'

Finally, save and close the file (Ctrl+O, Enter, Ctrl+X in nano).

Configure PostgreSQL Client Authentication

Next, edit the host-based authentication file to specify which clients can connect and how they authenticate:

sudo nano /etc/postgresql/15/main/pg_hba.conf

Then, add a line at the end of the file to allow remote connections. The format follows this pattern:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             192.168.1.0/24          scram-sha-256

This configuration allows all users to connect to all databases from the 192.168.1.0/24 subnet using password authentication with the secure SCRAM-SHA-256 method. Adjust the database, user, and address fields to match your security requirements.

Apply PostgreSQL Configuration Changes

After modifying both configuration files, restart PostgreSQL to apply the changes:

sudo systemctl restart postgresql

Then verify that PostgreSQL now listens on the configured addresses:

sudo ss -tln 'sport = :5432'
State  Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0      244          0.0.0.0:5432      0.0.0.0:*

The 0.0.0.0:5432 output indicates PostgreSQL listens on all interfaces. If you configure a specific IP, you would see that address instead.

Troubleshoot Common PostgreSQL Issues on Ubuntu

Fix PostgreSQL Connection Refused Errors

If you receive “connection refused” when trying to connect remotely, the error typically looks like:

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?

To diagnose this issue, verify these items in order:

  1. Check PostgreSQL status: Run systemctl status postgresql
  2. Verify listening address: Run sudo ss -tln 'sport = :5432'
  3. Check firewall rules: Run sudo ufw status
  4. Review pg_hba.conf: Ensure the file allows your client IP

Fix PostgreSQL Authentication Failed

If you see a password authentication error, it typically appears as:

psql: error: connection to server at "192.168.1.50", port 5432 failed: FATAL:  password authentication failed for user "app_user"

The issue typically involves one of these causes:

  • Incorrect password: Reset it with ALTER USER username WITH PASSWORD 'newpassword';
  • Wrong authentication method: Check that pg_hba.conf matches your connection method
  • User does not exist: Verify with \du in psql

Fix PostgreSQL Repository Issues

If apt update shows errors about the PostgreSQL repository, you may see:

E: The repository 'https://apt.postgresql.org/pub/repos/apt noble-pgdg Release' does not have a Release file.

To resolve this, verify your configuration:

cat /etc/apt/sources.list.d/pgdg.sources
sudo apt update
apt-cache policy postgresql-15

Ensure the Suites line contains your correct Ubuntu codename followed by -pgdg, such as resolute-pgdg for Ubuntu 26.04, noble-pgdg for Ubuntu 24.04, or jammy-pgdg for Ubuntu 22.04. Rerun sudo apt update after fixing the file so APT ingests the corrected source before you check the package policy again.

View PostgreSQL 15 Logs

For detailed error information, review the PostgreSQL logs. The tail command displays the most recent entries:

sudo tail -50 /var/log/postgresql/postgresql-15-main.log

Update PostgreSQL 15 on Ubuntu

The PGDG repository delivers updates through standard APT package management. To update PostgreSQL 15 to the latest patch release:

sudo apt update
sudo apt install --only-upgrade postgresql-15 postgresql-client-15

The --only-upgrade flag ensures the command only updates the packages if they already exist, preventing accidental installation on systems where PostgreSQL 15 might have been removed. For related guides, see installing PostgreSQL 16 on Ubuntu or installing PostgreSQL 17 on Ubuntu.

Remove PostgreSQL 15 from Ubuntu

PostgreSQL package removal can preserve or delete database clusters. Decide which state you want before running purge commands, especially on production systems.

Remove PostgreSQL 15 Packages Only (Preserve Data)

To remove the server and client packages while keeping the PostgreSQL 15 data and configuration directories:

sudo apt remove postgresql-15 postgresql-client-15

This approach allows reinstallation later without losing the 15/main cluster under /var/lib/postgresql/15/ and its configuration under /etc/postgresql/15/.

Purge PostgreSQL 15 Packages

To purge package configuration, run:

sudo apt purge postgresql-15 postgresql-client-15

If APT asks whether to remove PostgreSQL directories, answer no unless you have verified backups and intend to delete the database cluster. The prompt controls cluster data, configuration, and logs, not only package metadata.

Preview dependency cleanup before removing anything else:

sudo apt autoremove --dry-run

If the preview only lists PostgreSQL dependencies you no longer need, run the cleanup:

sudo apt autoremove

The autoremove command cleans up dependencies that were installed with PostgreSQL and are no longer required. Review APT’s package list before confirming on shared servers.

Remove PostgreSQL 15 Including Databases

The next commands permanently delete the PostgreSQL 15 cluster, including databases, configuration, and logs. Back up important data first with pg_dump, pg_dumpall, or your normal backup process.

sudo pg_dropcluster --stop 15 main
sudo apt purge postgresql-15 postgresql-client-15

The pg_dropcluster command removes the 15/main cluster through PostgreSQL’s own tooling before package purge runs. If you created additional PostgreSQL 15 clusters, list them first with pg_lsclusters and remove only the clusters you intend to delete.

Preview dependency cleanup after the purge:

sudo apt autoremove --dry-run

If the preview only lists PostgreSQL dependencies you no longer need, run:

sudo apt autoremove

Remove the PostgreSQL APT Repository

If you no longer need the PostgreSQL APT repository, remove the source file and signing key. The command also removes the older source and keyring paths used by previous LinuxCapable PostgreSQL 15 instructions when they exist:

sudo rm -f /etc/apt/sources.list.d/pgdg.sources /etc/apt/sources.list.d/postgresql.sources
sudo rm -f /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc /usr/share/keyrings/postgresql.gpg
sudo rmdir /usr/share/postgresql-common/pgdg 2>/dev/null || true
sudo apt update

After running apt update, verify the repository removal succeeded:

apt-cache policy postgresql-15
N: Unable to locate package postgresql-15

This output confirms APT no longer has access to PostgreSQL 15 from PGDG. If another repository still provides postgresql-15, review the source shown in apt-cache policy before assuming it is safe to install from that origin.

Conclusion

PostgreSQL 15 now installs on Ubuntu through the PGDG APT repository with verified server and client packages, local service checks, and optional remote-access controls. Keep patch releases current with APT, and use the PostgreSQL documentation, PostgreSQL 15 release notes, and PostgreSQL community resources when planning SSL/TLS, backups, monitoring, or a future major-version upgrade.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee

5 thoughts on “How to Install PostgreSQL 15 on Ubuntu 26.04, 24.04 and 22.04”

  1. Hi, i have a problem with installing on WSL 20.04, This is the error when trying to use the command:
    “sudo apt install postgresql-client-15 postgresql-15”
    => postgresql-15 : Depends: postgresql-common (>= 241~) but 214ubuntu0.1 is to be installed
    Depends: libpq5 (>= 14~beta2) but 12.22-0ubuntu0.20.04.1 is to be installed
    Recommends: sysstat but it is not going to be installed
    postgresql-client-15 : Depends: libpq5 (>= 15.12) but 12.22-0ubuntu0.20.04.1 is to be installed.

    Reply
    • Thanks for reporting this, Alex. The dependency errors you are seeing occur because Ubuntu 20.04’s base libraries are too old for the current PostgreSQL 15 packages. Specifically, your system has libpq5 version 12.22 and postgresql-common version 214, but PostgreSQL 15 now requires libpq5 15.12+ and postgresql-common 241+.

      Ubuntu 20.04 LTS reached end of standard support in April 2025, and this guide covers Ubuntu 22.04 and 24.04 LTS. The PostgreSQL APT repository still has packages for 20.04 (focal-pgdg), but dependency conflicts with the aging base system libraries make installation unreliable.

      Your best option is to upgrade your WSL Ubuntu installation to 22.04 or 24.04. In WSL, you can either install a fresh Ubuntu 22.04/24.04 distribution from the Microsoft Store, or attempt an in-place upgrade with sudo do-release-upgrade. After upgrading, the PostgreSQL 15 installation will work without dependency issues.

      Reply
    • Hello,

      Yes, the commands in this guide are designed specifically for Ubuntu and its versions, not Linux Mint or other Ubuntu-based distributions.

      If you’re using Linux Mint, Pop!_OS, or any other Ubuntu derivative, you’ll need to modify this part of the command:

      echo deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main | sudo tee /etc/apt/sources.list.d/postgresql.list

      The segment $(lsb_release -cs)-pgdg dynamically fetches the codename of your Ubuntu version. For example, if you’re using Linux Mint 22 (which is based on Ubuntu 24.04), you would replace that section with noble-pgdg.

      This ensures the command matches the right version for your system.

      Feel free to reach out if you have any further questions!

      Reply
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: