Handling dropped attributes in pglogical_proto

From: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Handling dropped attributes in pglogical_proto
Date: 2016-09-28 14:25:12
Message-ID: 57EBD2C8.1060202@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

pglogical_read_tuple from pglogical_proto.c contains the following code:

natts = pq_getmsgint(in, 2);
if (rel->natts != natts)
elog(ERROR, "tuple natts mismatch, %u vs %u", rel->natts, natts);

But if table was just altered and some attribute was removed from the
table, then rel->natts can be greater than natts.
The problem can be fixed by the following patch:

--- a/pglogical_proto.c
+++ b/pglogical_proto.c
@@ -263,10 +263,15 @@ pglogical_read_tuple(StringInfo in, PGLogicalRelation *rel,
{
int attid = rel->attmap[i];
Form_pg_attribute att = desc->attrs[attid];
- char kind = pq_getmsgbyte(in);
+ char kind;
const char *data;
int len;

+ if (att->atttypid == InvalidOid) {
+ continue;
+ }
+ kind = pq_getmsgbyte(in);
+
switch (kind)
{
case 'n': /* null */

--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2016-09-28 15:05:41 Re: Tuplesort merge pre-reading
Previous Message Robert Haas 2016-09-28 14:22:53 Re: psql casts aspersions on server reliability