Connecting to a PostgreSQL Database Server
This article is show you how to connect to a PostgreSQL Database Server via an interactive terminal program called psql and via the pgAdmin application.
Before using psql or pgAdmin, Please download and install PostgreSQL database server first. The PostgreSQL installer has also installed some useful tools for working with the PostgreSQL database server. You can connect to the PostgreSQL database server via the psql interactive program or pgAdmin tool.
Connecting to a PostgreSQL via psql
1. Launch SQL Shell(psql)
2. Enter the database server information
Orderly enter Server name/Server IP address, Database name, Port, Username, and Password. Press Enter to accept the default if you want to connect to a local PostgreSQL server.
3. Test it out
You can try the following SQL statement to test it out: SELECT version();
Connecting to a PostgreSQL database server using pgAdmin
1. Launch the pgAdmin
2. Create a new server
Right-click the Servers and select Create>Server to create a new server.
Enter host name, port, database name, user name and password, then save.
3. Connect to the database
click on the Servers node to expand the server. By default, PostgreSQL has a database named postgres.
Open the query tool by choosing the menu item Tool > Query Tool or click the lightning icon.
Enter the query in the Query Editor, click the Execute button, then you will see the result of the query displaying in the Data Output tab: