How To Setup And Install PostgreSQL Database Locally

What is PostgreSQL and its use case?

PostgreSQL (often called "Postgres" for short) is a free and open-source object-based relational database management system (RDBMS) that emphasizes extensibility and SQL compliance. It is well-suited for a wide range of use cases and is particularly well-suited for applications that require complex data processing and high levels of data integrity.

PostgreSQL is often used in situations where data integrity and robustness are a high priority, as well as in situations where complex data relationships and advanced data processing are required. It is a popular choice for web and mobile applications, data warehousing, and business intelligence systems, as well as for geographic information systems (GIS) and other scientific applications.

In general, PostgreSQL is a better choice for open-source projects, or for projects where cost is a major concern, whereas Microsoft SQL Server is a better choice for Windows-based enterprise environments or for projects that require integration with other Microsoft products.

This article demonstrates step by step approach on how to install and setup PostgreSQL DB locally on windows m/c.

Step 1. Download PostgreSQL Installer

Let’s download the windows installer from https://www.postgresql.org/download/windows/

Setup And Install PostgreSQL Database Locally

Step 2. Install PostgreSQL exe file

Double-click on the installation file (in my case “postgresql-15.1-1-windows-x64.exe”), and it will start on the installation wizard.

Let’s choose the installation directory.

Setup And Install PostgreSQL Database Locally

Click Next, and select the default components you want to install. Let’s keep the default selection.

Setup And Install PostgreSQL Database Locally

Click Next, and select the directory where data will be stored.

Setup And Install PostgreSQL Database Locally

Click Next, and enter the database superuser password. Remember, this password will be used for future use.

Setup And Install PostgreSQL Database Locally

Click Next, this is the port number where the PostgreSQL server listens. This is the default port number 5432 for PostgreSQL server.

Setup And Install PostgreSQL Database Locally

On click of Next, we will see pre-installation summary. Let’s click Next to begin installing PostgreSQL.

NOTE: This is an optional and additional steps in case below error.

During installation, if we get the error “Problem running the post-install step. Installation may not complete correctly. The database cluster initialisation failed.” Here, we need to perform certain extra steps to make this work.

Setup And Install PostgreSQL Database Locally

Let’s go to “C:\Program Files\PostgreSQL\15\bin” and run CMD and execute the below command

initdb -D "C:\Program Files\PostgreSQL\15\data" -U postgres

Setup And Install PostgreSQL Database Locally

pg_ctl start -D "C:\Program Files\PostgreSQL\15\data"

Setup And Install PostgreSQL Database Locally

Step 3. Connect to the PostgreSQL server using pgAdmin

Open pgAdmin 4 from the Start menu. For the first time, it will ask you to set a master password.

Right-click the Servers icon on the left-hand side. Select Register > Server to set up a new database server. Give a name to the server.

In the Connection tab, we need to enter the hostname (default is localhost) and password selected during the setup process and click on Save.

Setup And Install PostgreSQL Database Locally

Let’s set Binary Path from File -> Preferences -> Paths -> Binary paths  

Setup And Install PostgreSQL Database Locally

Verify the PostgreSQL databases version from Query Tool, this option is available if you do right-click on Postgres database.

Setup And Install PostgreSQL Database Locally

We are successfully up and running PostgreSQL server locally and managing PostgreSQL databases from pgAdmin 4.

Happy Learning!


Recommended Ebook

Printing in C# Made Easy

Download Now!
Similar Articles