postgres 数据库备份和恢复 (保证pg_dump的命令是全局的)

  • window
set pgpassword=密码
pg_dump -h 主机 -p 端口 -U 用户 -d 数据库 -t 表 -a > 文件地址  (只备份数据)
pg_dump -h 主机 -p 端口 -U 用户 -d 数据库 -t 表 -a > 文件地址 --column-inserts (只备份数据)


运行,CMD命令控制台,CD进入postgres 安装的根,查找BIN目录,如下图:

下一步,再执行以下命令:

备份
pg_dump -h localhost -U postgres tt > d:/the_backup.sql


恢复:
psql -h localhost -U postgres -p 5432 data < d:/cc.sql
  • linux
export pgpassword=密码
pg_dump -h 主机 -p 端口 -U 用户 -d 数据库 -t 表 -a > 文件地址  (只备份数据)
pg_dump -h 主机 -p 端口 -U 用户 -d 数据库 -t 表 -a > 文件地址 --column-inserts (只备份数据)
原文地址:https://www.cnblogs.com/Fooo/p/13275234.html