FastAPI - Beginner to Pro / Large Production Database Setup

PostgreSQL Windows Installation

🐘 Installing PostgreSQL on Windows

PostgreSQL is one of the most powerful open-source relational databases used in production systems. It is widely used with frameworks like Django, FastAPI, Node.js, and Spring Boot.

This guide explains how to install PostgreSQL on Windows step-by-step.


πŸ“₯ Step 1: Download PostgreSQL

  1. Open the official PostgreSQL website:

    https://www.postgresql.org/download/windows/

  2. Click Download the Installer

  3. You will be redirected to EnterpriseDB website

  4. Download the latest PostgreSQL version for Windows

Example file name:

postgresql-16.x-windows-x64.exe

βš™οΈ Step 2: Run the Installer

  1. Double-click the downloaded .exe file

  2. The Setup Wizard will open

  3. Click Next


πŸ“ Step 3: Choose Installation Directory

Default path usually:

C:\\Program Files\\PostgreSQL\\16

You can keep the default.

Click Next


🧩 Step 4: Select Components

Choose the components to install.

Typical components include:

Component

Description

PostgreSQL Server

Main database server

pgAdmin

GUI tool for database management

Stack Builder

Additional tools & extensions

Command Line Tools

CLI utilities like psql

Recommended: Install all components

Click Next


πŸ’Ύ Step 5: Choose Data Directory

This is where PostgreSQL stores database files.

Default location:

C:\\Program Files\\PostgreSQL\\16\\data

Click Next


πŸ” Step 6: Set Database Password

You must set a password for the postgres superuser.

Example:

Username: postgres
Password: yourpassword

⚠️ Important: Remember this password. You will need it to log in.

Click Next


🌐 Step 7: Configure Port

Default PostgreSQL port:

5432

Keep the default unless another service is already using this port.

Click Next


🌎 Step 8: Choose Locale

Locale controls language and formatting.

Example:

Default locale

Click Next


πŸš€ Step 9: Install PostgreSQL

Click Install.

<aside> πŸ’‘

Skip Stack Builder Setup. Click Cancel

</aside>

The installer will now:

  • Install PostgreSQL server

  • Setup database cluster

  • Install pgAdmin

  • Configure services

Installation usually takes 2–5 minutes.


πŸŽ‰ Step 10: Finish Installation

After installation:

Click Finish

PostgreSQL is now installed on your system.


πŸ–₯️ Step 11: Open pgAdmin

To open pgAdmin:

Start Menu β†’ pgAdmin 4

Steps:

  1. pgAdmin will open in your browser

  2. Enter the master password

  3. Expand:

Servers β†’ PostgreSQL
  1. Enter the postgres password

Now you can manage databases.


πŸ’» Step 12: Test PostgreSQL with Command Line

Open Command Prompt and run:

psql -U postgres

Enter password.

If successful, you will see:

postgres=#

Example commands:

SELECT version();

Create database:

CREATE DATABASE testdb;

List databases:

\\l

Exit:

\\q

πŸ“Œ PostgreSQL Important Paths (Windows)

Item

Location

PostgreSQL Install

C:\\Program Files\\PostgreSQL\\16

Data Folder

C:\\Program Files\\PostgreSQL\\16\\data

psql CLI

C:\\Program Files\\PostgreSQL\\16\\bin


⚑ Useful PostgreSQL Commands

Command

Description

psql -U postgres

Connect to database

\\l

List databases

\\c dbname

Connect database

\\dt

List tables

\\q

Quit psql