PostgreSQL is a powerful, open-source object-relational database system known for its reliability, robustness, and performance. Whether you’re working on a production-grade application or exploring data for a side project, PostgreSQL is an excellent choice. In this blog we will learn how to Install and Configure PostgreSQL with pgAdmin 4 on Ubuntu
To make database management easier, pgAdmin 4 provides a user-friendly web interface that allows you to interact with your PostgreSQL databases visually.
Update System Packages
Before we begin, it’s essential to update the package list and upgrade all existing packages. This ensures that you’re using the latest versions and reduces the risk of compatibility issues.
sudo apt update && sudo apt upgrade -y
Install PostgreSQL
Next, install PostgreSQL along with postgresql-contrib, which provides additional utilities and extensions.
sudo apt install postgresql postgresql-contrib -y
After installation, PostgreSQL starts automatically and runs as a service. You can verify that it’s installed correctly by checking its version:
psql –version
Start and Enable the PostgreSQL Service
To ensure PostgreSQL starts on boot and is currently running:
sudo systemctl start postgresql
sudo systemctl enable postgresql
To check the status of the service:
sudo systemctl status postgresql
Switch to the Default PostgreSQL User
PostgreSQL creates a system user called postgres. You must switch to this user to perform administrative tasks like creating roles and databases:
sudo -i -u postgres
Now you’re operating under the PostgreSQL user context.
Access the PostgreSQL Shell
To enter the interactive PostgreSQL shell (psql), run:
psql
Here, you can execute SQL queries and administrative commands.
Create a New User and Database
We’ll now create a new PostgreSQL role (user) and a database, then assign appropriate privileges.
In the psql shell, run:
— Create a new user with a secure password
CREATE ROLE pguser WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD 'password';
— Check that the user was created
\du
— Create a new database
CREATE DATABASE pgdb;
— Grant all privileges on the database to the new user
GRANT ALL PRIVILEGES ON DATABASE pgdb TO pguser;
Replace pguser and pgdb with your preferred username and database name.
Replace ‘password’ with a strong password of your choice.
Once done, exit the PostgreSQL shell:
\q
And switch back to your regular system user:
exit
Install pgAdmin 4 (Web Interface)
pgAdmin is a powerful, browser-based PostgreSQL database management tool. Let’s install it step-by-step.
Install Required Tools
You’ll need curl to download external resources:
sudo apt update && sudo apt install curl -y
Add pgAdmin’s GPG Key
Import the repository key to verify package authenticity:
curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg
Add the pgAdmin Repository
Add pgAdmin’s official APT repository to your sources list:
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
This command:
Adds the official pgAdmin APT source
Refreshes the package list
Install pgAdmin 4
Finally, install pgAdmin 4 using:
sudo apt install pgadmin4 -y
Configure pgAdmin 4 Web Mode
After installation, configure pgAdmin to run in web mode. This will prompt you to create an admin login for the web UI:
sudo /usr/pgadmin4/bin/setup-web.sh
During this process, you’ll be asked:
To enter an email address — this will be your login
To choose a password — make it strong and secure
Once configured, the pgAdmin web server will start.
Access pgAdmin in Your Web Browser
You can now access pgAdmin via your browser using your server’s IP address:
http://<your-server-ip>/pgadmin4
You’ll be greeted with a login screen. Use the credentials you provided during the web setup (email and password).
After logging in, you can:
Add a new server
Connect using your pguser and pgdb
Run SQL queries, manage tables, users, and backups — all through the graphical interface!
Setting up PostgreSQL with pgAdmin 4 on Ubuntu gives you a powerful and user-friendly environment for managing databases. With PostgreSQL as your robust backend and pgAdmin 4 providing a graphical interface, you’re now ready to Install and Configure PostgreSQL with pgAdmin 4 and build, manage, and scale your applications with ease.
If you encounter any issues or need expert assistance while you Install and Configure PostgreSQL with pgAdmin 4 on Ubuntu, our team is here to help. We offer reliable server management services to ensure your database setup is secure, optimized, and scalable.