Posted in

How to Install PostgreSQL on Ubuntu 24.04

How to Install PostgreSQL on Ubuntu 24.04
How to Install PostgreSQL on Ubuntu 24.04

PostgreSQL is a powerful, open-source object-relational database system known for its robustness, feature set, and performance. It’s a popular choice for many web applications and data-intensive projects. This Tutorial will guide you through the process of installing PostgreSQL on your Ubuntu 24.04 server.

First, ensure your system’s package list is up-to-date. This is a crucial step before installing any new software, as it fetches the latest information about available packages:

“`bash
sudo apt update
sudo apt upgrade -y
“`

Next, you can install the PostgreSQL server and client packages. Ubuntu’s default repositories usually contain a stable version of PostgreSQL. The `postgresql-contrib` package adds some extra utilities and functionalities that are often useful.

“`bash
sudo apt install postgresql postgresql-contrib -y
“`

Once the installation is complete, the PostgreSQL service should start automatically. You can verify its status to ensure it’s running correctly:

“`bash
systemctl status postgresql
“`

If the service is active and running, you’re good to go. PostgreSQL creates a default user called `postgres` which has administrative privileges. To interact with the database, you’ll typically switch to this user and access the PostgreSQL prompt.

“`bash
sudo -i -u postgres
psql
“`

From the `psql` prompt, you can create new roles (users) and databases. For example, to create a new user named `myuser` with a password and a database named `mydb` owned by `myuser`:

“`sql
CREATE USER myuser WITH PASSWORD ‘your_strong_password’;
CREATE DATABASE mydb OWNER myuser;
q
“`

To exit the `postgres` user shell, type `exit`.

For security reasons, it’s recommended to configure access and authentication methods in `pg_hba.conf` and `postgresql.conf` files, located in `/etc/postgresql/{version}/main/`. For remote connections, you’ll need to modify the `listen_addresses` in `postgresql.conf` and set appropriate rules in `pg_hba.conf`.

You have successfully installed PostgreSQL on your Ubuntu 24.04 system. You can now start building applications that leverage this powerful database.

Zac Morgan is a DevOps engineer and system administrator with over a decade of hands-on experience managing Linux and Windows infrastructure. Passionate about automation, cloud technologies, and sharing knowledge with the tech community. When not writing tutorials or configuring servers, you can find Zac exploring new tools, contributing to open-source projects, or helping others solve complex technical challenges.

Leave a Reply

Your email address will not be published. Required fields are marked *