今天用pg_dump 备份greenplum 数据库的ddl 的时候,遇到一个其他的错误,记录一下。
执行备份命令:
[gpadmin@gpmdw tmp]$ pg_dump -Fp --gp-syntax -s -f ./pgdump_output.sql testdb1 pg_dump: query to obtain distribution policy of table "dim_org" returned no data
使用-v 参数,查看详细出错信息,重新执行
[gpadmin@gpmdw tmp]$ pg_dump -Fp --gp-syntax -v -s -f ./pgdump_output.sql testdb1 20171121:18:43:37|pg_dump-[INFO]:-reading schemas 20171121:18:43:37|pg_dump-[INFO]:-reading user-defined functions 20171121:18:43:37|pg_dump-[INFO]:-reading user-defined types ..... 20171121:18:43:37|pg_dump-[INFO]:-reading constraints 20171121:18:43:37|pg_dump-[INFO]:-reading triggers pg_dump: reading dependency data pg_dump: saving encoding = UTF8 pg_dump: saving standard_conforming_strings = off pg_dump: saving database definition pg_dump: query to obtain distribution policy of table "dim_org" returned no data pg_dump: *** aborted because of error [gpadmin@gpmdw tmp]$
开始怀疑是dim_org 这张表有问题,经过检查,dim_org 很正常,没有任何问题;
testdb1=# d public.dim_org Table "public.dim_org" Column | Type | Modifiers --------+------------------------+----------- orgid | integer | name | character varying(100) | Distributed by: (orgid) testdb1=#
后来再检查数据库日志,发现 pg_dump 是执行如下SQL来查询表的表的分布键的:
SELECT attrnums from pg_namespace as n, pg_class as c, gp_distribution_policy as p WHERE c.relname = 'dim_org' AND n.nspname='public' AND c.relnamespace=n.oid AND c.oid = p.localoid;
而我的数据库testdb1 存在一张测试表 public.pg_class, 里面的数据为空,导致上面的SQL执行结果为空。所以报错退出;
把public.pg_class 修改为public.pg_class2 之后,重新执行pg_dump ,可以正常备份了。
以后还是不要再public 下创建和系统表同名的表了,这个问题又搞了一个上午。