HOW IT WORKS – Install and Configure PostgreSQL 15 on Ubuntu

Overview

This guide walks through installing PostgreSQL 15 on Ubuntu, verifying that the database service is running on port 5432, setting a password for the PostgreSQL superuser, and registering the server in pgAdmin 4. It finishes by creating a database through the pgAdmin interface.

What you will complete

  • Add the official PostgreSQL Apt Repository signing key and package source.
  • Install PostgreSQL 15 server and client packages.
  • Check the PostgreSQL service and listening port.
  • Set a password for the postgres database superuser.
  • Register the local server in pgAdmin 4.
  • Create a database from pgAdmin.

Before you begin

  • Ubuntu 24.04 LTS or Ubuntu 22.04 LTS is installed and you can open a terminal.
  • Your user account has sudo privileges.
  • An internet connection is available for package downloads.
  • pgAdmin 4 is installed if you want to follow the graphical connection steps. It is a separate application from PostgreSQL.

Note: The commands below target PostgreSQL 15 explicitly. Package availability depends on Ubuntu release and repository support. Use the official PostgreSQL repository instructions for your specific release if the repository configuration differs.


Add the Official PostgreSQL Repository

Ubuntu’s default repositories may provide a different PostgreSQL major version. The PostgreSQL Apt Repository (PGDG) allows you to request PostgreSQL 15 explicitly.

Create the keyring directory and import the signing key

 sudo mkdir -p /etc/apt/keyrings
 curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/keyrings/postgresql.gpg

The signing key allows APT to verify packages from the repository. If the key file already exists, review the error before overwriting it.

Add the repository source

 echo "deb [signed-by=/etc/apt/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list

The command uses the Ubuntu codename detected by lsb_release -cs and adds the PGDG repository for that release.

Refresh the package index

 sudo apt-get update

Check the output for repository or signature errors before continuing.


Install PostgreSQL 15

Install the PostgreSQL 15 server and client packages:

 sudo apt-get install -y postgresql-15 postgresql-client-15

The server package provides the database service. The client package provides tools such as psql for connecting to PostgreSQL.


Verify the Service and Port

Check the PostgreSQL service status:

 sudo systemctl status postgresql

If the service is not active, start it and enable it to start automatically at boot:

 sudo systemctl start postgresql
 sudo systemctl enable postgresql

Check whether a process is listening on the default PostgreSQL port, 5432:

 ss -nlt | grep 5432

A listener on 127.0.0.1:5432, [::1]:5432, or another configured address indicates that a process is listening on that port. If the command returns no result, inspect PostgreSQL status and configuration. The port can be configured differently, so verify rather than assuming.

Security note: For a local development setup, listening only on localhost is often appropriate. Do not expose PostgreSQL to a network unless remote access is required and access controls, authentication, and firewall rules have been configured.


Set a Password for the postgres Database User

Ubuntu commonly configures local PostgreSQL administration to use peer authentication. This means the operating-system account is checked when connecting locally, rather than requiring a database password. To use password authentication from pgAdmin, set a password for the PostgreSQL database role.

Open the PostgreSQL prompt

 sudo -u postgres psql

Set the password

At the psql prompt, run the following SQL command, replacing the example value with a strong, unique password:

 ALTER USER postgres WITH PASSWORD 'your_secure_password';

Then exit psql:

 \q

Important: Do not use the literal placeholder password. Avoid reusing passwords from tutorials, and do not include real passwords in screenshots, documentation, or recorded videos.

Setting a password does not automatically change PostgreSQL’s authentication rules for every connection. If pgAdmin cannot connect, review the active pg_hba.conf rules and server logs before changing authentication settings.


Connect to PostgreSQL Using pgAdmin 4

Open pgAdmin 4 using the desktop application, or use its browser interface if it has been installed and configured for web access. A common local URL is http://localhost/pgadmin4, but the exact URL depends on the installation method.

  1. In the browser tree, right-click Servers and select Register > Server.
  2. On the General tab, enter a recognizable name, such as Ubuntu PostgreSQL 15.
  3. Open the Connection tab and enter the connection details shown below.
  4. Enter the password set for the postgres database role.
  5. Optionally select Save password if this is an appropriate trusted local environment.
  6. Click Save and expand the registered server to confirm that the connection succeeds.

Connection settings

FieldValue
NameUbuntu PostgreSQL 15
Host name/addresslocalhost
Port5432
Maintenance databasepostgres
Usernamepostgres
PasswordThe password set in Section 5

Create a Database in pgAdmin

  1. Expand the registered server and locate Databases.
  2. Right-click Databases and choose Create > Database.
  3. Enter a database name appropriate for your project or test environment.
  4. Choose the owner if required. For a new local workspace, select the appropriate role for your intended use.
  5. Click Save and confirm that the new database appears under Databases.

This creates a clean database workspace. It does not automatically import iDempiere’s schema or seed data; those steps are performed separately when setting up the iDempiere application.


Verification Checklist

  • The PGDG repository was added and apt-get update completed without repository errors.
  • PostgreSQL 15 server and client packages are installed.
  • The PostgreSQL service is active.
  • A process is listening on the expected port, usually 5432.
  • The postgres database role has a strong password configured.
  • pgAdmin 4 can connect to the local PostgreSQL server.
  • A test database can be created and is visible in pgAdmin.

Common Issues to Check

IssueChecks
APT repository or key errorVerify the official PGDG repository instructions, key URL, Ubuntu codename, and file permissions.
PostgreSQL service is inactiveCheck sudo systemctl status postgresql and the PostgreSQL logs; then start the service if appropriate.
Port 5432 is not listeningConfirm the cluster is running and review its configured port and listen_addresses setting.
pgAdmin password authentication failsVerify the username and password, then review pg_hba.conf authentication rules and server logs.
Connection refusedConfirm the service is running, the host and port are correct, and PostgreSQL is listening on the requested interface.
pgAdmin URL does not openConfirm pgAdmin 4 is installed and determine the URL for that installation method; the web URL is not universal.

Completion

PostgreSQL 15 is ready for local development when the service is running, the expected port is available, and pgAdmin 4 can connect to the server and create a database. Keep database access local unless remote connectivity is specifically needed. For production, configure least-privilege roles, backups, secure authentication, network restrictions, and credential management.