Home → Articles → How to Install PostgreSQL Database Server on Ubuntu 26.04

How to Install PostgreSQL Database Server on Ubuntu 26.04

02 Apr, 2026

Introduction

PostgreSQL is a free, open-source relational database management system that offers advanced features and supports many modern programming languages like Python, Java, C++, PHP, Golang, and Node.js. The database server handles flexible data types and supports different operating systems. These features make PostgreSQL a powerful and versatile choice for developers and businesses.

This guide shows you how to install PostgreSQL on Ubuntu 26.04.

Prerequisites

Before you start:

Install PostgreSQL

The PostgreSQL package is available by default on the Ubuntu repositories. To install the package, follow these steps.

Manage PostgreSQL Service

PostgreSQL runs as a system service on Ubuntu under the name postgresql. You can manage this service by using specific commands to start, stop, restart, and check the PostgreSQL status. These commands ensure your PostgreSQL installation runs smoothly and make maintenance easier on your system.

Check PostgreSQL Status

console
$ sudo systemctl status postgresql

Output:

● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled)
     Active: active (exited) since Tue 2026-03-10 10:15:23 UTC; 5min 12s ago
    Process: 1143 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 1143 (code=exited, status=0/SUCCESS)
        CPU: 2ms

Press Ctrl + C.

Start PostgreSQL Service

console
$ sudo systemctl start postgresql

Stop PostgreSQL Service

console
$ sudo systemctl stop postgresql

Restart PostgreSQL Service

console
$ sudo systemctl restart postgresql

Enable PostgreSQL to Start on Boot

console
$ sudo systemctl enable postgresql

Output:

Synchronizing state of postgresql.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable postgresql

Secure PostgreSQL Database Server

By default, you can log in to your PostgreSQL server using the postgres user account without a password on your localhost. To secure the postgres user account with a password, follow the steps below.

Configure PostgreSQL to Accept Remote Connections (Optional)

By default, PostgreSQL listens only on localhost. To allow remote clients to connect, you need to modify the PostgreSQL configuration file and open the firewall port.

Configure Firewall for PostgreSQL

If UFW (Uncomplicated Firewall) is active on your Ubuntu server, you need to allow traffic on port 5432, which is the default port PostgreSQL uses.

Test the PostgreSQL Database Server

In this section, you'll test your PostgreSQL installation by logging into the database server, creating a sample database and table, inserting some data, and querying the table to ensure everything functions correctly. This process helps verify that your installation works as expected and that you can seamlessly perform basic database operations.

Your PostgreSQL database server is working as expected.

Conclusion

In this guide, you have installed PostgreSQL on Ubuntu 26.04 using apt, secured the database server with a password, configured remote access, opened the firewall port, and created a sample database with tables and records. Now that you have PostgreSQL running, consider integrating the database with a programming language like Python using psycopg2 or with Node.js using the pg package to build data-driven applications.