Creating a PostgreSQL Installation for Local Testing
This guide explains how to install PostgreSQL locally in a virtual machine for testing and development purposes.
Important
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.
Installing PostgreSQL
-
Start the virtual machine if it is not already running.
-
Log in as the root user.
-
Install PostgreSQL:
yum install postgresql-server postgresql-contrib
At the prompt, type y and press Enter to proceed with the installation.
-
Initialize the PostgreSQL database:
postgresql-setup initdb
-
Enable password authentication:
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.
-
Start PostgreSQL:
systemctl start postgresql
-
Verify that PostgreSQL is running:
systemctl status postgresql
You should see Active: active (running) in the output.
-
Enable PostgreSQL to start on system boot:
systemctl enable postgresql
-
Switch to the postgres user:
su - postgres
-
Access the PostgreSQL command-line interface:
psql
You should see the postgres=# prompt.
Next Steps
Once PostgreSQL is installed, you can configure it, create databases and users, and perform other administrative tasks.