Run PostgreSQL on Windows without an installer or admin privileges.
This repo holds the database cluster and helper scripts. PostgreSQL binaries are not included — download and point PG_INSTALL at them.
-
Download EnterpriseDB PostgreSQL binaries (Windows x64).
-
Extract the ZIP to any folder you like. Use the inner
pgsqldirectory (do not flatten the archive). Copy that path forPG_INSTALL, for example:D:\Tools\postgresql-17.6-1-windows-x64-binaries\pgsql -
Copy
.env.exampleto.envand setPG_INSTALLto that path:PG_INSTALL=D:\Tools\postgresql-17.6-1-windows-x64-binaries\pgsql PG_DATA=data
PG_BINdefaults toPG_INSTALL\bin.PG_DATAis relative to this repo unless you use an absolute path. -
For WinCC OA: set
PG_PASSWORDand allWINCCOA_*variables in.env— see.env.exampleand WinCC OA database below.
scripts\pg-setup.bat
scripts\pg-info.bat
scripts\postgres-init.bat
scripts\postgres-start.bat
scripts\postgres-connect.batRun scripts from the repo root or from scripts\. pg-setup.bat creates .venv once, then reuses it.
postgres-init.bat creates the cluster (UTF-8, English US locale, superuser postgres, SCRAM). You will be prompted for a password. To re-init, delete data\ first.
In .env (see .env.example):
PG_PASSWORD=postgres_superuser_password
WINCCOA_USERNAME=winccoa
WINCCOA_PASSWORD="your_password"
WINCCOA_DATABASE=winccoa
WINCCOA_VERSION=3.19
WINCCOA_SCHEMA=C:\Siemens\Automation\WinCC_OA\3.19\data\NGA\PostgreSQL\sqlWINCCOA_VERSION must be 3.19, 3.20, or 3.21 and must match your WinCC OA install. If WINCCOA_SCHEMA contains a version segment (e.g. ...\WinCC_OA\3.19\...), it must equal WINCCOA_VERSION.
WINCCOA_SCHEMA must point at the folder with Siemens schema.sql. Quote passwords that contain # or spaces.
| Version | Schema behavior |
|---|---|
| 3.19 | Tablespaces (winccoa, winccoa_events, winccoa_alerts); schema.sql drops and recreates the database |
| 3.20 / 3.21 | No tablespaces; skips bundled config.sql (uses .env credentials); drops existing DB before create when needed |
After the server is running:
scripts\winccoa-create.batApplies the full NGA schema for your WINCCOA_VERSION. Set WINCCOA_FORCE_RECREATE=yes to drop and recreate (3.20+ drops the database in Python first; 3.19 relies on schema.sql).
scripts\winccoa-drop.bat --yesRequires PG_PASSWORD and confirmation (--yes or WINCCOA_CONFIRM=yes in .env). Drops WINCCOA_DATABASE and terminates active connections. For WINCCOA_VERSION=3.19, also drops tablespaces winccoa, winccoa_events, and winccoa_alerts.
Optional flags:
--drop-userorWINCCOA_DROP_USER=yes— also removeWINCCOA_USERNAMErole--remove-data— delete localdata_winccoa_tablespaces\directories after drop
scripts\postgres-start.bat
scripts\postgres-connect.bat
scripts\postgres-stop.batOther scripts: postgres-restart.bat, postgres-status.bat, pg-info.bat.
postgres-status.bat shows server health, cluster settings, installed databases, and WinCC OA .env targets.
pg-info.bat shows paths and config only (works when the server is stopped).
Pass extra psql arguments through connect:
scripts\postgres-connect.bat -c "SELECT version();"| Item | Path |
|---|---|
| Binaries | PG_INSTALL\bin |
| Data directory | data (e.g. D:\dev\postgresql-portable\data when PG_DATA=data) |
| Startup log | data\log\startup.log |
postgresql-portable/
├── .env # local config (gitignored)
├── data/ # database cluster (gitignored, created by init)
├── pyproject.toml # package metadata and dependencies
├── scripts/ # Windows batch helpers ({group}-{verb}.bat)
│ ├── pg-setup.bat # venv + editable install
│ ├── pg-info.bat # paths and .env (server may be off)
│ ├── postgres-*.bat # server lifecycle
│ └── winccoa-*.bat # WinCC OA database
├── src/
│ └── postgresql_portable/ # Python package (CLI)
└── tests/
Operational batch scripts call python -m postgresql_portable under the hood. Equivalent commands:
| Batch | Python | Notes |
|---|---|---|
scripts\postgres-init.bat |
python -m postgresql_portable init |
|
scripts\postgres-start.bat |
python -m postgresql_portable start |
|
scripts\postgres-stop.bat |
python -m postgresql_portable stop |
|
scripts\postgres-restart.bat |
python -m postgresql_portable restart |
|
scripts\postgres-status.bat |
python -m postgresql_portable status |
Server, databases, cluster info |
scripts\postgres-connect.bat |
python -m postgresql_portable connect |
|
scripts\pg-info.bat |
python -m postgresql_portable info |
PG_* paths and settings (server may be off) |
scripts\winccoa-create.bat |
python -m postgresql_portable create-winccoa |
|
scripts\winccoa-drop.bat |
python -m postgresql_portable drop-winccoa --yes |
|
scripts\pg-setup.bat |
(venv + pip install -e .) |
First-time environment setup |
You can also use the console script after install: postgresql-portable info.
Manual setup without batch scripts:
cd D:\dev\postgresql-portable
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -e .
python -m postgresql_portable info- Missing
.env— copy.env.exampleto.envand setPG_INSTALL. - WinCC OA script fails auth — set
PG_PASSWORDin.envto thepostgressuperuser password. pg-setup.batpermission denied on.venv—.venvalready exists (often while activated). Setup now reuses it; or deactivate, delete.venv, and run setup again for a fresh env.- Data not initialized — run
scripts\postgres-init.batbefore start. postgres-init.bat: directory not empty — delete or emptydata\(e.g.Remove-Item -Recurse -Force data) and run init again. Do not createdata\log\manually before init.- Port 5432 in use — stop other PostgreSQL instances or change
portindata\postgresql.conf. - Start fails — read
data\log\startup.log. - Upgrade PostgreSQL — extract a new version folder, update
PG_INSTALLin.env; keepPG_DATAand runpg_upgradeif needed.
Custom env file:
$env:PG_ENV_FILE = "D:\other\.env"
python -m postgresql_portable infopip install -e .
pytestTests use temporary directories and mocked subprocess calls — no running PostgreSQL required.