How to create a PostgreSQL installation for local testing

This article describes how to create a PostgreSQL installation that you can use for local testing.

The following procedures assume that you have already created a virtual machine running CentOS 7 on your local computer. For information about how to do this, please see this article.

Table of Contents

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

    postgresql-setup initdb
  6. To enable password authentication, type the following command:

    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:

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

    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:

    systemctl enable postgresql
  13. To confirm that the postgres user is active, type the following command:

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

    psql

    You should see the postgres=# prompt.

    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.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.