Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ajaxsys/3a21d676516cc358308c480f095cc65c to your computer and use it in GitHub Desktop.

Select an option

Save ajaxsys/3a21d676516cc358308c480f095cc65c to your computer and use it in GitHub Desktop.

Revisions

  1. ajaxsys revised this gist May 15, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions windows下,操作zip版postgres常用命令
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    REM windows下,操作zip版postgres常用命令。参数的意义请参照官方文档
    REM zip版postgres下载地址:https://www.enterprisedb.com/download-postgresql-binaries

    REM 设置为postgres zip版本解压缩路径<path_to_pgsql>
    set PG_HOME=<path_to_pgsql>
  2. ajaxsys created this gist May 15, 2019.
    34 changes: 34 additions & 0 deletions windows下,操作zip版postgres常用命令
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    REM windows下,操作zip版postgres常用命令。参数的意义请参照官方文档

    REM 设置为postgres zip版本解压缩路径<path_to_pgsql>
    set PG_HOME=<path_to_pgsql>
    cd %PG_HOME%

    REM 自定义数据库保存文件夹
    mkdir data

    REM 初始化数据库服务,用户名postgres,密码postgres(推荐输入)
    bin\initdb -U postgres -A password -E utf8 -W -D .\data

    REM 启动数据库服务
    bin\pg_ctl -o "-F -p 5432" -D ".\data" start


    REM 自定义数据库名:<db_name>
    set DB_NAME=<db_name>
    bin\createdb -E UTF-8 -O postgres -U postgres %DB_NAME%

    REM 至此数据库<db_name>已经可以通过用户postgres密码postgres访问了


    REM 其他功能 REM

    REM 备份数据库,把数据库<db_name>输出为一个备份文件<db_name>.backup
    bin\pg_dump -h 127.0.0.1 -p 5432 -U postgres --file=%DB_NAME%.backup -Ft -b %DB_NAME%

    REM 恢复备份数据库
    bin\pg_restore -h 127.0.0.1 -p 5432 -U postgres -d <db_name> --file=<db_name>.backup

    REM 删除数据库
    bin\dropdb -U postgres %DB_NAME%