Skip to content

Creating a PostgreSQL installation for local testing

Creating a PostgreSQL Installation for Local Testing

Section titled “Creating a PostgreSQL Installation for Local Testing”

This guide explains how to install PostgreSQL locally in a virtual machine for testing and development purposes.

The following steps assume you have a virtual machine running AlmaLinux on your local computer. For instructions on setting up a virtual machine, see the relevant guide.

  1. Start the virtual machine if it is not already running.
  2. Log in as the root user.
yum install postgresql-server postgresql-contrib

At the prompt, type y and press Enter to proceed with the installation.

postgresql-setup initdb

Edit the pg_hba.conf file:

vi /var/lib/pgsql/data/pg_hba.conf

Locate the following lines:

## IPv4 local connections:
host all all 127.0.0.1/32 ident
## IPv6 local connections:
host all all::1/128 ident

Replace ident with md5 so the lines look like this:

## IPv4 local connections:
host all all 127.0.0.1/32 md5
## IPv6 local connections:
host all all::1/128 md5

Save and exit the editor by typing :wq.

systemctl start postgresql
systemctl status postgresql

You should see Active: active (running) in the output.

systemctl enable postgresql
su - postgres
  1. Access the PostgreSQL command-line interface

    Section titled “Access the PostgreSQL command-line interface”
psql

You should see the postgres=# prompt.

Once PostgreSQL is installed, you can configure it, create databases and users, and perform other administrative tasks.