1.并行备份
pg_dump -Fd --gp-syntax -U gpadmin -p 5432 -h 172.19.0.2 -d postgres -j 4 -f /opt/greenplum/data/postgres_backup_$(date +%Y-%m-%d)
参数 含义
-Fd 使用 directory 格式(支持并行)
--gp-syntax 使用 Greenplum 特定语法(保留分布策略等)
-U gpadmin 指定连接用户
-p 5432 数据库端口
-h 172.19.0.2 数据库主机地址
-d postgres 要备份的数据库名
-j 4 使用 4 个并行任务进行备份(加快速度)
-f <dir> 指定输出目录(必须是一个目录,不是文件)
2.并行恢复
pg_restore -Fd -U gpadmin -p 5432 -h 172.19.0.2 -d postgres -c --if-exists -j 4 /opt/greenplum/data/postgres_backup_2025-07-03
3.参数详细解释
3.1通用选项 (General options)
参数 | 全称 | 含义 |
-f | --file=FILENAME | 指定输出文件或目录名 |
-F | `--format=c | c|d|t|p ,默认为d |
-j | --jobs=NUM | 并行任务数(用于快速导出大数据库) 只有 directory 格式(-Fd)才支持并行备份(即 -j 参数)。 |
-v | --verbose | 显示详细输出信息 |
-V | --version | 显示版本号并退出 |
-Z | --compress=0-9 | 设置压缩级别(仅适用于支持压缩的格式) |
--lock-wait-timeout=TIMEOUT | - | 表锁等待超时时间(避免长时间阻塞) |
--no-sync | - | 不等待数据写入磁盘(加快速度但有风险) |
3.2控制输出内容的选项 (Options controlling the output content)
参数 全称 含义
-a --data-only 只导出数据,不包括 schema(表结构)
-b --blobs 包含大对象(BLOBs)
-B --no-blobs 不包含大对象
-c --clean 在恢复前删除已有对象(DROP)
-C --create 导出中包含创建数据库的命令
-E --encoding=ENCODING 使用指定编码导出数据(如 UTF8)
-n --schema=PATTERN 只导出匹配的 schema(例如:-n public)
-N --exclude-schema=PATTERN 排除某些 schema
-O --no-owner 忽略对象所有权(在 plain 文本格式中使用)
-s --schema-only 只导出 schema,不包括数据
-S --superuser=NAME 指定超级用户名称(plain 格式中使用)
-t --table=PATTERN 只导出匹配的表(支持通配符)
-T --exclude-table=PATTERN 排除指定表
-x --no-privileges 不导出权限信息(GRANT/REVOKE)
--binary-upgrade - 仅供升级工具内部使用
--column-inserts - 数据以带列名的 INSERT 形式导出
--disable-dollar-quoting - 禁用美元符号引用,使用标准 SQL 引号
--disable-triggers - 数据恢复时不触发触发器(适用于 --data-only)
--enable-row-security - 启用行级安全策略(只导出当前用户可访问的数据)
--exclude-table-and-children=PATTERN - 不导出指定表及其子表(分区表)
--exclude-table-data=PATTERN - 不导出指定表的数据
--exclude-table-data-and-children=PATTERN - 不导出指定表及其子表的数据
--extra-float-digits=NUM - 控制浮点数精度
--if-exists - DROP 对象时加上 IF EXISTS
--inserts - 数据以 INSERT 语句形式导出(不是 COPY)
--load-via-partition-root - 通过主表加载分区数据
--no-comments - 不导出注释
--no-publications - 不导出 publication 信息
--no-security-labels - 不导出安全标签信息
--no-subscriptions - 不导出订阅信息
--no-synchronized-snapshots - 并行作业中不使用同步快照
--no-tablespaces - 不导出表空间分配信息
--no-unlogged-table-data - 不导出未记录日志的表数据
--on-conflict-do-nothing - INSERT 加上 ON CONFLICT DO NOTHING
--quote-all-identifiers - 所有标识符加引号(即使不是关键字)
--rows-per-insert=NROWS - 每个 INSERT 插入多少行(隐含 --inserts)
--section=SECTION - 只导出指定部分:<br>pre-data, data, post-data
--serializable-deferrable - 保证 dump 能在可串行化事务中运行
--snapshot=SNAPSHOT - 使用指定快照进行导出
--strict-names - 要求 schema/table 模式必须匹配至少一个对象
--table-and-children=PATTERN - 只导出指定表及其子表
--use-set-session-authorization - 使用 SET SESSION AUTHORIZATION 而非 ALTER OWNER
--gp-syntax - 使用 Greenplum 语法导出(默认如果是 gpdb)
--no-gp-syntax - 不使用 Greenplum 语法(默认是 PostgreSQL)
--function-oids - 只导出指定 OIDs 的函数
--relation-oids - 只导出指定 OIDs 的关系(表等)
3.3连接选项 (Connection options)
参数 全称 含义
-d --dbname=DBNAME 要导出的数据库名称
-h --host=HOSTNAME 数据库服务器地址(IP 或主机名)
-p --port=PORT 数据库端口号
-U --username=NAME 连接数据库使用的用户名
-w --no-password 不提示输入密码
-W --password 强制提示输入密码
--role=ROLENAME - 在 dump 前执行 SET ROLE