加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL 注册启动 及 停用卸载 批处理脚本

发布时间:2020-12-13 17:23:19 所属栏目:百科 来源:网络整理
导读:注册启动 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

注册启动 pg_install.bat:

echo off
set PGSQL_DIR=%~dp0

if 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=chinese
	rem @if not "%ERRORLEVEL%" == "0" (
	rem There ERRORLEVEL is 2,but successfully inited
	rem 	echo PostgreSQL initdb failed.
	rem 	goto pg_ends
	rem )
) 

pg_ctl register --pgdata=%PGSQL_HOME%data -N pgsql_srv -S demand
net start pgsql_srv
rem pg_ctl -w start

pg_isready -h localhost 1>nul 2>nul
@if "%ERRORLEVEL%" == "0" (
	echo PostgreSQL server started successfully
) else (
	echo Failed to start PostgreSQL server
)

:pg_ends

cmd /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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读