Creating a PostgreSQL installation for local testing
In this article, learn how to install PostgreSQL locally in a virtual machine for your own website testing and development.
This article describes how to create a PostgreSQL installation that you can use for local testing.
Important
The following procedures assume that you have already created a virtual machine running AlmaLinux on your local computer. For information about how to do this, please see this article.
Installing PostgreSQL
To install PostgreSQL on your virtual machine, follow these steps:
-
Start the virtual machine, if you haven't already.
-
Log in to the virtual machine as the root user.
-
At the command prompt, type the following command to install PostgreSQL:
yum install postgresql-server postgresql-contrib
-
At the Is this ok prompt, type
y
and then press Enter. The installation process begins. -
After installation completes, type the following command to initialize PostgreSQL:
postgresql-setup initdb
-
To enable password authentication, type the following command:
vi /var/lib/pgsql/data/pg_hba.conf
-
In the pg_hba.conf file, 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 as follows:
## IPv4 local connections: host all all 127.0.0.1/32 md5 ## IPv6 local connections: host all all::1/128 md5
-
Type :wq to save your changes and exit the editor.
-
Type the following command to start PostgreSQL:
systemctl start postgresql
-
To confirm PostgreSQL is running, type the following command:
systemctl status postgresql
You should see Active: active (running) in the output.
-
To make PostgreSQL start automatically on system boot, type the following command:
systemctl enable postgresql
-
To confirm that the postgres user is active, type the following command:
su - postgres
-
As the postgres user, type the following command:
psql
You should see the postgres=# prompt.
Tip
Now that you have installed PostgreSQL, you are ready to configure it. For information about how to set up PostgreSQL databases, users, and more, please see the Related Articles section below.
Related Articles
Updated 3 days ago