@echo off

set pgdir=./
set ctl=%pgdir%/bin/pg_ctl
set dir=%pgdir%/data
set pid=%dir%/postmaster.pid

:: set environmental variables for PostGIS Raster
set GDAL_DATA=../gdal-data
set POSTGIS_GDAL_ENABLED_DRIVERS=ENABLE_ALL
set POSTGIS_ENABLE_OUTDB_RASTERS=1

if exist "%pid%" (
    echo postmaster.pid exists and PostgreSQL have been started possibly.
    goto ask
) else (
    "%ctl%" -D "%dir%" start
)

:ask
set /p inp="press [R] to restart PostgreSQL, [Q] to quit : "
if "%inp%"=="R" (
    "%ctl%" -D "%dir%" restart
) else if "%inp%"=="Q" (
    "%ctl%" -D "%dir%" stop
    goto :eof
)
goto ask