PostgreSQL 註冊啟動 及 停用卸載 批處理指令碼

來源:互聯網
上載者:User

標籤:postgresql   批處理   啟動   停止   

註冊啟動 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


 停用卸載 pg_stop.bat:

@echo off
echo 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


 

PostgreSQL 註冊啟動 及 停用卸載 批處理指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.