Skip to content

Instantly share code, notes, and snippets.

@albertopasqualetto
Created November 7, 2022 20:50
Show Gist options
  • Save albertopasqualetto/e88fee17459fbf05b7cbd1e4983c13be to your computer and use it in GitHub Desktop.
Save albertopasqualetto/e88fee17459fbf05b7cbd1e4983c13be to your computer and use it in GitHub Desktop.
Start or stop postgresql service if it is (not) running
@echo off
:: Source: https://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file
:: Source: https://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights
:: batch code to request admin previleges, if no admin previleges
fltmc >nul 2>&1
if NOT %errorLevel% == 0 (
powershell start -verb runas '%0' am_admin & exit /b
)
net start | findstr /c:"postgresql-x64-15" >nul 2>&1
if errorlevel == 1 (
echo Starting postgresql...
net start postgresql-x64-15
pause
) else (
echo Stopping postgresql...
net stop postgresql-x64-15
pause
)
@albertopasqualetto
Copy link
Author

This has to be updated using \PostgreSQL\15\scripts\runpsql.bat, the file used by default after a postresql install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment