Menu
User

DropVPS Team

Writer: Cooper Reagan

how to install postgresql on ubuntu 25.10

how to install postgresql on ubuntu 25.10

Publication Date

09/29/2025

Category

Articles

Reading Time

5 Min

Table of Contents

In this step-by-step guide, you’ll learn how to install PostgreSQL on Ubuntu 25.10. We’ll install the latest version from either the official Ubuntu repository or the PGDG repository, start and secure the service, configure remote access and the firewall, create users and databases, handle backups, and perform major version upgrades. Ideal for admins and DevOps engineers.

Update system and prerequisites

Refresh package indexes and install utilities used to add repositories, manage keys, and firewall.

sudo apt update
sudo apt -y upgrade
sudo apt -y install curl ca-certificates gnupg lsb-release ufw

Install PostgreSQL from Ubuntu repository

Install the default PostgreSQL shipped with Ubuntu 25.10. Good stability and quick setup.

sudo apt -y install postgresql postgresql-contrib
psql --version
sudo -u postgres psql -c "SELECT version();"
version
-------------------------------------------------------------------------------------------------
 PostgreSQL 17.x (Ubuntu 17.x-0ubuntu...) on x86_64-pc-linux-gnu, compiled by gcc ..., 64-bit
(1 row)

Optional: Install latest PostgreSQL from PGDG

Use the official PostgreSQL (PGDG) APT repository to get newer major versions. The codename is detected automatically; if 25.10 is not yet available, fall back to noble.

# Import PGDG signing key
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/pgdg.gpg

# Add PGDG repo using your Ubuntu codename
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list

# If the above fails due to unsupported codename, use noble as a safe fallback
# echo "deb http://apt.postgresql.org/pub/repos/apt noble-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list

sudo apt update
# Install a specific major version, e.g., 17
sudo apt -y install postgresql-17 postgresql-client-17

Check and manage the PostgreSQL service

The service usually starts after install. Verify status, enable at boot, and view logs.

sudo systemctl status postgresql
sudo systemctl enable postgresql
sudo journalctl -u postgresql -e --no-pager
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
     Active: active (exited) ...
     Tasks: 0 (limit: ...)
     ...

Set the postgres superuser password

Use the postgres Linux account to access psql and secure the default superuser with a strong password.

sudo -u postgres psql
\password postgres
\q

Create an application role and database

Create a least-privilege role and a dedicated database. Avoid using superuser in apps.

sudo -u postgres createuser --pwprompt --login --no-superuser --no-createdb --no-createrole appuser
sudo -u postgres createdb --owner=appuser appdb

# Test login locally
psql -U appuser -d appdb -h 127.0.0.1 -W -c "SELECT current_user, current_database();"

Configure listen address and authentication

Enable network listening and strong auth. Replace X.Y.Z.0/24 with your trusted subnet.

# Find your installed major version (e.g., 17)
ls /etc/postgresql

# Edit postgresql.conf
sudo nano /etc/postgresql/17/main/postgresql.conf
# Set:
# listen_addresses = '*'
# port = 5432

# Edit pg_hba.conf for authentication rules
sudo nano /etc/postgresql/17/main/pg_hba.conf
# Ensure local connections use scram-sha-256 (or md5 if needed):
# local   all             all                                     peer
# host    all             all             127.0.0.1/32            scram-sha-256
# host    all             all             ::1/128                 scram-sha-256
# Restrict remote access to your subnet:
# host    all             all             X.Y.Z.0/24              scram-sha-256

# Apply changes
sudo systemctl reload postgresql

Open the firewall (UFW) for PostgreSQL

Allow inbound TCP 5432 from trusted sources only. Replace the CIDR as needed.

# Allow only your subnet
sudo ufw allow from X.Y.Z.0/24 to any port 5432 proto tcp

# Or, if testing on a private network (not recommended on the internet):
# sudo ufw allow 5432/tcp

sudo ufw status

Verify remote connectivity

Connect from a client machine using the URL format. Confirm SSL and authentication as configured.

psql "postgresql://appuser@SERVER_IP:5432/appdb" -W -c "SELECT version();"

Backup and restore essentials

Use pg_dump for per-database backups and pg_dumpall for roles and globals. Store backups off-server.

# Logical backup
pg_dump -U appuser -h 127.0.0.1 -F c -f appdb_$(date +%F).dump appdb

# Restore to a new database
createdb -U postgres appdb_restore
pg_restore -U postgres -d appdb_restore appdb_YYYY-MM-DD.dump

# Backup roles and globals
pg_dumpall -U postgres --globals-only > globals.sql

Minor updates and major upgrades

Apply minor updates via APT. For major version upgrades with Debian-style packages, use pg_upgradecluster to migrate the cluster safely.

# Minor updates
sudo apt update
sudo apt -y upgrade

# Example major upgrade from 17 to 18 (when available via PGDG/Ubuntu)
sudo apt -y install postgresql-18
sudo pg_lsclusters
sudo systemctl stop postgresql
sudo pg_upgradecluster 17 main
sudo pg_lsclusters
# If all good, remove old cluster
sudo pg_dropcluster 17 main --stop

Uninstall or clean up (optional)

Remove packages or purge clusters. Be careful: purge removes data directories.

# Stop PostgreSQL
sudo systemctl stop postgresql

# Remove server binaries but keep data
sudo apt -y remove postgresql postgresql-*

# Purge everything including configs/data (destructive)
# sudo apt -y purge postgresql\* postgresql-common
# sudo rm -rf /var/lib/postgresql/ /etc/postgresql/

PostgreSQL can be easily installed on Ubuntu 25.10 using APT. By setting up secure authentication, configuring the firewall, and enabling backups, you’ll have a production-ready database. For more tutorials, guidance, and to buy various servers with support, visit dropvps.

Linux VPS
U
Loading...

Related Posts

how to install postgresql on ubuntu 25.10