PostgreSQL registration Start and Stop unmount batch processing script, postgresql Batch Processing
Register to start pg_install.bat:
echo offset PGSQL_DIR=%~dp0if not "%PGSQL_HOME%"=="" ( if not "%PGSQL_HOME%"=="%PGSQL_DIR%" ( echo PGSQL_HOME=%PGSQL_HOME% != PGSQL_DIR=%PGSQL_DIR% goto pg_ends )) else ( set PGSQL_HOME=%PGSQL_DIR% echo PGSQL_HOME must be set as PGSQL_DIR=%PGSQL_DIR%)set PATH=%PGSQL_HOME%bin;%PGSQL_HOME%lib;%PATH%pg_isready -h localhost 1>nul 2>nul@if "%ERRORLEVEL%" == "0" ( echo PostgreSQL is running. goto pg_ends)echo "PGSQL_HOME = %PGSQL_HOME%"echo Install and start PostgreSQL server ...@if not exist %PGSQL_HOME%data (mkdir %PGSQL_HOME%data%PGSQL_HOME%bin/initdb --username=root --pgdata=%PGSQL_HOME%data --encoding=UTF8 --locale=chineserem @if not "%ERRORLEVEL%" == "0" (rem There ERRORLEVEL is 2, but successfully initedrem echo PostgreSQL initdb failed.rem goto pg_endsrem )) pg_ctl register --pgdata=%PGSQL_HOME%data -N pgsql_srv -S demandnet start pgsql_srvrem pg_ctl -w startpg_isready -h localhost 1>nul 2>nul@if "%ERRORLEVEL%" == "0" (echo PostgreSQL server started successfully) else (echo Failed to start PostgreSQL server):pg_endscmd /K
Disable uninstall pg_stop.bat:
@echo offecho Stop and uninstall PostgreSQL server ...pg_isready -h localhost 1>nul 2>nul@if "%ERRORLEVEL%" == "0" ( net stop pgsql_srv)pg_ctl unregister -N pgsql_srv@if "%ERRORLEVEL%" == "0" echo Unregister PostgreSQL successfully:my_ends