How to Install PostgreSQL on Ubuntu 26.04
PostgreSQL is a powerful, open-source object-relational database system with over 30 years of active development, earning a strong reputation for reliability, feature robustness, and performance.
Install PostgreSQL
Update your package list and install PostgreSQL using the following commands:
apt update
apt install postgresql postgresql-contrib
Output:
root@server:~# apt update
apt install postgresql postgresql-contrib
Hit:1 http://archive.ubuntu.com/ubuntu resolute InRelease
Hit:2 http://archive.ubuntu.com/ubuntu resolute-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu resolute-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu resolute-security InRelease
All packages are up to date.
Installing:
postgresql
Installing dependencies:
postgresql-18 postgresql-client-18 postgresql-common libpq5
Summary:
Upgrading: 0, Installing: 10, Removing: 0, Not Upgrading: 0
PostgreSQL Roles and Databases
We'll now switch to the postgres user account. Run:
sudo -i -u postgres
Then access the PostgreSQL prompt using psql:
psql
Output:
postgres@server:~$ psql
psql (18.3 (Ubuntu 18.3-1))
Type "help" for help.
postgres=#
To exit the PostgreSQL prompt, type:
\q
Create a PostgreSQL Role
To create a new PostgreSQL user (role), run:
createuser --interactive
Output:
postgres@ubuntu26:~$ createuser --interactive
Enter name of role to add: adam
Shall the new role be a superuser? (y/n) y
Create a PostgreSQL Database
Create a new database as the postgres user:
createdb database_name
Example:
postgres@ubuntu26:~$ createdb my_db
Open a Postgres Prompt with the New Role
Now, create a Linux system user with the same name as the PostgreSQL role (for easier access):
adduser username
Example:
root@server:~# adduser adam
Adding user `adam' ...
Adding new group `adam' (1001) ...
Adding new user `adam' (1001) with group `adam' ...
Creating home directory `/home/adam' ...
New password:
Retype new password:
passwd: password updated successfully
Switch to the new Linux user:
su username
Example:
su adam
Then connect to the database:
psql -d database_name
Example:
psql -d my_db
Once connected, you can check your connection info using:
\conninfo
Output:
my_db=# \conninfo
You are connected to database "my_db" as user "adam" via socket in "/var/run/postgresql" at port "5432".
That concludes installing and basic setup of PostgreSQL on Ubuntu 26.04!
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS