# Verifying the Connection to the PostgreSQL Database Server

Before creating a PostgreSQL instance, verify that you can connect to the PostgreSQL database server.

### Before You Begin

Ensure the following prerequisites are met before verifying the connection:

- PostgreSQL is installed on the computer where you plan to test the connection.

- You have access to a valid user account with permissions to run the `psql` binary.

- The PostgreSQL service is running.

- You know the following connection details:

  - Database name
  - Database user
  - Port number
  - (Optional) Hostname or IP address if connecting remotely

## Procedure

1. Log on using a user account that has permissions to run the `psql` binary.

2. Navigate to the `bin` folder in the PostgreSQL installation directory.

3. Run one of the following commands to establish a connection to the PostgreSQL server:

   - On a Unix computer:

         ./psql -p port -U $[database_user] -d $[database_name]

   - On a Windows computer:

         psql.exe -p port -U $[database_user] -d $[database_name]

   Where:

   - `database_user` — The user account with permissions to perform backups and restores.
   - `database_name` — The name of the database available on the server.

   For example:

   The following example verifies the connection to the `demopgsql` database:

       [root@mpgstandby bin]# cd /usr/pgsql-13/bin
       [root@mpgstandby bin]# ./psql -p 5432 -U postgres -d demopgsql
       psql (13.0)
       Type "help" for help.
       demopgsql=# \q
       [root@mpgstandby bin]#

4. If you use a hostname to connect to the PostgreSQL server, specify the port in the `hostname:port` format within the instance properties.

   To verify the connection:

   - On a Unix computer:

         ./psql -p port -U $[database_user] -d $[database_name] -h $[hostname]

   - On a Windows computer:

         psql.exe -p port -U $[database_user] -d $[database_name] -h $[hostname]

   Where:

   - `database_user` — The user account with permissions to perform backups and restores.
   - `database_name` — The name of the database available on the server.
   - `hostname` — The IP address or fully qualified domain name (FQDN) of the computer that hosts the database server.

   For example:

   The following example verifies the connection to the `demopgsql` database using a hostname:

       [root@mpgstandby bin]# cd /usr/pgsql-13/bin
       [root@mpgstandby bin]# ./psql -p 5432 -U postgres -d demopgsql -h mpgstandby
       psql (13.0)
       Type "help" for help.
       demopgsql=# \q
       [root@mpgstandby bin]#

×

Loading...