Databases Azure

PostgreSQL 18 on Windows Server 2025 on Azure User Guide

| Product: PostgreSQL 18 on Windows Server 2025 on Azure

Overview

PostgreSQL is the open source relational database known for its reliability, standard SQL, transactions, JSON support, full-text search and rich indexing, used by applications of every size.

This image runs PostgreSQL 18.7 as a Windows service on Windows Server 2025 Datacenter (Desktop Experience), listening on TCP 5432. Every connection needs a password (scram-sha-256), and every connection from the network must use TLS. On the first boot of every VM the image creates the database cluster, a TLS certificate and the postgres superuser's password of its own, so nothing is shared between machines and no default password exists. psql, pg_dump, pg_restore and the other command line tools are on the PATH. The Windows Server licence is included in the virtual machine price that Microsoft bills; PostgreSQL is open source under the PostgreSQL Licence. cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours.

What is included:

  • PostgreSQL 18.7 (EDB's Windows x64 binaries, PostgreSQL Licence) in C:\Program Files\PostgreSQL\18, running as the Windows service postgresql-x64-18 (startup Automatic) under its own virtual account NT SERVICE\postgresql-x64-18, not LocalSystem
  • The command line tools (psql, pg_dump, pg_restore, pg_basebackup and the rest) on the machine PATH
  • A database cluster made at first boot in C:\ProgramData\PostgreSQL\18\data (UTF8, locale C), readable only by SYSTEM, Administrators and the service
  • Client authentication by scram-sha-256 password only; TLS required from the network (TLS 1.2 or later), optional from the VM itself
  • A per-VM self signed TLS certificate for the VM's computer name, localhost, its private IP address and its public IP address
  • A per-VM password for the postgres superuser, written to a file only administrators can read
  • A Windows Firewall rule for TCP 5432
  • Windows Server 2025 Datacenter, patched with Windows Update at build, Microsoft Defender Antivirus and Windows Firewall on
  • cloudimg's support team on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours

pgAdmin 4 and StackBuilder are not installed: connect pgAdmin, or any other client, from your own computer (Step 7).

Prerequisites

An active Azure subscription, a Remote Desktop client, and a virtual network in the target region. Standard_B2ms (2 vCPU, 8 GiB RAM) is a good starting point; choose a larger size for bigger databases or more connections. In the network security group, allow inbound TCP 3389 (Remote Desktop) from your own address range. Allow TCP 5432 (PostgreSQL) only from the addresses your applications and administrators connect from; leave it closed if everything that uses the database runs on the VM itself.

Step 1 - Deploy from the Azure Marketplace

Sign in to the Azure Portal, choose Create a resource, search the Marketplace for PostgreSQL 18 on Windows Server 2025 by cloudimg, and select Create. On Basics pick your subscription, resource group, region and size, and set the Administrator account username and password. Under Inbound port rules allow RDP (3389), then narrow the rule's source to your own address range on the Networking tab, and add a rule for TCP 5432 from your own ranges if you will connect from outside the VM. Select Review + create, then Create.

Step 2 - Deploy from the Azure CLI

# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn cloudimg1647283583153:postgresql-windows-server:default:latest

az vm create \
  --resource-group <your-rg> \
  --name postgresql \
  --image cloudimg1647283583153:postgresql-windows-server:default:latest \
  --size Standard_B2ms \
  --admin-username <admin-name> \
  --admin-password '<a strong password>' \
  --public-ip-sku Standard

az vm open-port --resource-group <your-rg> --name postgresql --port 3389 --priority 1000
az vm open-port --resource-group <your-rg> --name postgresql --port 5432 --priority 1010

az vm open-port opens each port to any address; narrow the rules to your own ranges in the network security group afterwards, or skip the second command if nothing outside the VM connects to the database.

First boot takes about five minutes. When the VM first starts, Windows finishes its setup, then the image creates this VM's database cluster, certificate and password and starts PostgreSQL. Port 5432 stays closed in Windows Firewall until the server has passed its own checks. The setup is finished when the file C:\ProgramData\postgresql-windows-server-firstboot.done exists (Step 4).

Step 3 - Connect with Remote Desktop

Connect to the VM's public IP address with your Remote Desktop client (on Windows, mstsc; on macOS, Windows App), signing in with the administrator name and password you set at deployment. Open Windows PowerShell as administrator for the commands below.

Step 4 - Confirm PostgreSQL is running

psql reads the postgres password from the environment variable PGPASSWORD (Step 5 shows where the password is), or asks for it:

Test-Path C:\ProgramData\postgresql-windows-server-firstboot.done
Get-CimInstance Win32_Service -Filter "Name='postgresql-x64-18'" | Format-Table Name, State, StartMode, StartName -AutoSize
Get-NetTCPConnection -State Listen -LocalPort 5432 | Format-Table LocalAddress, LocalPort, @{n='Process';e={(Get-Process -Id $_.OwningProcess).ProcessName}} -AutoSize
psql -V
psql -h localhost -U postgres -c "SELECT version()"
psql -h localhost -U postgres -c "SHOW data_directory"
Get-NetFirewallRule -Group PostgreSQL | Get-NetFirewallPortFilter | Format-Table Protocol, LocalPort -AutoSize
True

Name              State   StartMode StartName
----              -----   --------- ---------
postgresql-x64-18 Running Auto      NT SERVICE\postgresql-x64-18

LocalAddress LocalPort Process
------------ --------- -------
::                5432 postgres
0.0.0.0           5432 postgres

psql (PostgreSQL) 18.7

                                 version
-------------------------------------------------------------------------
 PostgreSQL 18.7 on x86_64-windows, compiled by msvc-19.44.35230, 64-bit
(1 row)

          data_directory
-----------------------------------
 C:/ProgramData/PostgreSQL/18/data
(1 row)

Protocol LocalPort
-------- ---------
TCP      5432

The same commands in an elevated PowerShell window on a new VM:

An elevated PowerShell window on a new VM: first boot done, postgresql-x64-18 running and set to Automatic under its own NT SERVICE account, postgres listening on port 5432, PostgreSQL 18.7, and the firewall rule for TCP 5432

True confirms first boot finished. The service runs under its own account and starts automatically with Windows. The first boot log records what it made:

Get-Content C:\ProgramData\postgresql-windows-server-firstboot.log -Tail 14
2026-12-03T07:29:55.4282129Z provisioning finished
2026-12-03T07:30:06.2271835Z service postgresql-x64-18 as NT SERVICE\postgresql-x64-18, data C:\ProgramData\PostgreSQL\18\data
2026-12-03T07:30:09.9726494Z made C:\ProgramData\PostgreSQL\18\data (SYSTEM, Administrators and NT SERVICE\postgresql-x64-18 only)
2026-12-03T07:33:02.6341540Z cluster made (initdb; UTF8, locale C; scram-sha-256; listen '*' on 5432; hostssl for every address but loopback)
2026-12-03T07:33:07.9353684Z certificate made: CN=wsrdp-f02c11 names=wsrdp-f02c11,localhost,10.20.0.15,<vm-public-ip>,127.0.0.1 sha256=350D51E9E6599DCB3759560D9704A5987A83282F3682B8F571649A9C2391B4C4
2026-12-03T07:33:17.3027952Z server checked: settings=1 hba=1 noPw=1 wrongPw=1 remoteClear=1 remoteTls=1 ssl=on version=18.7 encryption=scram-sha-256 postgresScram=true superusers=1 badRules=0 rules=host,host,hostssl,hostssl listen=* ip=10.20.0.15
2026-12-03T07:33:17.3384894Z credentials written (SYSTEM and Administrators only)
2026-12-03T07:33:17.9983024Z Windows Firewall rule cloudimg-PostgreSQL-In (TCP 5432) enabled
2026-12-03T07:33:18.9527696Z service postgresql-x64-18 Automatic and running
2026-12-03T07:33:35.2614313Z first boot done

The server checked line is first boot's own proof, made before the firewall opened: a sign-in with no password and one with a wrong password were both refused (noPw=1 wrongPw=1), a connection to the VM's own address without TLS was refused (remoteClear=1) and one with TLS was accepted (remoteTls=1), and postgres is the only superuser. The certificate is named for the VM's computer name (wsrdp-f02c11 here), localhost, its private IP address (10.20.0.15 here) and its public IP address (shown as <vm-public-ip>; yours shows its own), and is valid for ten years.

Step 5 - Read the postgres password

First boot wrote the connection settings and the postgres password to a file that only the SYSTEM account and the Administrators group can read. Here it is with the password hidden:

PS> (Get-Content C:\ProgramData\postgresql-windows-server-credentials.txt) -replace '(password=).*', '$1<hidden here>'
# PostgreSQL 18 on Windows Server 2025 by cloudimg: this VM's own database superuser password (made at first boot).
# From your own computer, after allowing TCP 5432 from your address in the network security group (the server
#   refuses any connection from the network that does not use TLS):
#   copy this VM's certificate (the certificate line below) to your computer as server.crt, check its sha256
#   against certificate.sha256 below, then connect verifying it:
#   psql "host=<vm-public-ip> port=5432 dbname=postgres user=postgres sslmode=verify-full sslrootcert=server.crt"
# On this VM (psql is on the PATH): psql -h localhost -U postgres
# Guide: https://www.cloudimg.co.uk/guides/postgresql-on-windows-server-2025-azure/

postgresql-windows-server.host=<vm-public-ip>
postgresql-windows-server.port=5432
postgresql-windows-server.sslmode=verify-full
postgresql-windows-server.database=postgres
postgresql-windows-server.superuser=postgres
postgresql-windows-server.superuser.password=<hidden here>
postgresql-windows-server.certificate=C:\ProgramData\PostgreSQL\18\data\server.crt
postgresql-windows-server.certificate.sha256=350D51E9E6599DCB3759560D9704A5987A83282F3682B8F571649A9C2391B4C4

Run Get-Content C:\ProgramData\postgresql-windows-server-credentials.txt to see the password itself. It is random and different on every VM. Only SYSTEM and Administrators can open the file:

PS> (Get-Acl C:\ProgramData\postgresql-windows-server-credentials.txt).Access | Format-Table IdentityReference, FileSystemRights -AutoSize

IdentityReference      FileSystemRights
-----------------      ----------------
NT AUTHORITY\SYSTEM         FullControl
BUILTIN\Administrators      FullControl

An elevated PowerShell window: the credentials file readable by SYSTEM and Administrators only, and its settings with the password hidden

To use the password in this PowerShell window without showing it, read it into PGPASSWORD:

$env:PGPASSWORD = (Select-String C:\ProgramData\postgresql-windows-server-credentials.txt -Pattern 'superuser\.password=(\S+)').Matches[0].Groups[1].Value

Keep the password somewhere safe, and use postgres for administration only (Step 6 makes a user for your application).

Step 6 - Create a database and a user

Make a login role and a database it owns, choosing the password yourself. \getenv reads it from the environment, so it is never typed on the command line:

PS> $env:APPUSER_PASSWORD = '<a password you choose>'
PS> @"
\getenv pw APPUSER_PASSWORD
CREATE ROLE appuser LOGIN PASSWORD :'pw';
\unset pw
CREATE DATABASE appdb OWNER appuser;
"@ | psql -h localhost -U postgres -d postgres
CREATE ROLE
CREATE DATABASE

Then connect as appuser to the VM's private IP address, which, like any address but localhost, requires TLS. sslmode=verify-full checks the server's certificate against this VM's own server.crt and its name against the address, so nothing can stand in for the server. This makes a table, adds a row, and shows the TLS session:

PS> $env:PGPASSWORD = $env:APPUSER_PASSWORD
PS> @"
CREATE TABLE notes (id serial PRIMARY KEY, body text NOT NULL, added timestamptz NOT NULL DEFAULT now());
INSERT INTO notes (body) VALUES ('hello from appuser over TLS');
SELECT id, body FROM notes;
SELECT ssl, version, cipher FROM pg_stat_ssl WHERE pid = pg_backend_pid();
"@ | psql "host=10.20.0.15 dbname=appdb user=appuser sslmode=verify-full sslrootcert=C:/ProgramData/PostgreSQL/18/data/server.crt"
CREATE TABLE
INSERT 0 1
 id |            body
----+-----------------------------
  1 | hello from appuser over TLS
(1 row)

 ssl | version |         cipher
-----+---------+------------------------
 t   | TLSv1.3 | TLS_AES_256_GCM_SHA384
(1 row)

Use your VM's own private IP address in place of 10.20.0.15 (ipconfig shows it). Write the certificate path with forward slashes: in a connection string a backslash is an escape character. The same connection without TLS is refused:

PS> psql "host=10.20.0.15 dbname=appdb user=appuser sslmode=disable" -c "SELECT 1"
psql: error: connection to server at "10.20.0.15", port 5432 failed: FATAL:  no pg_hba.conf entry for host "10.20.0.15", user "appuser", database "appdb", no encryption

The same checks as postgres, on a new VM: the connection's TLS session, and the databases the cluster starts with:

An elevated PowerShell window: psql connected to the VM's private address with sslmode=verify-full, the session using TLSv1.3, and the postgres, template0 and template1 databases in UTF8 with collation C

Step 7 - Connect from your own computer

  1. Allow TCP 5432 from your own address in the VM's network security group.
  2. On the VM, show the certificate (it is public, not a secret) and copy its text, from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----, into a file named server.crt on your computer.
  3. Check that the copy is this VM's certificate: its SHA-256 fingerprint must equal certificate.sha256 in the credentials file (Step 5).
  4. Connect with sslmode=verify-full, naming the VM by its public IP address, the address the certificate was made for.

On the VM:

Get-Content C:\ProgramData\PostgreSQL\18\data\server.crt

On your computer, with OpenSSL (it prints the same hex digits separated by colons):

openssl x509 -in server.crt -noout -fingerprint -sha256

Then connect with any PostgreSQL client. With psql:

psql "host=<vm-public-ip> port=5432 dbname=postgres user=postgres sslmode=verify-full sslrootcert=server.crt"

In pgAdmin or another graphical client, set SSL mode to verify-full and the root certificate to your server.crt. If you point a DNS name at the VM, verify-full refuses it, because the certificate does not carry that name: install a certificate for the name (Use your own certificate below).

How the server is set up

Who may connect, from pg_hba.conf:

host     all       all   127.0.0.1/32   scram-sha-256
host     all       all   ::1/128        scram-sha-256
hostssl  all       all   0.0.0.0/0      scram-sha-256
hostssl  all       all   ::/0           scram-sha-256

From the VM itself (localhost) TLS is optional; from any other address only TLS connections are accepted, and every connection needs a scram-sha-256 password. To allow only some addresses, replace 0.0.0.0/0 and ::/0 with your own ranges, then run psql -h localhost -U postgres -c "SELECT pg_reload_conf()".

The settings first boot adds to postgresql.conf:

listen_addresses = '*'
port = 5432
max_connections = 100
shared_buffers = 256MB
password_encryption = 'scram-sha-256'
ssl = on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
ssl_min_protocol_version = 'TLSv1.2'
logging_collector = on
log_directory = 'log'
log_line_prefix = '%m [%p] %q%u@%d '
log_timezone = 'UTC'
timezone = 'UTC'

Raise shared_buffers (about a quarter of the VM's memory) and max_connections for a larger VM, then Restart-Service postgresql-x64-18.

Use your own certificate

The image's certificate is self signed. To use a certificate your clients already trust, for example one for a DNS name that points at the VM, replace server.crt and server.key in C:\ProgramData\PostgreSQL\18\data with your certificate and its unencrypted private key (both PEM), keeping the files' permissions, then Restart-Service postgresql-x64-18. Clients then use sslmode=verify-full with your certificate authority's root as sslrootcert.

Server components

Component Version Where
PostgreSQL 18.7 C:\Program Files\PostgreSQL\18, service postgresql-x64-18
Microsoft Visual C++ 2015-2022 runtime (x64) 14.52.37029.0 installed for PostgreSQL
Windows Server 2025 Datacenter Desktop Experience

Files and folders

Path What it holds
C:\Program Files\PostgreSQL\18 The server and tools (bin, lib, share), the licences and README.txt
C:\ProgramData\PostgreSQL\18\data The cluster: databases, postgresql.conf, pg_hba.conf, server.crt, server.key (only SYSTEM, Administrators and the service)
C:\ProgramData\PostgreSQL\18\data\log The server log
C:\ProgramData\postgresql-windows-server-credentials.txt This VM's connection settings and postgres password (Step 5)
C:\ProgramData\postgresql-windows-server-firstboot.log What first boot did (it never contains a password)

Maintenance

  • Windows updates: Windows Update is on, as Microsoft ships it. Restarting the VM restarts PostgreSQL automatically.
  • Back up your data: use Azure Backup of the VM, or pg_dump for one database (pg_dump -h localhost -U postgres -Fc -f appdb.dump appdb) and pg_dumpall for the whole cluster. Keep the backups off the VM.
  • Upgrade PostgreSQL: minor releases of 18 (18.8 and later) replace the program files and keep the data folder; a new major version needs pg_upgrade or a dump and restore. Back up first.
  • Logs: the server log is in C:\ProgramData\PostgreSQL\18\data\log (a new file each day and at each start), with every refused sign-in.
  • Firewall: Windows Firewall allows TCP 5432 through the rule in the PostgreSQL group; the network security group decides who can reach it.

Troubleshooting

  • Nothing answers on 5432 just after deployment: first boot is still running (about five minutes). Wait for C:\ProgramData\postgresql-windows-server-firstboot.done, and read the first boot log.
  • no pg_hba.conf entry ... no encryption: the client connected from the network without TLS. Use sslmode=verify-full (or at least sslmode=require).
  • password authentication failed for user "postgres": use the password from Step 5.
  • certificate verify failed or server certificate for "..." does not match host name: sslrootcert is not this VM's server.crt, or the host is a name the certificate does not carry. Connect by the public or private IP address, or install your own certificate.
  • A connection from your computer times out: allow TCP 5432 from your address in the network security group.

Support

cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours. Contact support@cloudimg.co.uk.