How to connect PostgreSQL database after installation on Windows
We now have PostgreSQL database installed on our system by following the step given on Install PostgreSQL guide
In this tutorial, we will explore two methods, among various others, for establishing a connection to a PostgreSQL database. These two methods come along with the PostgreSQL installation.
- SQL shell (psql)
- PgAdmin4
Connecting PostgreSQL with SQL shell (psql)
PostgreSQL command-line utility commonly known as psql
. psql
is a powerful and interactive command-line tool that allows you to work with PostgreSQL databases using SQL queries and perform various administrative tasks
Let’s now see how to open psql on windows
Search for sql shell or psql on windows
Proceed with the [localhost]. Press Enter
For Database, Proceed with [postgres]. Press Enter
For Port, Proceed with [5432]. Press Enter
For Username, Proceed with [postgres]. Press Enter
Enter the Password for user postgres which we had set at the time of installation
After inputting the password, we can observe that we have obtained the PostgreSQL version and the prompt postgres=# indicating a successful connection to the database.
How to check Postgres version using sql command line
Command to check the Postgres version
SELECT version();
Connecting PostgreSQL with pgAdmin
pgAdmin is an open-source graphical administration and management tool designed for PostgreSQL, a powerful relational database system. It provides a user-friendly interface for creating, managing, and querying databases, making it easier for users to interact with PostgreSQL databases without needing extensive command-line knowledge.
Open pgAdmin by searching it from the Start button
It will take few seconds to launch
Connect to your PostgreSQL instance using the superuser credentials which you had set during installation
After entering the password, we would be connected to the database
Navigate to Servers > Databases > postgres
Right click on postgres > select Query tool
Run the select version command by typing the following command select version(); on the query space
Execute the query by clicking on the Run button
Result of the Query can be seen under Data Output
Conclusion
In this post we learned about two ways of connecting PostgreSQL database.