
PostgreSQL is one of the most powerful, stable, and feature-rich open-source database systems available today. It’s widely used by startups, agencies, and enterprise-level companies for building reliable and scalable applications. If your server or application stack runs on Ubuntu, installing PostgreSQL is straightforward — especially with the latest Ubuntu 24.04 release.
In this guide, we’ll walk you through how to install PostgreSQL on Ubuntu 24.04, how to configure it, create users, manage roles, and connect to your database securely. Whether you're hosting databases for WordPress, Laravel apps, or custom software — this tutorial will help you get PostgreSQL up and running quickly.
Before diving into the installation steps, here are a few reasons why PostgreSQL is a favorite among developers:
If reliability and scalability are important to your project, PostgreSQL is an excellent choice.
Before starting, ensure you have:
If you're using a cloud server or VPS, you can connect using:
ssh username@your_server_ip
It’s always a good idea to update your system packages before installing any new software:
sudo apt update && sudo apt upgrade -y
This ensures that your PostgreSQL installation uses the latest stable dependencies.
Ubuntu 24.04 comes with PostgreSQL available directly in its default repositories, which makes installation simple:
sudo apt install postgresql postgresql-contrib -y
postgresql installs the core PostgreSQL database server.postgresql-contrib installs useful additional tools and extensions.Once installed, PostgreSQL should automatically start. You can verify this by running:
sudo systemctl status postgresql
You should see output showing that PostgreSQL is active (running).
If, for any reason, it’s not running, start it manually:
sudo systemctl start postgresql
PostgreSQL creates a user and group called postgres automatically. This is the default database superuser.
Switch to the postgres user:
sudo -i -u postgres
Now open the PostgreSQL command prompt:
psql
You should see a prompt like:
postgres=#
This means you’re inside the PostgreSQL shell.
To exit:
\q
And return to your normal user:
exit
For security reasons, it’s recommended not to use the default postgres user for application access. Let’s create our own database and user.
Switch to the PostgreSQL user:
sudo -i -u postgres
Open the PostgreSQL shell:
psql
Create a new user (replace myuser with your username):
CREATE USER myuser WITH PASSWORD 'mypassword';
Now create a new database (replace mydb with your database name):
CREATE DATABASE mydb OWNER myuser;
Give your user necessary privileges:
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
Exit the PostgreSQL shell:
\q
Exit back to normal user:
exit
If your application is on another server or you need remote access:
Open PostgreSQL configuration file:
sudo nano /etc/postgresql/*/main/postgresql.conf
Find this line and change:
#listen_addresses = 'localhost'
To:
listen_addresses = '*'
Now edit the authentication file:
sudo nano /etc/postgresql/*/main/pg_hba.conf
Add this line at the bottom (replace 0.0.0.0/0 with your allowed IP, if needed):
host all all 0.0.0.0/0 md5
Restart PostgreSQL:
sudo systemctl restart postgresql
To connect to your new database:
psql -U myuser -d mydb
If connecting remotely:
psql -h your_server_ip -U myuser -d mydb
sudo systemctl enable postgresql
This ensures PostgreSQL starts automatically when the server restarts.
sudo apt update && sudo apt upgrade
You’ve successfully installed and configured PostgreSQL on Ubuntu 24.04!
Whether you're building a new application or migrating from a different database system, PostgreSQL provides the stability, speed, and flexibility needed for modern data-driven applications.
If you're hosting your applications on Hostomy, our optimized VPS Hosting Service are fully compatible with PostgreSQL — giving you faster database performance, low latency, and 24/7 support.