Skip to content

Instantly share code, notes, and snippets.

@ergo70
Last active March 7, 2026 20:34
Show Gist options
  • Select an option

  • Save ergo70/ff29a9a4f18b12920eea86bd1e8c62cd to your computer and use it in GitHub Desktop.

Select an option

Save ergo70/ff29a9a4f18b12920eea86bd1e8c62cd to your computer and use it in GitHub Desktop.
Create ephemeral PostgreSQL 18.x Server using Windows Sandbox
@echo off
wsb start
if %ERRORLEVEL% EQU 0 echo 0
wsb list > id.txt
if %ERRORLEVEL% EQU 0 echo 1
set /p id=<id.txt
del id.txt
if %ERRORLEVEL% EQU 0 echo 2
wsb exec -r System -c "curl -L https://sbp.enterprisedb.com/getfile.jsp?fileid=1260041 --output C:\Users\WDAGUtilityAccount\Downloads\installer.exe" --id %id%
if %ERRORLEVEL% EQU 0 echo 3
wsb exec -r System -c "C:\Users\WDAGUtilityAccount\Downloads\installer.exe --install_runtimes 1 --disable-components pgAdmin,stackbuilder --mode unattended --unattendedmodeui none --superpassword postgres --create_shortcuts 0 --servicename postgresql18 --datadir C:\PostgreSQL\18\data --prefix C:\PostgreSQL\18" --id %id%
if %ERRORLEVEL% EQU 0 echo 4
wsb exec -r System -c "cmd /c del C:\Users\WDAGUtilityAccount\Downloads\installer.exe" --id %id%
wsb exec -r System -c "netsh advfirewall firewall add rule name=PostgreSQL dir=in action=allow program=C:\PostgreSQL\18\bin\postgres.exe protocol=TCP localport=5432 enable=yes remoteip=localsubnet profile=public" --id %id%
if %ERRORLEVEL% EQU 0 echo 5
wsb exec -r System -c "net stop postgresql18" --id %id%
if %ERRORLEVEL% EQU 0 echo 6
wsb exec -r System -c "cmd /c echo host all all 0.0.0.0/0 scram-sha-256>> C:\PostgreSQL\18\data\pg_hba.conf" --id %id%
if %ERRORLEVEL% EQU 0 echo 7
wsb exec -r System -c "net start postgresql18" --id %id%
if %ERRORLEVEL% EQU 0 echo 8
wsb ip --id %id% > ip.txt
if %ERRORLEVEL% EQU 0 echo 9
type ip.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment