GreenPlum 大数据平台--非并行备份(六)

2022-12-15,,,,

一,非并行备份(pg_dump)

  1) GP依然支持常规的PostgreSQL备份命令pg_dump和pg_dumpall
  2) 备份将在Master主机上创建一个包含所有Segment数据的大的备份文件
  3) 不适合于全部数据备份,适用于小部分数据的迁移或备份

  pg_dump是用于备份数据库的标准PostgreSQL实用程序,在Greenplum数据库中也受支持。它创建一个(非并行)转储文件。对于Greenplum数据库的常规备份,最好使用Greenplum Database备份实用程序gpcrondump以获得最佳性能。

  如果要将数据迁移到其他数据库供应商的系统,或者使用具有不同段配置的另一个Greenplum
Database系统(例如,如果要迁移到的系统具有更多或更少的段实例),请使用pg_dump。要还原,必须使用相应的pg_restore实用程序(如果转储文件采用存档格式),或者可以使用客户端程序(如psql)(如果转储文件采用纯文本格式)。

  由于pg_dump与常规PostgreSQL兼容,因此可用于将数据迁移到Greenplum数据库。 Greenplum数据库中的pg_dump实用程序与PostgreSQL pg_dump实用程序非常相似,但有以下例外和限制:

  如果使用pg_dump备份Greenplum数据库数据库,请记住,对于非常大的数据库,转储操作可能需要很长时间(几个小时)。此外,您必须确保有足够的磁盘空间来创建转储文件。

  如果要将数据从一个Greenplum数据库系统迁移到另一个,请使用--gp-syntax命令行选项在CREATE
TABLE语句中包含DISTRIBUTED BY子句。这可确保Greenplum Database表数据在还原时与正确的分发键列一起分发。

  即使同时使用数据库,pg_dump也会进行一致的备份。 pg_dump不会阻止访问数据库的其他用户(读者或编写者)。

  当与其中一种存档文件格式一起使用并与pg_restore结合使用时,pg_dump提供了灵活的存档和传输机制。
pg_dump可用于备份整个数据库,然后pg_restore可用于检查存档和/或选择要还原数据库的哪些部分。最灵活的输出文件格式是自定义格式(-Fc)。它允许选择和重新排序所有已归档项目,并在默认情况下进行压缩。
tar格式(-Ft)未压缩,加载时无法重新排序数据,但在其他方面非常灵活。它可以使用标准的UNIX工具(如tar)进行操作

  参数:

 [gpadmin@greenplum01 ~]$ pg_dump --help
pg_dump dumps a database as a text file or to other formats. Usage:
pg_dump [OPTION]... [DBNAME] General options:
-f, --file=FILENAME output file name
-F, --format=c|t|p output file format (custom, tar, plain text)
-i, --ignore-version proceed even when server version mismatches
pg_dump version
-v, --verbose verbose mode
-Z, --compress=- compression level for compressed formats
--help show this help, then exit
--version output version information, then exit Options controlling the output content:
-a, --data-only dump only the data, not the schema
-b, --blobs include large objects in dump
-c, --clean clean (drop) schema prior to create
-C, --create include commands to create database in dump
-d, --inserts dump data as INSERT, rather than COPY, commands
-D, --column-inserts dump data as INSERT commands with column names
-E, --encoding=ENCODING dump the data in encoding ENCODING
-n, --schema=SCHEMA dump the named schema(s) only
-N, --exclude-schema=SCHEMA do NOT dump the named schema(s)
-o, --oids include OIDs in dump
-O, --no-owner skip restoration of object ownership
in plain text format
-s, --schema-only dump only the schema, no data
-S, --superuser=NAME specify the superuser user name to use in
plain text format
-t, --table=TABLE dump only matching table(s) (or views or sequences)
-T, --exclude-table=TABLE do NOT dump matching table(s) (or views or sequences)
-x, --no-privileges do not dump privileges (grant/revoke)
--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
--gp-syntax dump with Greenplum Database syntax (default if gpdb)
--no-gp-syntax dump without Greenplum Database syntax (default if postgresql)
--function-oids dump only function(s) of given list of oids
--relation-oids dump only relation(s) of given list of oids Connection options:
-h, --host=HOSTNAME database server host or socket directory
-p, --port=PORT database server port number
-U, --username=NAME connect as specified database user
-W, --password force password prompt (should happen automatically) If no database name is supplied, then the PGDATABASE environment
variable value is used. Report bugs to <bugs@greenplum.org>.

实例:

. 只导出postgres数据库的数据,不包括模式 -s

   pg_dump -U gpadmin -f /postgres.sql -s postgres(数据库名)

. 导出postgres数据库(包括数据)

   pg_dump -U gpadmin -f /postgres.sql  postgres(数据库名)

. 导出postgres数据库中表test01的数据

   create database "test1" with owner="gpadmin" encoding='utf-8';(单引号,双引号不能错)

   pg_dump -U gpadmin -f /postgres.sql -t test1 postgres(数据库名)

. 导出postgres数据库中表test1的数据,以insert语句的形式

   pg_dump -U gpadmin -f /postgres.sql -t test1 --column-inserts postgres(数据库名)

. 恢复数据到gpdb数据库

  psql -U gpadmin -f /postgres.sql gpdb

二,操作指南

  备份1:

[gpadmin@greenplum01 ~]$ pg_dump -U gpadmin -F t -f /gpbackup/back2/gpdb.tar gpdb
[gpadmin@greenplum01 ~]$

  恢复:

[gpadmin@greenplum01 ~]$ pg_restore -U gpadmin -d gpdb /gpdb.tar
[gpadmin@greenplum01 ~]$

  备份2:

[gpadmin@greenplum01 ~]$ pg_dump -U gpadmin -F c -f /gpbackup/back2/gpdb.tar gpdb

  备份压缩1:

[gpadmin@greenplum01 ~]$ pg_dump -U gpadmin gpdb | gzip > /gpbackup/back2/gpdb.gz
[gpadmin@greenplum01 ~]$

  恢复

 gunzip -c /gpdb.gz | psql -U gpadmin postgres
cat /gpdb.gz | gunzip | psql -U gpadmin postgres

  备份切割:

 pg_dump -U gpadmin -d gpdb | split -b 100k - gpback/gpb

  恢复:

cat /gpback/gpb* | psql -U gpadmin postgres

  

 

 
 

GreenPlum 大数据平台--非并行备份(六)的相关教程结束。

《GreenPlum 大数据平台--非并行备份(六).doc》

下载本文的Word格式文档,以方便收藏与打印。