Skip to content

Instantly share code, notes, and snippets.

@yilmazdurmaz
Created August 8, 2022 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yilmazdurmaz/3e2229fd2cf3cd5305b57f80c422d677 to your computer and use it in GitHub Desktop.
Save yilmazdurmaz/3e2229fd2cf3cd5305b57f80c422d677 to your computer and use it in GitHub Desktop.
start/stop postgresql server in windows with a simple batch file
:: postgresql is extracted into "d:\pgsql\" and data is init at "d:\pgsql\pgdata"
:: d:\pgsql\bin\initdb -D d:\pgsql\pgdata -U postgres -W -E UTF8 -A scram-sha-256
:: find postres instances running on our data folder
wmic.exe path Win32_Process where name="postgres.exe" get Commandline /format:list | find "d:/pgsql/pgdata" > null
:: stop is already running, and start if not
if errorlevel 1 (d:\pgsql\bin\pg_ctl -D d:\pgsql\pgdata -l logfile start) else (d:\pgsql\bin\pg_ctl -D d:\pgsql\pgdata -l logfile stop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment