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"

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...