PowerShell Installation Method

For Windows installations, PostgreSQL 17.4 is installed using a PowerShell script that automates the installation process.


Prerequisites

Installation Steps

1. Open PowerShell as Administrator

Right-click on PowerShell and select "Run as Administrator"

2. Set Execution Policy (if needed)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
3. Run the Installation Script

Execute the pre-written PostgreSQL installation script (install-postgresql.ps1):

Basic usage with default parameters:

.\install-postgresql.ps1

Custom installation with parameters:

.\install-postgresql.ps1 -BaseDir "C:\PostgreSQL" -ServerPort 5433 -DataDir "C:\PostgreSQL\pgdata"

Script Parameters

Parameter Description Default Value
BaseDir Installation directory for PostgreSQL the script directory
ServerPort Port number for PostgreSQL server 5432
DataDir Data directory for PostgreSQL database cluster data (inside installation directory)

Examples

Example 1: Install with all default settings

.\install-postgresql.ps1

Example 2: Custom installation directory

.\install-postgresql.ps1 -BaseDir "C:\Program Files\PostgreSQL"

Example 3: Custom port

.\install-postgresql.ps1 -ServerPort 5433

Example 4: Full custom configuration

.\install-postgresql.ps1 -BaseDir "E:\Database\PostgreSQL" -ServerPort 5433 -DataDir "E:\Database\PostgreSQL\pgdata"

Post-Installation Verification

After the script completes, verify the installation by opening Command Prompt or PowerShell and running:

psql --version

Expected output: psql (PostgreSQL) 17.4

The PostgreSQL service should start automatically after installation.

Alternative: Manual Installation

PostgreSQL provides an official Windows installer available at the PostgreSQL Windows Downloads page. The installer offers both graphical and silent installation modes.