
PostgreSQL is a reliable and scalable open-source relational database system that supports complex queries, custom data types, and JSON. It's ideal for managing large datasets in applications like analytics, GIS, and dynamic websites. It has a rich feature set perfected over decades and a strong community that ensures resilience and data integrity. Developers prefer it for its flexibility and compatibility with modern data workflows.
This article explains how to install PostgreSQL on a Ubuntu 25.04 server. You will enable the PostgreSQL database server and secure it for production use on your server.
Before you begin, you need to:
PostgreSQL is available in Ubuntu’s default APT package list, so you can install it easily using the terminal. Follow the steps below to set up PostgreSQL, add the official repository, and ensure that the database starts automatically when your server boots. After completing these steps, your server will be ready to use PostgreSQL for storing and managing data.
Update the APT package index.
Install the postgresql-common package, which includes the common utilities and configurations for managing PostgreSQL.
Run the setup script to add the PostgreSQL APT repository on your server.
When prompted, press the Enter key to set up the repository on your server:
Install the PostgreSQL server package.
Start the PostgreSQL service.
Enable the PostgreSQL systemd service to start at the time of system boot.
Your output should be similar to the one below:
View the status of the PostgreSQL service to confirm it's in active state.
Your output should be similar to the one below:
PostgreSQL uses the default postgres superuser account to handle administrative tasks like managing databases and users. On Ubuntu, it defaults to peer authentication, which permits access only to local system users without requiring a password. Follow the steps below to improve security, allow broader access control, enable password authentication and restrict access to only authorized users.
Check the installed PostgreSQL version.
Your output should be similar to the one below:
Log in to PostgreSQL server as the postgres user.
Set a new strong password for the postgres user.
Replace strong_password with a strong password including random characters.
Create a new user named park_admin and set a strong password for secure authentication.
Replace strong_password with a strong password including random characters.
Exit the PostgreSQL console.
Enable password authentication by modifying the pg_hba.conf file.
Replace 17 with your installed PostgreSQL version if it's different.
Restart the PostgreSQL service to apply the changes made to the configuration.
View the service status to confirm PostgreSQL service is in active state.
Your output should be similar to the one below:
You can access the PostgreSQL database console through the pre-installed psql utility, which comes with the server package. Alternatively, you can use graphical tools that establish a direct connection to the server. Follow the steps below to access the PostgreSQL database console and create a new sample database for use with a non-privileged user.
Create a new sample PostgreSQL database amusement_park and grant the ownership to the park_admin user.
When prompted, enter the postgres user password you created earlier.
Log in to the PostgreSQL database as the park_admin user.
When prompted, Enter the park_admin user password and press Enter to access the database.
Create a new table visitors in the amusement_park database.
The above SQL statement creates a new table in the amusement_park database with the following columns:
visitor_id is a PRIMARY KEY that uniquely identifies each visitor.SERIAL generates a new visitor_id for each new record.first_name and last_name store the visitor’s name.entry_date stores the date the visitor entered the amusement park.Insert sample data into the visitors table.
Query the visitors table to view all available records.
Your output should be similar to the one below:
Exit the PostgreSQL console.
You have installed PostgreSQL on your Ubuntu 25.04 server and used the psql utility to create databases and manage records. You can now integrate PostgreSQL with your applications to securely manage data. For additional information and configuration options, refer to the official PostgreSQL documentation.
0 Comments
Be the first to comment and share your perspective with the community.