Skip to content
Install PostgreSQL on Windows: Step-by-Step Guide (2026)

Click to use (opens in a new tab)

Install PostgreSQL on Windows: Step-by-Step Guide (2026)

August 27, 2026 by Chat2DBChat2DB Team

Installing PostgreSQL on Windows is a ten-minute job when you know which choices matter — and a frustrating afternoon when you hit psql is not recognized, a forgotten superuser password, or a service that refuses to start. This guide walks through the EDB installer step by step, covers the command-line alternative with winget, and fixes the errors that appear most often on Windows 10 and 11.

Which installation method to pick

There are three sensible ways to run PostgreSQL on Windows:

MethodBest for
EDB interactive installerMost users; installs server + psql + pgAdmin + StackBuilder
winget / command lineScripted setups, dev machines, dotfiles automation
Docker DesktopThrowaway databases, matching a Linux production version

If you just want PostgreSQL running as a normal Windows service, use the EDB installer. It is the build the PostgreSQL project links from postgresql.org/download/windows.

Method 1: The EDB installer, step by step

1. Download. Go to postgresql.org, click Download → Windows → "Download the installer", and pick the newest major version (18.x as of 2026) for Windows x86-64.

2. Run the installer. The wizard asks a series of questions; here is what each one means:

  • Installation directory — default C:\Program Files\PostgreSQL\18 is fine.
  • Components — keep PostgreSQL Server and Command Line Tools. pgAdmin 4 is optional (see the GUI section below). Stack Builder can be unticked; you can add extensions later.
  • Data directory — default C:\Program Files\PostgreSQL\18\data. If this machine hosts real data, putting the data directory on a separate drive (e.g. D:\pgdata) makes future reinstalls painless.
  • Password — this sets the password for the postgres superuser. Write it down; this is the credential everyone forgets.
  • Port5432 unless something else already uses it.
  • Locale — "Default locale" is fine; it affects sort order, not data safety.

3. Finish and verify. The installer registers a Windows service named postgresql-x64-18 and starts it. Verify from PowerShell:

Get-Service postgresql*
 
# Status   Name                DisplayName
# ------   ----                -----------
# Running  postgresql-x64-18   postgresql-x64-18 - PostgreSQL Server 18

Fix PATH so psql works

The number-one post-install complaint: 'psql' is not recognized as an internal or external command. The installer does not add the bin directory to your PATH. Add it:

# PowerShell (run as your user, then restart the terminal)
[Environment]::SetEnvironmentVariable(
  "Path",
  $env:Path + ";C:\Program Files\PostgreSQL\18\bin",
  "User"
)

Or via GUI: Start → "Edit environment variables for your account" → Path → New → C:\Program Files\PostgreSQL\18\bin.

Open a new terminal and connect:

psql -U postgres -h localhost
Password for user postgres: ********
 
psql (18.4)
postgres=#

First commands worth running:

SELECT version();
 
-- Create a working database and a non-superuser role
CREATE ROLE dev LOGIN PASSWORD 'dev-password';
CREATE DATABASE devdb OWNER dev;

Then connect to it: psql -U dev -d devdb -h localhost.

Method 2: winget (command-line install)

Windows Package Manager ships with Windows 10 21H2+ and Windows 11:

winget install PostgreSQL.PostgreSQL.18

This runs the same EDB installer in unattended mode. The service, default port and directories match the interactive install; the superuser password is set to postgres on some versions — change it immediately:

psql -U postgres -c "ALTER USER postgres PASSWORD 'a-real-password';"

For fully scripted installs with explicit options, call the EDB installer directly:

.\postgresql-18.4-1-windows-x64.exe --mode unattended `
  --superpassword "a-real-password" --serverport 5432 `
  --datadir "D:\pgdata"

Managing the service

PostgreSQL runs as a Windows service, so it starts with the machine. Control it with either the Services app (services.msc) or the command line:

# PowerShell (as Administrator)
Restart-Service postgresql-x64-18
Stop-Service    postgresql-x64-18
Start-Service   postgresql-x64-18
 
# Or with pg_ctl, which prints better error messages
& "C:\Program Files\PostgreSQL\18\bin\pg_ctl.exe" `
  -D "C:\Program Files\PostgreSQL\18\data" status

Config files live in the data directory: postgresql.conf (settings) and pg_hba.conf (who may connect from where). After editing either, reload without a restart:

SELECT pg_reload_conf();

Common Windows-specific problems

psql: error: connection to server at "localhost" (::1), port 5432 failed: Connection refused — the service is not running. Check Get-Service postgresql*; if it is stopped and will not start, read the newest file in data\log\ — the real cause is always in there. The two usual culprits: another program bound port 5432, or a permissions problem on the data directory after moving it.

Forgot the postgres password. Edit pg_hba.conf, change the 127.0.0.1/32 line's method from scram-sha-256 to trust, restart the service, connect with psql -U postgres, run ALTER USER postgres PASSWORD 'new-password';, then revert pg_hba.conf and restart again.

Port 5432 already in use — usually an older PostgreSQL major version still installed. Either uninstall it, or run the new one on 5433 and connect with psql -p 5433.

Installer fails with "Unable to write inside TEMP environment path" — an antivirus is blocking the installer's scripts; temporarily disable it or add an exclusion for the installer.

Locale/checksum errors after copying a data directory from another machine — you cannot mix data directories across major versions or OSes. Use pg_dump/pg_restore to move data instead.

Connecting with a GUI

psql is worth learning, but a GUI makes exploring schemas and writing queries much faster. The EDB installer bundles pgAdmin, which is serviceable but heavy. A lighter, more modern option is Chat2DB (opens in a new tab) — a free desktop client for Windows that connects to PostgreSQL (plus MySQL, SQL Server, Oracle and 20+ other engines) and adds an AI assistant that turns plain English into SQL against your actual schema. There is also a zero-install web version at app.chat2db.ai (opens in a new tab).

Connection settings for a local install, in any client:

  • Host: localhost, Port: 5432
  • Database: postgres (or your own)
  • User: postgres, Password: the one from the installer

Uninstalling cleanly

Settings → Apps → PostgreSQL 18 → Uninstall runs the EDB uninstaller. Two things it leaves behind on purpose: the data directory (your databases) and the registry entries for the service if the uninstall was interrupted. Delete the data directory manually once you are sure nothing in it matters, and remove a stale service with sc.exe delete postgresql-x64-18 from an elevated prompt.

One WSL2 note: PostgreSQL installed inside WSL2 (Ubuntu) and PostgreSQL installed natively on Windows are separate worlds with separate data directories, and both may claim port 5432. If psql connects to a server you do not recognize, check which one you are talking to with SELECT version(); — the Windows build reports Visual C++, the WSL build reports gcc. Pick one home for your dev database and stop the other's service to avoid chasing phantom data.

Summary

The EDB installer plus a PATH entry gives you a full PostgreSQL setup on Windows in about ten minutes: server as a service, psql on the command line, and a GUI of your choice on top. The three decisions worth making deliberately are the superuser password (store it in a password manager), the data directory location (separate drive if the data matters), and the port (default 5432 unless it collides). Everything else can be changed later in postgresql.conf without reinstalling.