微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Postgresql:命令备份与还原

逻辑备份与还原

pg_dump.exe逻辑备份

与pg_dump.exe输出备份之对应的还原

  • 何种输出就需要何种逆向操作,最终就是要获得标准的sql输入

pg_dump.exe的选项    pg_dump [选项]... [数据库名字]

  • pg_dump.exe --no-owner  --no-privileges  --create
  • pg_dump.exe --no-owner  --no-privileges  --create  --inserts

一般选项:
-f,--file=文件输出文件
-F,--format=c|t|p 输出文件格式 (定制,tar,明文)
-i,--ignore-version 当服务器的版本号与 pg_dump 的版本号不匹配时仍继续运行
-v,--verbose 详细模式
-Z,--compress=0-9 被压缩格式的压缩级别
--help 显示此帮助信息,然后退出
--version 输出版本信息,然后退出

控制输出内容选项:
-a,--data-only dump only the data,not the schema  --仅备份数据。用于还原的数据库和备份的数据库结构完全一致时!

-s,--schema-only dump only the schema,no data  --仅备份结构。用于生成结构脚本

-c,--clean clean (drop) schema prior to create  --重新生成目标表。和--create是不兼容选项。被还原的库应该存在!!
-C,--create include commands to create database in dump  --创建数据库,用于创建完全的备份。和--clean是不兼容选项。一般情况下,该选项不起作用!!

-O,--no-owner skip restoration of object ownershipin plain text format
-x,--no-privileges do not dump privileges (grant/revoke)

-t,--table=TABLE dump the named table(s) only
-T,--exclude-table=TABLE do NOT dump the named table(s)

-n,--schema=SCHEMA dump the named schema(s) only  --指定要导出的构架
-N,--exclude-schema=SCHEMA do NOT dump the named schema(s) --指定要排除的构架

-b,--blobs include large objects in dump
-d,--inserts dump data as INSERT commands,rather than copY
-D,--column-inserts dump data as INSERT commands with column names
-E,--encoding=ENCODING dump the data in encoding ENCODING


-o,--oids include OIDs in dump

-S,--superuser=NAME specify the superuser user name to use in plain text format


--disable-dollar-quoting disable dollar quoting,use sql standard quoting
--disable-triggers disable triggers during data-only restore
--use-set-session-authorization use SESSION AUTHORIZATION commands instead of ALTER OWNER commands to set ownership

联接选项:
-h,--host=主机名 数据库服务器的主机名或套接字目录
-p,--port=端口号 数据库服务器的端口号
-U,--username=名字 以指定的数据库用户联接
-W,--password 强制口令提示 (自动)

如果没有提供数据库名字,那么使用 PGDATABASE 环境变量
的数值.

恢复数据库实例amohpj

pg_restore.exe -hlocalhost -Upostgres -damohpj -v "C:\amohpj.dat"

原文地址:https://www.jb51.cc/postgresql/196427.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐