> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

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

<Warning>
  **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](/docs/configuring-a-virtual-machine-for-local-testing).
</Warning>

## Installing PostgreSQL

To install PostgreSQL on your virtual machine, follow these steps:

1. Start the virtual machine, if you haven't already.

2. Log in to the virtual machine as the root user.

3. At the command prompt, type the following command to install PostgreSQL:

   ```bash theme={null}
   yum install postgresql-server postgresql-contrib
   ```

4. At the **Is this ok** prompt, type `y` and then press Enter. The installation process begins.

5. After installation completes, type the following command to initialize PostgreSQL:

   ```bash theme={null}
   postgresql-setup initdb
   ```

6. To enable password authentication, type the following command:

   ```bash theme={null}
   vi /var/lib/pgsql/data/pg_hba.conf
   ```

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

8. 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
   ```

9. Type **:wq** to save your changes and exit the editor.

10. Type the following command to start PostgreSQL:

    ```bash theme={null}
    systemctl start postgresql
    ```

11. To confirm PostgreSQL is running, type the following command:

    ```bash theme={null}
    systemctl status postgresql
    ```

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

12. To make PostgreSQL start automatically on system boot, type the following command:

    ```bash theme={null}
    systemctl enable postgresql
    ```

13. To confirm that the **postgres** user is active, type the following command:

    ```bash theme={null}
    su - postgres
    ```

14. As the postgres user, type the following command:

    ```bash theme={null}
    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

* [Connecting to PostgreSQL using psql](/docs/connect-to-postgresql-from-the-command-line)

* [Managing PostgreSQL databases and users from the command line](/docs/managing-postgresql-databases-and-users-from-the-command-line)

* [Importing and exporting a PostgreSQL database](/docs/import-and-export-a-postgresql-database)

* [Determining the size of PostgreSQL databases and tables](/docs/determining-the-size-of-postgresql-databases-and-tables)

* [Configuring a virtual machine for local testing](/docs/configuring-a-virtual-machine-for-local-testing)
