Saturday, January 25, 2014

PostgreSQL script to keep postgreSQL server running


:loop

@ECHO OFF

set PSQL="C:\Program Files\PostgreSQL\9.1\bin"

set DBNAME="template1"

set USER="postgres"

set PORT="5432"

set RES="Not Pinging"

%PSQL%\psql -Atq -c "SELECT 'ping'" -p %PORT% -U %USER% %DBNAME% > _Res.txt

set /p RES=<_Res.txt

IF %RES% EQU ping (echo "Postgres running... ") else (echo "PostgreSQL seems not pinging.. Restarting..."
sc start postgreSQL-9.1 > NUL
)

ping -n 10 127.0.0.1 > NUL

goto loop

No comments:

Post a Comment