Skip to content

Instantly share code, notes, and snippets.

@ststeiger
Last active October 14, 2024 17:48
Show Gist options
  • Save ststeiger/7b01067a02d330a8fca7018089b9dc80 to your computer and use it in GitHub Desktop.
Save ststeiger/7b01067a02d330a8fca7018089b9dc80 to your computer and use it in GitHub Desktop.
Batch-start PostGreSQL on Windows
@echo off
title PostgreSQL Portable
cls
:: set default code page
chcp 1252 > nul
:: initialise a new database on first use
if not exist "%PGDATA%" (
echo.
echo Initialising database for first use, please wait...
"%PGSQL%\bin\initdb" -U %PGUSER% -A trust -E utf8 --locale=C >nul
)
:: startup postgres server
echo.
"%PGSQL%\bin\pg_ctl" -D "%PGDATA%" -l "%PGLOG%" -w start
cls
echo.
echo Type \q to quit and shutdown server
echo.
"%PGSQL%\bin\psql.exe"
echo.
"%PGSQL%\bin\pg_ctl" -D "%PGDATA%" stop
Simpler version:
@echo off
start /B pg_ctl -D "D:\username\Programme\sql\postgresql-16.2-1\data" -l "D:\username\Programme\sql\postgresql-16.2-1\log\logfile.txt" start
echo PostgreSQL started in the background.
cls
echo.
echo Type \q to quit and shutdown server
echo.
"psql.exe"
pg_ctl -D "D:\username\Programme\sql\postgresql-16.2-1\data" stop
echo PostgreSQL stopped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment