标签:大数据 greenplum pg-dump 分布键 元数据
Greenplum的元数据错误也会影响到数据备份过程,在使用pg_dump进行数据结构备份时,会由于分布策略的缺失导致备份失败,本文介绍此错误的解决办法。
使用pg_dump命令备份整个Greenplum数据库的数据结构时:
pg_dump -f /data/dailybak/dw-nodata-$(date +%Y%m%d%H%M%S) -v -F c -p 5432 -h masterhostname -C -d databasename -s
报出如下错误后,备份进程终止:
pg_dump: query to obtain distribution policy of table "table1" returned no data
出现此错误后,从pg_class元数据表中找到此relation的oid:
psql databasename -c "select oid,* from pg_class where relname=‘table1‘;"
假定输出的oid为1234,relnamespace为5678,如果有多条,就逐条处理,从gp_distribution_policy中查找localoid为此oid的记录:
psql databasename -c "select oid,* from gp_distribution_policy where localoid=1234;"
此查询应返回0条记录,从pg_namespace中找到此表所属namespace名称:
psql databasename -c "select * from pg_namespace where oid=5678;"
假定nspname为ns1,至此,证明ns1.table1没有分布策略,因此备份失败
基本思路是为ns1.table1设置分布策略:
su - gpadmin
psql databasename
alter table ns1.table1 set distributed randomly;
或者设置指定列为分布依据
databasename=# alter table ns1.table1 set distributed by (column1);
如果此修改报错:
ERROR: SET DISTRIBUTED BY not supported on non-distributed tables
则放弃下一步重分布,drop掉ns1.table1重建吧
databasename=# alter table ns1.table1 set with(reorganize=true);
databasename=# \d ns1.table1
应返回表的基本信息
databasename=# select oid,* from pg_class where relname=‘table1‘;
如重建过,假定返回的oid为12345,否则就是1234
databasename=# select oid,* from gp_distribution_policy where localoid=12345;
应返回这个表的分布策略
databasename=# select relname from pg_class where relnamespace=5678 and oid not in (select localoid from gp_distribution_policy);
附送两个pg_dump的其他问题:
pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: column c.oid does not exist
LINE 1: ...spname=‘dataservice‘ AND c.relnamespace=n.oid AND c.oid = p....
^
pg_dump: The command was: SELECT attrnums from pg_namespace as n, pg_class as c, gp_distribution_policy as p WHERE c.relname = ‘table1‘ AND n.nspname=‘ns1‘ AND c.relnamespace=n.oid AND c.oid = p.localoid
pg_dump: *** aborted because of error
pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: relation "ns1.table1" does not exist
pg_dump: The command was: LOCK TABLE ns1.table1IN ACCESS SHARE MODE
pg_dump: *** aborted because of error
如何解决Greenplum中用pg_dump备份数据结构时的分布策略缺失等三个问题
标签:大数据 greenplum pg-dump 分布键 元数据
原文地址:http://blog.csdn.net/cloudguru/article/details/45718535