How to Install PostgreSQL on Windows Server 2025
PostgreSQL is one of the world’s most advanced open-source relational database management systems, renowned for its standards compliance, extensibility, and rock-solid reliability. Whether you are building a new application backend, migrating from another database platform, or standing up a data warehouse, PostgreSQL on Windows Server 2025 is a production-ready choice. This guide walks through every step of the installation and initial configuration using the EnterpriseDB (EDB) distribution — the most widely used PostgreSQL installer for Windows — covering component selection, data directory setup, network configuration, firewall rules, and first-connection testing with both psql and pgAdmin 4.
Prerequisites
- Windows Server 2025 (Standard or Datacenter edition, fully patched)
- Administrator or Domain Admin privileges on the server
- At least 4 GB RAM and 20 GB free disk space for the data directory
- Outbound internet access (or a pre-downloaded installer) from postgresql.org
- Windows Firewall or a perimeter firewall you can configure
- A dedicated service account or the default
NT AUTHORITYNetworkService(the installer handles this automatically)
Step 1 — Download the EDB PostgreSQL Installer
Navigate to https://www.postgresql.org/download/windows/ and click Download the installer. This takes you to the EDB downloads page. Select the latest PostgreSQL 16 (or 17) release for Windows x86-64. At the time of writing, PostgreSQL 16.x is the long-term support release recommended for production servers. Download the .exe installer (roughly 300 MB) to a local folder such as C:Installers.
Alternatively, you can download directly from PowerShell:
# Download PostgreSQL 16 installer
$url = "https://get.enterprisedb.com/postgresql/postgresql-16.4-1-windows-x64.exe"
$dest = "C:Installerspostgresql-16.4-1-windows-x64.exe"
Invoke-WebRequest -Uri $url -OutFile $dest -UseBasicParsing
Write-Host "Download complete: $dest"
Step 2 — Run the Installer and Select Components
Right-click the downloaded .exe and choose Run as administrator. The EDB Setup Wizard opens. Work through the screens as follows:
- Installation Directory — Accept the default
C:Program FilesPostgreSQL16or choose a custom path. Keep program files and data files on separate volumes for production workloads. - Select Components — Ensure all three are checked:
- PostgreSQL Server — the database engine itself
- pgAdmin 4 — the web-based GUI management tool
- Stack Builder — a utility to install additional drivers and extensions (PostGIS, ODBC, etc.) post-install
- Command Line Tools is selected by default and should remain checked
- Data Directory — The default is
C:Program FilesPostgreSQL16data. For production, redirect this to a dedicated data volume, for exampleD:PGData16, to isolate I/O and make backup policy simpler. - Password — Enter a strong password for the
postgressuperuser account. Store this in your password manager immediately. - Port — Leave as 5432 (the standard PostgreSQL port) unless you have a specific reason to change it.
- Locale — Select the locale appropriate for your data. For most English-language deployments, English, United States (
en-US) is correct. This setting controls default collation and cannot be changed without re-initialising the cluster. - Click Next and then Finish to complete installation. The installer creates the
postgresWindows user account and registers thepostgresql-x64-16Windows service.
Step 3 — Verify the Windows Service
Confirm that PostgreSQL started successfully:
# Check service status
Get-Service -Name "postgresql-x64-16"
# Expected output:
# Status Name DisplayName
# ------ ---- -----------
# Running postgresql-x64-16 postgresql-x64-16
# View the service startup type
Get-Service -Name "postgresql-x64-16" | Select-Object Name, Status, StartType
If the service is not running, check the Windows Event Log (Application log, source PostgreSQL) for startup errors.
Step 4 — Configure postgresql.conf for Production
The primary configuration file is located in the data directory. Open it in a text editor run as Administrator:
notepad "D:PGData16postgresql.conf"
# or with the default path:
notepad "C:Program FilesPostgreSQL16datapostgresql.conf"
Adjust the following key parameters. Values below assume a dedicated 16 GB RAM server; scale proportionally for your hardware:
# Network — allow connections from all interfaces
listen_addresses = '*' # default is 'localhost'
# Connections
max_connections = 200 # default 100; tune to your workload
# Memory
shared_buffers = 4GB # ~25% of total RAM
effective_cache_size = 12GB # ~75% of total RAM (hint for planner)
work_mem = 64MB # per sort/hash; watch total = max_connections * work_mem
maintenance_work_mem = 1GB # for VACUUM, CREATE INDEX, etc.
# Write-Ahead Log
wal_level = replica # enables streaming replication if needed later
checkpoint_completion_target = 0.9
wal_buffers = 64MB
# Logging (recommended for production)
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_rotation_age = 1d
log_rotation_size = 100MB
log_min_duration_statement = 1000 # log queries taking > 1 second
Save the file. Changes to postgresql.conf require a service restart to take effect (some parameters support pg_reload_conf() without a full restart — check the documentation column Context).
Step 5 — Configure pg_hba.conf for Remote Access
pg_hba.conf (Host-Based Authentication) controls who can connect, from where, and using which authentication method. The default configuration only allows local connections. To permit remote clients:
notepad "D:PGData16pg_hba.conf"
Add or modify entries at the end of the file. Use scram-sha-256 (the modern, secure default in PostgreSQL 14+) rather than the older md5:
# TYPE DATABASE USER ADDRESS METHOD
# Allow the postgres superuser from the local server
host all postgres 127.0.0.1/32 scram-sha-256
# Allow all users to all databases from your trusted subnet
host all all 192.168.1.0/24 scram-sha-256
# Allow a specific application user from a specific IP
host appdb appuser 10.10.5.20/32 scram-sha-256
# If you must allow from any IP (not recommended for production):
# host all all 0.0.0.0/0 scram-sha-256
After editing both configuration files, restart the service:
Restart-Service -Name "postgresql-x64-16"
Get-Service -Name "postgresql-x64-16" # confirm Running
Step 6 — Open Windows Firewall Port 5432
# Allow inbound TCP connections on port 5432
New-NetFirewallRule `
-DisplayName "PostgreSQL 5432" `
-Direction Inbound `
-Protocol TCP `
-LocalPort 5432 `
-Action Allow `
-Profile Domain,Private
# Verify the rule was created
Get-NetFirewallRule -DisplayName "PostgreSQL 5432" | Select-Object DisplayName, Enabled, Direction
Step 7 — Test the Connection with psql
The psql command-line client is installed alongside the server. Add it to your PATH or use the full path:
# Add psql to the current session PATH
$env:PATH += ";C:Program FilesPostgreSQL16bin"
# Connect as the postgres superuser (will prompt for password)
psql -U postgres -h 127.0.0.1 -p 5432
# Once connected, run basic checks:
-- Show server version
SELECT version();
-- List databases
l
-- Create a test database and user
CREATE DATABASE testdb;
CREATE USER appuser WITH PASSWORD 'StrongP@ssw0rd!';
GRANT ALL PRIVILEGES ON DATABASE testdb TO appuser;
-- Exit
q
Step 8 — Connect with pgAdmin 4
pgAdmin 4 is installed as a local web application and opens in your default browser. Launch it from the Start Menu (PostgreSQL 16 > pgAdmin 4). On first launch, set a master password for the pgAdmin keystore.
- In the left panel, right-click Servers and choose Register > Server.
- On the General tab, enter a name such as Local PostgreSQL 16.
- On the Connection tab:
- Host:
127.0.0.1 - Port:
5432 - Maintenance database:
postgres - Username:
postgres - Password: (your postgres superuser password)
- Host:
- Click Save. pgAdmin connects and displays the server tree.
Step 9 — (Optional) Install Extensions with Stack Builder
Launch Stack Builder from the Start Menu to install additional components post-setup. Useful add-ons include:
- PostGIS — spatial and geographic data support
- pgAgent — PostgreSQL job scheduler
- PostgreSQL ODBC Driver — for Excel, Power BI, and legacy application connectivity
- EDB Language Pack — PL/Python, PL/Perl support
Stack Builder walks through component selection, download, and installation automatically.
Conclusion
You now have a fully operational PostgreSQL 16 instance running as a Windows service on Windows Server 2025, with remote access enabled through pg_hba.conf, a hardened firewall rule on port 5432, and both psql and pgAdmin 4 available for administration. From here, the next steps are to configure automated backups with pg_dump or continuous archiving (WAL archiving + point-in-time recovery), set up streaming replication for high availability, and tune autovacuum thresholds to match your workload. PostgreSQL’s broad ecosystem — logical replication, foreign data wrappers, full-text search, JSON/JSONB support — makes it a versatile foundation for virtually any data-driven application.