greenplum集群中 插入序列报错处理

    xiaoxiao2026-08-29  3

    自增ID,是数据库中一个重要的功能,在Oracle和postgresql数据库中,自增ID主要都是通过 序列实现的。 Greenplum数据库,是基于postgresql实现的MPP数据库集群,其中也可以基于序列 实现自增ID的功能。 但在在近段时间使用时,就遇到一个错误: 创建一个包含自增ID的表,建表sql如下:

    CREATE TABLE customers ( customerid SERIAL primary key , companyname character varying, contactname character varying, phone character varying, country character varying ) ;

    执行insert操作,insert的sql如下:  insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1');

    结果在执行过程中,遇到一个问题:

    testDB=# testDB=# CREATE TABLE customers testDB-# ( testDB(# customerid SERIAL primary key , testDB(# companyname character varying, testDB(# contactname character varying, testDB(# phone character varying, testDB(# country character varying testDB(# ) ; NOTICE: CREATE TABLE will create implicit sequence "customers_customerid_seq" for serial column "customers.customerid" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "customers_pkey" for table "customers" CREATE TABLE testDB=# testDB=# testDB=# insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1'); ERROR: Interconnect Error: Could not connect to seqserver (connection: 11, host: 127.0.0.1, port: 51380). (seg0 slice1 tk-dat-asa201:40000 pid=29853) DETAIL: Connection refused (connect errno 111) testDB=#

    这个问题非常奇怪,在Greenplum集群中,创建和查询序列没有问题,但在插入时就会报错。 而且提示的错误是,不能连接到序列服务器, 但实际上通过下面的命令,是可以连接到序列服务器的segment节点:

    PGOPTIONS='-c gp_session_role=utility' psql -p 40000

    在这种连接方式下,执行任何序列的添删改查操作,都是没有问题的。 自己找了一段时间原因后,和别人沟通,确定原因根据报错提示,应该还是网络解析的问题,于是在各个节点上,依次进行自己主机和其他主机的ping命令,确认IP是多少。 connection: 11, host: 127.0.0.1, port: 51380 这个说明是 集群中两个主机之间网络不通的问题;根据提示,直接怀疑是网络DNS解析问题,造成访问拒绝。 数据库之间连通,不应该是通过 127.0.0.1 地址的; 但在自己的主机上ping时,发现IP是这样的:

    [root@mc-data-asa211 ~]# ping mc-data-asa211 PING mc-data-asa211 (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.077 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.043 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.037 ms 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.037 ms 64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.037 ms

    所有将 /etc/hosts 中的这个IP注释关闭:

    vim /etc/hosts [root@mc-data-asa211 ~]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 #127.0.0.1 mc-data-asa211 ## 注释掉,不然有的情况下,会导致Greenplum报错 192.168.3.201 mc-data-asa211

    修改之后,ping本机的IP地址:

    [root@mc-data-asa211 ~]# ping mc-data-asa211 PING mc-data-asa211 (192.168.3.201) 56(84) bytes of data. 64 bytes from mc-data-asa211 (192.168.3.201): icmp_seq=1 ttl=64 time=0.054 ms 64 bytes from mc-data-asa211 (192.168.3.201): icmp_seq=2 ttl=64 time=0.036 ms

    这样再执行序列插入操作,就没有任何问题了:

    testDB=# select * from customers; customerid | companyname | contactname | phone | country ------------+-------------+-------------+-------+--------- (0 rows) testDB=# testDB=# testDB=# insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1'); INSERT 0 1 testDB=# insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1'); INSERT 0 1 testDB=# insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1'); INSERT 0 1 testDB=# insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1'); INSERT 0 1 testDB=# insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1'); INSERT 0 1 testDB=# insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1'); INSERT 0 1 testDB=# insert into customers(companyname,contactname,phone,country) values('a1','b1','c1','d1'); INSERT 0 1 testDB=# testDB=# select * from customers; customerid | companyname | contactname | phone | country ------------+-------------+-------------+-------+--------- 6 | a1 | b1 | c1 | d1 4 | a1 | b1 | c1 | d1 5 | a1 | b1 | c1 | d1 7 | a1 | b1 | c1 | d1 3 | a1 | b1 | c1 | d1 1 | a1 | b1 | c1 | d1 2 | a1 | b1 | c1 | d1 (7 rows)

    通过这个问题发现,Greenplum集群,有很多内部网络通信,对于 /etc/hosts , iptables 等网络配置一定要非常谨慎,不要有多余信息,否则会有各种奇怪问题。

    转载请注明原文地址: https://ju.6miu.com/read-1311680.html
    最新回复(0)