PostgreSQL 备份与恢复

原创
2016/10/15 19:57
阅读数 877

使用PostgreSQL内建格式(custom格式)

/Library/PostgreSQL/9.6/bin/pg_dump --host localhost --port 5432 --username "postgres" --password  --format custom --blobs --encoding UTF8 --no-privileges --verbose --file "/home/my/dbname.backup" --schema "app" --schema "sys" "dbname"

 

使用sql格式(plain格式)

/Library/PostgreSQL/9.6/bin/pg_dump --host localhost --port 5432 --username "postgres" --no-password  --format plain --no-owner --encoding UTF8 --inserts --column-inserts --no-privileges --verbose --file "/home/my/dbname.sql" --schema "app" --schema "sys" "dbname"

 

恢复数据库(custom格式)

#覆盖已有的数据,
pg_restore --host localhost --port 5432 --username "db_user" --dbname "db_name" --password  --no-owner --no-privileges --clean --verbose "/home/my/dbname.backup"

#新建数据库
pg_restore --host localhost --port 5432 --username "db_user" --dbname "db_name" --password  --no-owner --no-privileges  --verbose "/home/my/dbname.backup"

#差别在于是否有 --clean

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
2 收藏
0
分享
返回顶部
顶部