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.
Important
Section titled “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
Section titled “Installing PostgreSQL”- Start the virtual machine if it is not already running.
- Log in as the root user.
-
Install PostgreSQL
Section titled “Install PostgreSQL”
yum install postgresql-server postgresql-contribAt the prompt, type y and press Enter to proceed with the installation.
-
Initialize the PostgreSQL database
Section titled “Initialize the PostgreSQL database”
postgresql-setup initdb-
Enable password authentication
Section titled “Enable password authentication”
Edit the pg_hba.conf file:
vi /var/lib/pgsql/data/pg_hba.confLocate the following lines:
## IPv4 local connections:host all all 127.0.0.1/32 ident## IPv6 local connections:host all all::1/128 identReplace 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 md5Save and exit the editor by typing :wq.
-
Start PostgreSQL
Section titled “Start PostgreSQL”
systemctl start postgresql-
Verify that PostgreSQL is running
Section titled “Verify that PostgreSQL is running”
systemctl status postgresqlYou should see Active: active (running) in the output.
-
Enable PostgreSQL to start on system boot
Section titled “Enable PostgreSQL to start on system boot”
systemctl enable postgresql-
Switch to the postgres user
Section titled “Switch to the postgres user”
su - postgres-
Access the PostgreSQL command-line interface
Section titled “Access the PostgreSQL command-line interface”
psqlYou should see the postgres=# prompt.
Next Steps
Section titled “Next Steps”Once PostgreSQL is installed, you can configure it, create databases and users, and perform other administrative tasks.