How to install PostgreSQL server on Windows

Download & Install PostgreSQL

Download the installer from the official site of PostgreSQL (select the package compatible with your operating system).

  • In this tutorial, we will install PostgreSQL on the Windows operating system. So, we will download the latest version of the Windows installer.
download-postgresql-installer-codexworld

In the Select Components screen, choose “PostgreSQL Server”, “pgAdmin 4”, and “Command Line Tools” to install.

Once the PostgreSQL installer installation is completed, you can connect the database.

You can use the following two ways to connect the PostgreSQL database.

  • SQL Shell (psql)
  • pgAdmin 4

Connect to the PostgreSQL Database using SQL Shell

SQL Shell (psql):
psql is a terminal-based program that allows you to write SQL queries and execute them to the PostgreSQL database. This tool provides an interface to interact with the PostgreSQL database through SQL syntax in the command-line terminal.

Open the SQL Shell (psql) tool, you will see the program window like the below one.

sql-shell-psql-postgresql-command-line-terminal-codexworld

Since we are willing to connect the PostgreSQL database from our local system, the default parameters can be used.

  • The default server is [localhost], press [Enter] to proceed.
  • The default database is [postgres], press [Enter] to proceed.
  • The default port is [5432], press [Enter] to proceed.
  • The default username is [postgres], press [Enter] to proceed.

Enter the password you chose at the time of PostgreSQL database installation.

sql-shell-psql-postgresql-database-server-port-username-password-codexworld

As a result, you will see the below screen, it will show psql (16.3) or the version you installed, and in the end line postgres=# command will show. So you have successfully connected to the PostgreSQL database!

sql-shell-psql-postgresql-database-connection-codexworld

Connect to the PostgreSQL Database using pgAdmin 4

The pgAdmin 4 application provides a user-friendly way to interact with the PostgreSQL database.

Open the pgAdmin4 program and navigate to the database:
Click the [Servers] option in the menu on the left side.

  • Available server will appear, in our case “PostgreSQL 16”, click on it.

A dialog window will appear, enter the password to connect to the server.

  • You need to provide the password that you created at the time of PostgreSQL installation, my password is root.

Under the [Databases] option, you will see the default database.

pgadmin-connect-postgresql-database-codexworld

To run an SQL query, you need to open the Query Tool.

  • Right-click on the database name and select the “Query Tool” option.
pgadmin-query-tool-codexworld

Now, you can execute the SQL query to the PostgreSQL server using psql Shell or pgAdmin 4 programs.

RELATED HOW TO GUIDES

Leave a reply

keyboard_double_arrow_up