
PostgreSQL is an open-source relational database management system known for its extensibility, standards compliance, and support for advanced features such as complex queries, JSON data types, and full-text search. It handles workloads ranging from single-server applications to large-scale data warehouses, making it a preferred choice for analytics platforms, geographic information systems, and dynamic web applications.
This article explains how to install PostgreSQL on an Ubuntu 26.04 server. It covers adding the official PostgreSQL APT repository, enabling the database service, configuring password-based authentication, and creating a sample database with test records.
Before you begin, you need to:
The postgresql-common package provides shared utilities and a setup script that adds the official PostgreSQL APT repository to your system. After adding the repository, install the server package and configure the service to start automatically on boot.
Update the APT package index.
Install the postgresql-common package, which contains shared utilities and the repository setup script.
Run the setup script to add the official PostgreSQL APT repository.
The script displays the repository details. Press Enter to confirm and proceed:
Install the PostgreSQL server package.
Start the PostgreSQL service.
Enable PostgreSQL to start automatically at boot time.
Verify that the PostgreSQL service is active.
Your output should be similar to the one below:
PostgreSQL ships with a default superuser account named postgres that manages all administrative operations. Ubuntu configures peer authentication by default, which allows local system users to connect without a password. The following steps switch to password-based authentication using scram-sha-256, set a password for the postgres account, and create a dedicated database user.
Check the installed PostgreSQL version.
Your output should be similar to the one below:
Log in to the PostgreSQL console as the postgres superuser.
Set a strong password for the postgres account. Replace strong_password with a secure password.
Create a new database user named example_admin with an encrypted password. Replace strong_password with a secure password.
Exit the PostgreSQL console.
Switch from peer authentication to scram-sha-256 password authentication by updating the pg_hba.conf file. Replace 17 with your installed PostgreSQL major version if it differs.
Restart PostgreSQL to apply the authentication changes.
Verify that the PostgreSQL service is active after the restart.
Your output should be similar to the one below:
The psql command-line utility ships with the PostgreSQL server package and provides direct access to the database console. The following steps create a sample database owned by the example_admin user, build a table, and populate it with test records.
Create a new database named example_store and assign ownership to the example_admin user.
Enter the postgres user password when prompted.
Log in to the example_store database as the example_admin user.
Enter the example_admin password and press Enter to access the database.
Create a new table named products to store sample records.
The SQL statement creates a table with the following columns:
product_id is a PRIMARY KEY that uniquely identifies each record.SERIAL auto-generates a new product_id for each inserted row.product_name and category store text values describing the product.price stores the product price as a numeric value with two decimal places.Insert sample records into the products table.
Query the products table to verify the inserted data.
Your output should be similar to the one below:
Exit the PostgreSQL console.
You have installed PostgreSQL on an Ubuntu 26.04 server, enabled password-based authentication, and created a dedicated user with a sample database. PostgreSQL integrates with a wide range of application frameworks and supports replication for high-availability deployments. For more information, refer to the official PostgreSQL documentation.
0 Comments
Be the first to comment and share your perspective with the community.