Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ajaxsys/3a21d676516cc358308c480f095cc65c to your computer and use it in GitHub Desktop.
Save ajaxsys/3a21d676516cc358308c480f095cc65c to your computer and use it in GitHub Desktop.
zip_postgres_usefule_cmd.cmd
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>
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%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment