# Creating a PostgreSQL installation for local testing

> Install and configure PostgreSQL in a local AlmaLinux virtual machine for testing and development.

Source: https://helpcenter.ruachost.com/developers/web-development/creating-a-postgresql-installation-for-local-testing/

> **PostgreSQL is available on Managed VPS only:**
Ruachost shared hosting supports MySQL (MariaDB) databases, not PostgreSQL. To use PostgreSQL, choose a [Managed VPS](https://ruachost.com/vps).

## 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

1. **Start the virtual machine** if it is not already running.
2. **Log in as the root user**.
3. #### Install PostgreSQL

```
yum install postgresql-server postgresql-contrib
```

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

4. #### Initialize the PostgreSQL database

```
postgresql-setup initdb
```

5. #### 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`.

6. #### Start PostgreSQL

```
systemctl start postgresql
```

7. #### Verify that PostgreSQL is running

```
systemctl status postgresql
```

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

8. #### Enable PostgreSQL to start on system boot

```
systemctl enable postgresql
```

9. #### Switch to the postgres user

```
su - postgres
```

10. #### 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.
