>_ blog · databases

How To Install PostgreSQL 18 on Ubuntu 24.04

A tested, production-minded guide to installing PostgreSQL 18 on Ubuntu 24.04 — from the official repository to secure remote access, tuning and backups.

Version:PostgreSQL 18
CurrentBy DevNextBD Team4 min read

What's different in PostgreSQL 18

  • New asynchronous I/O (io_method) speeds up sequential scans, bitmap heap scans and vacuum
  • Data checksums are on by default for new clusters, so silent disk corruption is detected
  • uuidv7() creates time-ordered UUIDs that are much friendlier to indexes than random ones
  • OAuth sign-in support; MD5 passwords are deprecated — use SCRAM-SHA-256
  • pg_upgrade keeps planner statistics, so queries are fast right after an upgrade
  • Best choice for new projects: supported until 14 November 2030

Supported until 14 November 2030

PostgreSQL is the open-source database we reach for most often: reliable, fast and rich in features. This guide installs PostgreSQL 18 on Ubuntu 24.04 LTS, secures it, creates a database for your application, allows remote connections safely and sets up backups. Every command was written for a fresh server; read the explanation before running each one.

Which version should you install?

Each major version is supported for five years. Pick the newest one your application, drivers and hosting support.

VersionReleasedSupported untilChoose it when
1825 September 202514 November 2030Starting something new
1726 September 20248 November 2029Your tools don't support 18 yet
1614 September 20239 November 2028You want Ubuntu's own package

You are reading the guide for PostgreSQL 18, released on 25 September 2025 and supported until 14 November 2030.

Prerequisites

  • A server running Ubuntu 24.04 with at least 1 GB of RAM (2 GB or more for production).
  • A user with sudo rights. Don't work as root.
  • The UFW firewall enabled, with SSH allowed: sudo ufw allow OpenSSH && sudo ufw enable.

Step 1 — Add the official PostgreSQL repository

Ubuntu 24.04's own repositories only include PostgreSQL 16. Version 18 comes from the PostgreSQL project's own repository (PGDG), which is signed and maintained by the PostgreSQL developers. The postgresql-common package includes a script that adds it safely:

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

The script asks you to press Enter, then imports the repository's signing key and adds the source for your Ubuntu release. The same steps work on Ubuntu 22.04 and 26.04.

Step 2 — Install PostgreSQL 18

Install the server with its version number in the package name. That pins you to 18: a later apt upgrade installs new 18.x security releases but never jumps to a new major version by surprise.

Server
sudo apt install -y postgresql-18

Step 3 — Check that the server is running

The package creates a database cluster called main and starts it straight away. List the clusters:

Server
pg_lsclusters
Output
Ver Cluster Port Status Owner    Data directory              Log file
18  main    5432 online postgres /var/lib/postgresql/18/main /var/log/postgresql/postgresql-18-main.log

Note the paths — every version has its own:

  • Configuration: /etc/postgresql/18/main/postgresql.conf
  • Client access rules: /etc/postgresql/18/main/pg_hba.conf
  • Data: /var/lib/postgresql/18/main

Make sure it starts after a reboot:

Server
sudo systemctl enable --now postgresql

Step 4 — Connect with psql

Installation creates an operating-system user and a database superuser, both called postgres. Open the PostgreSQL shell as that user:

Server
sudo -u postgres psql

Confirm the version, then quit with \q:

psql
SELECT version();
Output
PostgreSQL 18.x (Ubuntu 18.x-1.pgdg24.04+1) on x86_64-pc-linux-gnu, compiled by gcc …

Step 5 — Create a user and a database for your application

Never connect your application as postgres. Create a separate role with a strong password and a database it owns:

Server
sudo -u postgres createuser --pwprompt appuser
sudo -u postgres createdb --owner=appuser appdb

Passwords are stored with SCRAM-SHA-256, the secure default since PostgreSQL 14. PostgreSQL 18 also warns when MD5 passwords are used — they are deprecated and will be removed. Test the new login over a local TCP connection:

Server
psql -h 127.0.0.1 -U appuser -d appdb -c "SELECT current_user, current_database();"

Step 6 — Allow remote connections (only if you need them)

By default PostgreSQL listens only on localhost. If your application runs on the same server, skip this step — it is the safest setup.

To allow one application server (here 203.0.113.10) to connect, edit /etc/postgresql/18/main/postgresql.conf:

postgresql.conf
listen_addresses = 'localhost,10.0.0.5'   # this server's private IP

Then add one rule to the end of /etc/postgresql/18/main/pg_hba.conf. It allows only that database, that user and that address, over an encrypted connection:

pg_hba.conf
hostssl  appdb  appuser  203.0.113.10/32  scram-sha-256

Restart PostgreSQL and open the port only for that address:

Server
sudo systemctl restart postgresql
sudo ufw allow from 203.0.113.10 to any port 5432 proto tcp

Step 7 — Basic tuning

The defaults are deliberately small. For a server that runs mainly PostgreSQL, these are sensible starting points in postgresql.conf (example for 8 GB of RAM):

postgresql.conf
shared_buffers = 2GB            # about 25% of RAM
effective_cache_size = 6GB      # about 75% of RAM
work_mem = 16MB                 # per sort/hash operation, so keep it modest
maintenance_work_mem = 512MB

Restart after changing shared_buffers. Measure with your real queries before tuning further.

PostgreSQL 18 also adds io_method. Leave it at the default (worker) unless you have benchmarked io_uring on your own workload.

Step 8 — Back up your data

Take a compressed logical backup with pg_dump, and test that it restores:

Server
sudo -u postgres pg_dump -Fc appdb > appdb-$(date +%F).dump
sudo -u postgres createdb appdb_restore_test
sudo -u postgres pg_restore -d appdb_restore_test appdb-$(date +%F).dump

Run backups on a schedule and copy them to another server or to object storage — a backup on the same disk is not a backup.

For large databases, PostgreSQL 17 and later can also take incremental physical backups with pg_basebackup --incremental and merge them with pg_combinebackup.

Upgrading to a newer major version later

Debian and Ubuntu packages make major upgrades manageable with pg_upgradecluster. Install the new version, remove the empty cluster it creates, then upgrade your existing cluster (example: from 18 to a newer NEW):

Server
sudo apt install -y postgresql-NEW
sudo pg_dropcluster NEW main --stop
sudo pg_upgradecluster -m upgrade 18 main

Test your application on the new version, then remove the old cluster with sudo pg_dropcluster 18 main. Always take a full backup first.

Conclusion

You now have PostgreSQL 18 running on Ubuntu 24.04 with a dedicated application user, safe remote access rules, basic tuning and tested backups. Next steps: set up monitoring (for example pg_stat_statements), automate backups, and plan an upgrade well before 14 November 2030.

All versions of this guide

Each version is a complete guide written and tested for that release.

VersionStatusSupported untilGuide
PostgreSQL 18Current14 November 2030You're reading this
PostgreSQL 17Supported8 November 2029Open
PostgreSQL 16Supported9 November 2028Open

#PostgreSQL#Ubuntu#Linux#Databases