You can use pgadmin or psql to connect to the PostgreSQL database.
I do not prefer to do database administration with pgadmin.
You can simply connect to the database by downloading and installing pgadmin.
Connect With sqlplus
In this article we will examine the options to connect to the database with psql.
First of all, we should connect to the server with ssh and we pass to the postgres user with the following command.
You can also connect to the database using psql from a remote server.
We will see how to do this by making examples in later parts of the article.
1 | su - postgres |
If you run the following command, by default the postgres user will be connected to the postgres database.
1 | psql |
If you did not change anything in the pg_hba.conf file after installing Postgres, it will not ask for a password.
For all configurations that can be done from the pg_hba.conf file, I recommend reading the article named “How To Configure pg_hba.conf File On PostgreSQL”.
This file is crucial for PostgreSQL.
Connection Options
If you want to connect to a specific database with a specific user, you should use the -d and -U parameters as follows.
1 | psql -d test -U testuser |
If you want to connect to a specific database with a specific user, you should use the -d and -U parameters as follows.
1 | psql -d test -U testuser -p 5432 |