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

PostgreSQL 备份与恢复

发布时间:2020-12-13 18:11:27 所属栏目:百科 来源:网络整理
导读:使用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" --sche

使用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

(编辑:李大同)

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

    推荐文章
      热点阅读