如何解决Greenplum master node与seg node元数据不一致,greenplumseg


作为分布式数据库,Greenplum的元数据经常(是真的,经常遇到)会出现些错误,典型的一个是master node与seg node元数据不一致,本文结合一个具体错误,介绍下解决的办法。

现象

使用gpcheckcat -p 5432 databasename检查数据库时,将报出类似如下的输出:

Relation oid: 12345678
Relation name: ns1.table1

    Name of test which found this issue: missing_extraneous_pg_class
    Name of test which found this issue: missing_extraneous_pg_attribute
    Name of test which found this issue: missing_extraneous_pg_type
        Missing relation metadata for {'oid':12345678} on master (mdw:5432) seg65 (sdw20:40000) seg66 (sdw20:40001) seg67 (sdw20:40002) seg68 (sdw20:40003) seg69 (sdw21:40000) seg70 (sdw21:40001) seg71 (sdw21:40002) seg72 (sdw21:40003) seg73 (sdw22:40000) seg74 (sdw22:40001) seg75 (sdw22:40002) seg76 (sdw22:40003) seg77 (sdw23:40000) seg78 (sdw23:40001) seg79 (sdw23:40002) seg80 (sdw23:40003) seg81 (sdw24:40000) seg82 (sdw24:40001) seg83 (sdw24:40002) seg84 (sdw24:40003) seg85 (sdw25:40000) seg86 (sdw25:40001) seg87 (sdw25:40002) seg88 (sdw25:40003) 

分析

这个错误表示在master node以及错误中指出24个seg node(查询gp_segment_configuration元数据表会发现这些seg node都是primary node)中都已经没有了ns1.table1(relname=table1,oid=12345678)这个表的定义,也就是说pg_class,pg_attribute,pg_type这些元数据表都已经没有了此relation的定义。此时,尝试在master上drop ns1.table1会发现没有这个表。但是,剩余的seg node上仍然存在这个relation的定义。可以通过查询gp_segment_configuration找到剩余segment node。

解决

基本思路当然就是将残余的表定义drop掉。首先,需要从gp_segment_configuration中查到所有没在错误中列出的primary segment node的hostname和node;然后,分别登陆到这些segment node上drop掉ns1.table1。具体过程如下:

  • root登陆master host
  • 切换到Greenplum的管理员用户,比如gpadmin:
su - gpadmin
  • 查找所有primary segment node:
psql -d databasename -c "select hostname,port from gp_segment_configuration where role='p';"
  • 找到所有没在错误信息中列出的hostname+port,按照如下格式编写语句:
PGOPTIONS='-c gp_session_role=utility' psql -h hostname -p port  -d databasename -c 'drop table if exists ns1.table1;'
  • 在gpadmin用户下执行上一步生成的所有命令
  • 找到所有没在错误信息中列出的hostname+port,按照如下格式编写语句:
PGOPTIONS='-c gp_session_role=utility' psql -h hostname -p port  -d databasename -c 'select * from pg_class where oid=12345678;'
  • 在gpadmin用户下执行上一步生成的所有命令,确定每一条命令返回的都是0条记录

相关内容