pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
logical replication - negative bitmapset member not allowed
20+ messages / 6 participants
[nested] [flat]

Commits from this thread:
  2019-11-09 1c60e40ad5 d891d2c897 7961da1887 2e00d59764  Fix negative bitmapset member not allowed error in logical replication
* logical replication - negative bitmapset member not allowed
@ 2019-04-01 13:36  Tim Clarke <tim.clarke@minerva.info>
  0 siblings, 1 reply; 20+ messages in thread

From: Tim Clarke @ 2019-04-01 13:36 UTC (permalink / raw)
  To: pgsql-general

I'm getting this message every 5 seconds on a single-master,
single-slave replication of PG10.7->PG10.7 both on Centos. Its over the
'net but otherwise seems to perform excellently. Any ideas what's
causing it and how to fix?

--
Tim Clarke
IT Director
Direct: +44 (0)1376 504510 | Mobile: +44 (0)7887 563420



Main: +44 (0)1376 503500 | Fax: +44 (0)1376 503550
Web: https://www.manifest.co.uk/



Minerva Analytics Ltd
9 Freebournes Court | Newland Street | Witham | Essex | CM8 2BL | England

----------------------------------------------------------------------------------------------------------------------------

Copyright: This e-mail may contain confidential or legally privileged information. If you are not the named addressee you must not use or disclose such information, instead please report it to admin@minerva.info<mailto:admin@minerva.info>
Legal:  Minerva Analytics is the trading name of: Minerva Analytics
Ltd: Registered in England Number 11260966 & The Manifest Voting Agency Ltd: Registered in England Number 2920820 Registered Office at above address. Please Click Here >><https://www.manifest.co.uk/legal/; for further information.


^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-01 14:02  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Tim Clarke <tim.clarke@minerva.info>
  0 siblings, 2 replies; 20+ messages in thread

From: Tom Lane @ 2019-04-01 14:02 UTC (permalink / raw)
  To: Tim Clarke <tim.clarke@minerva.info>; +Cc: pgsql-general

Tim Clarke <tim.clarke@minerva.info> writes:
> I'm getting this message every 5 seconds on a single-master,
> single-slave replication of PG10.7->PG10.7 both on Centos. Its over the
> 'net but otherwise seems to perform excellently. Any ideas what's
> causing it and how to fix?

That'd certainly be a bug, but we'd need to reproduce it to fix it.
What are you doing that's different from everybody else?  Can you
provide any other info to narrow down the problem?

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-01 14:53  Tim Clarke <tim.clarke@minerva.info>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 20+ messages in thread

From: Tim Clarke @ 2019-04-01 14:53 UTC (permalink / raw)
  To: pgsql-general

Dang. I just replicated ~380 tables. One was missing an index so I
paused replication, added a unique key on publisher and subscriber,
re-enabled replication and refreshed the subscription.

The table has only 7 columns, I added a primary key with a default value
from a new sequence.

Tim Clarke
IT Director
Direct: +44 (0)1376 504510 | Mobile: +44 (0)7887 563420

On 01/04/2019 15:02, Tom Lane wrote:
> Tim Clarke <tim.clarke@minerva.info> writes:
>> I'm getting this message every 5 seconds on a single-master,
>> single-slave replication of PG10.7->PG10.7 both on Centos. Its over the
>> 'net but otherwise seems to perform excellently. Any ideas what's
>> causing it and how to fix?
> That'd certainly be a bug, but we'd need to reproduce it to fix it.
> What are you doing that's different from everybody else?  Can you
> provide any other info to narrow down the problem?
>
> regards, tom lane


Main: +44 (0)1376 503500 | Fax: +44 (0)1376 503550
Web: https://www.manifest.co.uk/



Minerva Analytics Ltd
9 Freebournes Court | Newland Street | Witham | Essex | CM8 2BL | England

----------------------------------------------------------------------------------------------------------------------------

Copyright: This e-mail may contain confidential or legally privileged information. If you are not the named addressee you must not use or disclose such information, instead please report it to admin@minerva.info<mailto:admin@minerva.info>
Legal:  Minerva Analytics is the trading name of: Minerva Analytics
Ltd: Registered in England Number 11260966 & The Manifest Voting Agency Ltd: Registered in England Number 2920820 Registered Office at above address. Please Click Here >><https://www.manifest.co.uk/legal/; for further information.


^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-01 21:43  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 20+ messages in thread

From: Alvaro Herrera @ 2019-04-01 21:43 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On 2019-Apr-01, Tom Lane wrote:

> Tim Clarke <tim.clarke@minerva.info> writes:
> > I'm getting this message every 5 seconds on a single-master,
> > single-slave replication of PG10.7->PG10.7 both on Centos. Its over the
> > 'net but otherwise seems to perform excellently. Any ideas what's
> > causing it and how to fix?
> 
> That'd certainly be a bug, but we'd need to reproduce it to fix it.
> What are you doing that's different from everybody else?  Can you
> provide any other info to narrow down the problem?

Maybe the replica identity of a table got set to a unique index on oid?
Or something else involving system columns?  (If replication is
otherwise working, the I suppose there's a separate publication that's
having the error; the first thing to isolate would be to see what tables
are involved in that publication).

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-02 13:59  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Tim Clarke <tim.clarke@minerva.info>
  0 siblings, 1 reply; 20+ messages in thread

From: Tom Lane @ 2019-04-02 13:59 UTC (permalink / raw)
  To: Tim Clarke <tim.clarke@minerva.info>; +Cc: pgsql-general

Tim Clarke <tim.clarke@minerva.info> writes:
> Dang. I just replicated ~380 tables. One was missing an index so I
> paused replication, added a unique key on publisher and subscriber,
> re-enabled replication and refreshed the subscription.

Well, that's not much help :-(.  Can you provide any info to narrow
down where this is happening?  I mean, you haven't even told us whether
it's the primary or the slave that is complaining.  Does it seem to
be associated with any particular command?  (Turning on log_statement
and/or log_replication_commands would likely help with that.)  Does
data seem to be getting transferred despite the complaint?  If not,
what's missing on the slave?

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-02 14:26  Tim Clarke <tim.clarke@minerva.info>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 20+ messages in thread

From: Tim Clarke @ 2019-04-02 14:26 UTC (permalink / raw)
  To: pgsql-general

On 02/04/2019 14:59, Tom Lane wrote:
> Well, that's not much help :-(.  Can you provide any info to narrow
> down where this is happening?  I mean, you haven't even told us whether
> it's the primary or the slave that is complaining.  Does it seem to
> be associated with any particular command?  (Turning on log_statement
> and/or log_replication_commands would likely help with that.)  Does
> data seem to be getting transferred despite the complaint?  If not,
> what's missing on the slave?
>
> regards, tom lane


I've been working to narrow it, the error is being reported on the slave.

The only schema changes have been the two primary keys added to two
tables. The problem occurred during this cycle:

1) Replication proceeding fine for ~380 tables, all added individually
not "all tables".

2) Add primary key on master.

3) Add primary key on slave.

4) Refresh subscription on slave; error starts being reported.

I've cleared it by dropping the slave database, re-creating from the
live schema then fully replicating. Its all running happily now.


Tim Clarke



Main: +44 (0)1376 503500 | Fax: +44 (0)1376 503550
Web: https://www.manifest.co.uk/



Minerva Analytics Ltd
9 Freebournes Court | Newland Street | Witham | Essex | CM8 2BL | England

----------------------------------------------------------------------------------------------------------------------------

Copyright: This e-mail may contain confidential or legally privileged information. If you are not the named addressee you must not use or disclose such information, instead please report it to admin@minerva.info<mailto:admin@minerva.info>
Legal:  Minerva Analytics is the trading name of: Minerva Analytics
Ltd: Registered in England Number 11260966 & The Manifest Voting Agency Ltd: Registered in England Number 2920820 Registered Office at above address. Please Click Here >><https://www.manifest.co.uk/legal/; for further information.


^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-02 14:46  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Tim Clarke <tim.clarke@minerva.info>
  0 siblings, 1 reply; 20+ messages in thread

From: Tom Lane @ 2019-04-02 14:46 UTC (permalink / raw)
  To: Tim Clarke <tim.clarke@minerva.info>; +Cc: pgsql-general

Tim Clarke <tim.clarke@minerva.info> writes:
> I've cleared it by dropping the slave database, re-creating from the
> live schema then fully replicating. Its all running happily now.

I'm glad you're out of the woods, but we still have a bug there
waiting to bite the next person.  I wonder if you'd be willing to
spend some time trying to develop a reproduction sequence for this
(obviously, working on a test setup not your live servers).
Presumably there's something in the subscription-alteration logic
that needs work, but I don't think we have enough detail here for
somebody else to reproduce the error without a lot of guesswork.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-02 15:04  Tim Clarke <tim.clarke@minerva.info>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 20+ messages in thread

From: Tim Clarke @ 2019-04-02 15:04 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

On 02/04/2019 15:46, Tom Lane wrote:
> I'm glad you're out of the woods, but we still have a bug there
> waiting to bite the next person.  I wonder if you'd be willing to
> spend some time trying to develop a reproduction sequence for this
> (obviously, working on a test setup not your live servers).
> Presumably there's something in the subscription-alteration logic
> that needs work, but I don't think we have enough detail here for
> somebody else to reproduce the error without a lot of guesswork.
>
> regards, tom lane


I'll do what I can :)


Tim Clarke



Main: +44 (0)1376 503500 | Fax: +44 (0)1376 503550
Web: https://www.manifest.co.uk/



Minerva Analytics Ltd
9 Freebournes Court | Newland Street | Witham | Essex | CM8 2BL | England

----------------------------------------------------------------------------------------------------------------------------

Copyright: This e-mail may contain confidential or legally privileged information. If you are not the named addressee you must not use or disclose such information, instead please report it to admin@minerva.info<mailto:admin@minerva.info>
Legal:  Minerva Analytics is the trading name of: Minerva Analytics
Ltd: Registered in England Number 11260966 & The Manifest Voting Agency Ltd: Registered in England Number 2920820 Registered Office at above address. Please Click Here >><https://www.manifest.co.uk/legal/; for further information.


^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-04 21:37  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 2 replies; 20+ messages in thread

From: Peter Eisentraut @ 2019-04-04 21:37 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On 2019-04-01 23:43, Alvaro Herrera wrote:
> Maybe the replica identity of a table got set to a unique index on oid?
> Or something else involving system columns?  (If replication is
> otherwise working, the I suppose there's a separate publication that's
> having the error; the first thing to isolate would be to see what tables
> are involved in that publication).

Looking through the code, the bms_add_member() call in
logicalrep_read_attrs() does not use the usual
FirstLowInvalidHeapAttributeNumber offset, so that seems like a possible
problem.

However, I can't quite reproduce this.  There are various other checks
that prevent this scenario, but it's plausible that with a bit of
whacking around you could hit this error message.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-04-04 22:05  Tim Clarke <tim.clarke@minerva.info>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  1 sibling, 0 replies; 20+ messages in thread

From: Tim Clarke @ 2019-04-04 22:05 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-general

On 04/04/2019 22:37, Peter Intrauterine wrote:
> On 2019-04-01 23:43, Alvaro Herrera wrote:
>> Maybe the replica identity of a table got set to a unique index on oid?
>> Or something else involving system columns?  (If replication is
>> otherwise working, the I suppose there's a separate publication that's
>> having the error; the first thing to isolate would be to see what tables
>> are involved in that publication).
> Looking through the code, the bms_add_member() call in
> logicalrep_read_attrs() does not use the usual
> FirstLowInvalidHeapAttributeNumber offset, so that seems like a possible
> problem.
>
> However, I can't quite reproduce this.  There are various other checks
> that prevent this scenario, but it's plausible that with a bit of
> whacking around you could hit this error message.
>

Promise I've not been whacking around......


Tim Clarke



Main: +44 (0)1376 503500 | Fax: +44 (0)1376 503550
Web: https://www.manifest.co.uk/



Minerva Analytics Ltd
9 Freebournes Court | Newland Street | Witham | Essex | CM8 2BL | England

----------------------------------------------------------------------------------------------------------------------------

Copyright: This e-mail may contain confidential or legally privileged information. If you are not the named addressee you must not use or disclose such information, instead please report it to admin@minerva.info<mailto:admin@minerva.info>
Legal:  Minerva Analytics is the trading name of: Minerva Analytics
Ltd: Registered in England Number 11260966 & The Manifest Voting Agency Ltd: Registered in England Number 2920820 Registered Office at above address. Please Click Here >><https://www.manifest.co.uk/legal/; for further information.


^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-10-10 13:15  Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  1 sibling, 1 reply; 20+ messages in thread

From: Jehan-Guillaume de Rorthais @ 2019-10-10 13:15 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

Hello,

On Thu, 4 Apr 2019 23:37:04 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

> On 2019-04-01 23:43, Alvaro Herrera wrote:
> > Maybe the replica identity of a table got set to a unique index on oid?
> > Or something else involving system columns?  (If replication is
> > otherwise working, the I suppose there's a separate publication that's
> > having the error; the first thing to isolate would be to see what tables
> > are involved in that publication).  
> 
> Looking through the code, the bms_add_member() call in
> logicalrep_read_attrs() does not use the usual
> FirstLowInvalidHeapAttributeNumber offset, so that seems like a possible
> problem.
> 
> However, I can't quite reproduce this.  There are various other checks
> that prevent this scenario, but it's plausible that with a bit of
> whacking around you could hit this error message.

Here is a script to reproduce it under version 10, 11 and 12:

################################################
# env
PUB=/tmp/pub
SUB=/tmp/sub
unset PGPORT PGHOST PGDATABASE PGDATA
export PGUSER=postgres

# cleanup
kill %1
pg_ctl -w -s -D "$PUB" -m immediate stop; echo $?
pg_ctl -w -s -D "$SUB" -m immediate stop; echo $?
rm -r "$PUB" "$SUB"

# cluster
initdb -U postgres -N "$PUB" &>/dev/null; echo $?
initdb -U postgres -N "$SUB" &>/dev/null; echo $?
echo "wal_level=logical" >> "$PUB"/postgresql.conf
echo "port=5433" >> "$SUB"/postgresql.conf
pg_ctl -w -s -D $PUB -l "$PUB"-"$(date +%FT%T)".log start; echo $?
pg_ctl -w -s -D $SUB -l "$SUB"-"$(date +%FT%T)".log start; echo $?
pgbench -p 5432 -qi 
pg_dump -p 5432 -s | psql -qXp 5433

# fake activity
pgbench -p 5432 -T 300 -c 2 &

# replication setup
psql -p 5432 -Xc "CREATE PUBLICATION prov FOR ALL TABLES"
psql -p 5433 -Xc "CREATE SUBSCRIPTION sub
                  CONNECTION 'port=5432'
                  PUBLICATION prov"

# wait for the streaming
unset V;
while [ "$V" != "streaming" ]; do sleep 1
    V=$(psql -AtXc "SELECT 'streaming'
                    FROM pg_stat_replication WHERE state='streaming'")
done

# trigger the error message
psql -p 5433 -Xc "ALTER SUBSCRIPTION sub DISABLE"
psql -p 5433 -Xc "ALTER TABLE pgbench_history ADD id SERIAL PRIMARY KEY"
psql -p 5432 -Xc "ALTER TABLE pgbench_history ADD id SERIAL PRIMARY KEY"
psql -p 5433 -Xc "ALTER SUBSCRIPTION sub ENABLE"
################################################

Regards,





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-10-25 15:38  Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  parent: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  0 siblings, 1 reply; 20+ messages in thread

From: Jehan-Guillaume de Rorthais @ 2019-10-25 15:38 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On Thu, 10 Oct 2019 15:15:46 +0200
Jehan-Guillaume de Rorthais <jgdr@dalibo.com> wrote:

[...]
> Here is a script to reproduce it under version 10, 11 and 12:

I investigated on this bug while coming back from pgconf.eu. Bellow what I found
so far.

The message "negative bitmapset member not allowed" comes from
logicalrep_rel_open().

Every field that are unknown, dropped or generated are mapped to remote attnum
-1. See backend/replication/logical/relation.c:

    if (attr->attisdropped || attr->attgenerated)
    {
        entry->attrmap[i] = -1;
        continue;
    }

    attnum = logicalrep_rel_att_by_name(remoterel, NameStr(attr->attname));

Note that logicalrep_rel_att_by_name returns -1 on unknown fields.

Later in the same function, we check if fields belonging to some PK or unique
index appears in remote keys as well:

    while ((i = bms_next_member(idkey, i)) >= 0)
    {
        [...]
        if (!bms_is_member(entry->attrmap[attnum], remoterel->attkeys))
        {
            entry->updatable = false;
            break;
        }
    }

However, before checking if the local attribute belong to the remote keys,
it should check if it actually mapped to a remote one. In other words, I
suppose we should check entry->attrmap[attnum] > 0 before calling
bms_is_member().

The trivial patch would be:

-        if (!bms_is_member(entry->attrmap[attnum], remoterel->attkeys))
+        if (entry->attrmap[attnum] < 0 ||
+            !bms_is_member(entry->attrmap[attnum], remoterel->attkeys))
         {
             entry->updatable = false;
             break;
         }

I tested with the attached scenario and it sound to work correctly.

Note that while trying to fix this bug, I found a segment fault while compiling
with asserts. You might want to review/test without --enable-cassert. I will
report in another thread as this seems not related to this bug or fix.

Attachments:

  negative_bitmap_error-fix.bash (application/octet-stream, 2.3K) download

^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-11-05 15:02  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  0 siblings, 2 replies; 20+ messages in thread

From: Peter Eisentraut @ 2019-11-05 15:02 UTC (permalink / raw)
  To: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On 2019-10-25 17:38, Jehan-Guillaume de Rorthais wrote:
> On Thu, 10 Oct 2019 15:15:46 +0200
> Jehan-Guillaume de Rorthais <jgdr@dalibo.com> wrote:
> 
> [...]
>> Here is a script to reproduce it under version 10, 11 and 12:
> 
> I investigated on this bug while coming back from pgconf.eu. Bellow what I found
> so far.

I have simplified your reproduction steps from the previous message to a 
test case, and I can confirm that your proposed fix addresses the issue. 
  A patch is attached.  Maybe someone can look it over.  I target next 
week's minor releases.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

  0001-Fix-negative-bitmapset-member-not-allowed-error-in-l.patch (text/plain, 0B) download

^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-11-05 16:05  Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  1 sibling, 1 reply; 20+ messages in thread

From: Jehan-Guillaume de Rorthais @ 2019-11-05 16:05 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On Tue, 5 Nov 2019 16:02:51 +0100
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

> On 2019-10-25 17:38, Jehan-Guillaume de Rorthais wrote:
> > On Thu, 10 Oct 2019 15:15:46 +0200
> > Jehan-Guillaume de Rorthais <jgdr@dalibo.com> wrote:
> > 
> > [...]
> >> Here is a script to reproduce it under version 10, 11 and 12:
> > 
> > I investigated on this bug while coming back from pgconf.eu. Bellow what I
> > found so far.
> 
> I have simplified your reproduction steps from the previous message to a 
> test case, and I can confirm that your proposed fix addresses the issue. 

Thanks for the feedback and the test case. I wonder if ALTER SUBSCRIPTION
DISABLE/ENABLE is useful in the test case?

Is it something recommended during DDL on logically replicated relation? If
yes, I suppose we should update the first point of the restriction chapter in
documentation:
https://www.postgresql.org/docs/11/logical-replication-restrictions

Regards,





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-11-05 16:18  Andres Freund <andres@anarazel.de>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  1 sibling, 1 reply; 20+ messages in thread

From: Andres Freund @ 2019-11-05 16:18 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>; Tom Lane <tgl@sss.pgh.pa.us>; Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

Hi,

On 2019-11-05 16:02:51 +0100, Peter Eisentraut wrote:
>  $node_publisher->stop('fast');
> +
> +
> +# TODO: https://www.postgresql.org/message-id/flat/a9139c29-7ddd-973b-aa7f-71fed9c38d75%40minerva.info
> +
> +$node_publisher = get_new_node('publisher3');
> +$node_publisher->init(allows_streaming => 'logical');
> +$node_publisher->start;
> +
> +$node_subscriber = get_new_node('subscriber3');
> +$node_subscriber->init(allows_streaming => 'logical');
> +$node_subscriber->start;

Do we really have to create a new subscriber for this test? The creation
of one isn't free. Nor is the amount of test code duplication
neglegible.

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-11-07 15:02  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  0 siblings, 1 reply; 20+ messages in thread

From: Peter Eisentraut @ 2019-11-07 15:02 UTC (permalink / raw)
  To: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On 2019-11-05 17:05, Jehan-Guillaume de Rorthais wrote:
>> I have simplified your reproduction steps from the previous message to a
>> test case, and I can confirm that your proposed fix addresses the issue.
> 
> Thanks for the feedback and the test case. I wonder if ALTER SUBSCRIPTION
> DISABLE/ENABLE is useful in the test case?

Turns out it's not necessary.  Attached is an updated patch that 
simplifies the test even further and moves it into the 
008_diff_schema.pl file.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Fix-negative-bitmapset-member-not-allowed-error-i.patch (text/plain, 4.0K) download From dcc12ec8315ecb8613190052d4f787cf0554e2c2 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Thu, 7 Nov 2019 13:48:59 +0100 Subject: [PATCH v2] Fix negative bitmapset member not allowed error in logical replication This happens when we add a replica identity column on a subscriber that does not yet exist on the publisher, according to the mapping maintained by the subscriber. Code that checks whether the target relation on the subscriber is updatable would check the replica identity attribute bitmap with a column number -1, which would result in an error. To fix, skip such columns in the bitmap lookup and consider the relation not updatable. The result is consistent with the rule that the replica identity columns on the subscriber must be a subset of those on the publisher, since if the column doesn't exist on the publisher, the column set on the subscriber can't be a subset. Reported-by: Tim Clarke <tim.clarke@minerva.info> Analyzed-by: Jehan-Guillaume de Rorthais <jgdr@dalibo.com> Discussion: https://www.postgresql.org/message-id/flat/a9139c29-7ddd-973b-aa7f-71fed9c38d75%40minerva.info --- src/backend/replication/logical/relation.c | 3 +- src/test/subscription/t/008_diff_schema.pl | 37 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c index f938d1fa48..b386f8460d 100644 --- a/src/backend/replication/logical/relation.c +++ b/src/backend/replication/logical/relation.c @@ -340,7 +340,8 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode) attnum = AttrNumberGetAttrOffset(attnum); - if (!bms_is_member(entry->attrmap[attnum], remoterel->attkeys)) + if (entry->attrmap[attnum] < 0 || + !bms_is_member(entry->attrmap[attnum], remoterel->attkeys)) { entry->updatable = false; break; diff --git a/src/test/subscription/t/008_diff_schema.pl b/src/test/subscription/t/008_diff_schema.pl index 3ad00eae3b..d1c8fb7061 100644 --- a/src/test/subscription/t/008_diff_schema.pl +++ b/src/test/subscription/t/008_diff_schema.pl @@ -3,7 +3,7 @@ use warnings; use PostgresNode; use TestLib; -use Test::More tests => 4; +use Test::More tests => 5; # Create publisher node my $node_publisher = get_new_node('publisher'); @@ -29,7 +29,7 @@ # Setup logical replication my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; $node_publisher->safe_psql('postgres', - "CREATE PUBLICATION tap_pub FOR TABLE test_tab"); + "CREATE PUBLICATION tap_pub FOR ALL TABLES"); $node_subscriber->safe_psql('postgres', "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub" @@ -88,5 +88,38 @@ is($result, qq(3|3|3|3), 'check extra columns contain local defaults after apply'); + +# Check a bug about adding a replica identity column on the subscriber +# that was not yet mapped to a column on the publisher. This would +# result in errors on the subscriber and replication thus not +# progressing. +# (https://www.postgresql.org/message-id/flat/a9139c29-7ddd-973b-aa7f-71fed9c38d75%40minerva.info) + +$node_publisher->safe_psql('postgres', + "CREATE TABLE test_tab2 (a int)"); + +$node_subscriber->safe_psql('postgres', + "CREATE TABLE test_tab2 (a int)"); + +$node_subscriber->safe_psql('postgres', + "ALTER SUBSCRIPTION tap_sub REFRESH PUBLICATION"); + +# Add replica identity column. (The serial is not necessary, but it's +# a convenient way to get a default on the new column so that rows +# from the publisher that don't have the column yet can be inserted.) +$node_subscriber->safe_psql('postgres', + "ALTER TABLE test_tab2 ADD COLUMN b serial PRIMARY KEY"); + +$node_publisher->safe_psql('postgres', + "INSERT INTO test_tab2 VALUES (1)"); + +$node_publisher->wait_for_catchup('tap_sub'); + +is($node_subscriber->safe_psql('postgres', + "SELECT count(*), min(a), max(a) FROM test_tab2"), + qq(1|1|1), + 'check replicated inserts on subscriber'); + + $node_subscriber->stop; $node_publisher->stop; base-commit: e5cfb8cbbe91e73ee92d9e4ab023ca208f3b748a -- 2.23.0
^ permalink raw reply [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-11-07 15:02  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 20+ messages in thread

From: Peter Eisentraut @ 2019-11-07 15:02 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>; Tom Lane <tgl@sss.pgh.pa.us>; Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On 2019-11-05 17:18, Andres Freund wrote:
> On 2019-11-05 16:02:51 +0100, Peter Eisentraut wrote:
>>   $node_publisher->stop('fast');
>> +
>> +
>> +# TODO: https://www.postgresql.org/message-id/flat/a9139c29-7ddd-973b-aa7f-71fed9c38d75%40minerva.info
>> +
>> +$node_publisher = get_new_node('publisher3');
>> +$node_publisher->init(allows_streaming => 'logical');
>> +$node_publisher->start;
>> +
>> +$node_subscriber = get_new_node('subscriber3');
>> +$node_subscriber->init(allows_streaming => 'logical');
>> +$node_subscriber->start;
> 
> Do we really have to create a new subscriber for this test? The creation
> of one isn't free. Nor is the amount of test code duplication
> neglegible.

I changed that in the v2 patch.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-11-07 15:18  Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 20+ messages in thread

From: Jehan-Guillaume de Rorthais @ 2019-11-07 15:18 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On Thu, 7 Nov 2019 16:02:21 +0100
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

> On 2019-11-05 17:05, Jehan-Guillaume de Rorthais wrote:
> >> I have simplified your reproduction steps from the previous message to a
> >> test case, and I can confirm that your proposed fix addresses the issue.  
> > 
> > Thanks for the feedback and the test case. I wonder if ALTER SUBSCRIPTION
> > DISABLE/ENABLE is useful in the test case?  
> 
> Turns out it's not necessary.  Attached is an updated patch that 
> simplifies the test even further and moves it into the 
> 008_diff_schema.pl file.

OK. No further comments on my side.

Thanks,





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-11-09 08:18  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  0 siblings, 1 reply; 20+ messages in thread

From: Peter Eisentraut @ 2019-11-09 08:18 UTC (permalink / raw)
  To: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On 2019-11-07 16:18, Jehan-Guillaume de Rorthais wrote:
> On Thu, 7 Nov 2019 16:02:21 +0100
> Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:
> 
>> On 2019-11-05 17:05, Jehan-Guillaume de Rorthais wrote:
>>>> I have simplified your reproduction steps from the previous message to a
>>>> test case, and I can confirm that your proposed fix addresses the issue.
>>>
>>> Thanks for the feedback and the test case. I wonder if ALTER SUBSCRIPTION
>>> DISABLE/ENABLE is useful in the test case?
>>
>> Turns out it's not necessary.  Attached is an updated patch that
>> simplifies the test even further and moves it into the
>> 008_diff_schema.pl file.
> 
> OK. No further comments on my side.

Committed and backpatched.  Thanks!

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 20+ messages in thread

* Re: logical replication - negative bitmapset member not allowed
@ 2019-11-09 12:44  Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 0 replies; 20+ messages in thread

From: Jehan-Guillaume de Rorthais @ 2019-11-09 12:44 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Alvaro Herrera <alvherre@2ndquadrant.com>; Tim Clarke <tim.clarke@minerva.info>; pgsql-general

On Sat, 9 Nov 2019 09:18:21 +0100
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

> On 2019-11-07 16:18, Jehan-Guillaume de Rorthais wrote:
> > On Thu, 7 Nov 2019 16:02:21 +0100
> > Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:
> >   
> >> On 2019-11-05 17:05, Jehan-Guillaume de Rorthais wrote:  
> >>>> I have simplified your reproduction steps from the previous message to a
> >>>> test case, and I can confirm that your proposed fix addresses the
> >>>> issue.  
> >>>
> >>> Thanks for the feedback and the test case. I wonder if ALTER SUBSCRIPTION
> >>> DISABLE/ENABLE is useful in the test case?  
> >>
> >> Turns out it's not necessary.  Attached is an updated patch that
> >> simplifies the test even further and moves it into the
> >> 008_diff_schema.pl file.  
> > 
> > OK. No further comments on my side.  
> 
> Committed and backpatched.  Thanks!

I'm glad to help!

Thanks,





^ permalink  raw  reply  [nested|flat] 20+ messages in thread


end of thread, other threads:[~2019-11-09 12:44 UTC | newest]

Thread overview: 20+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-04-01 13:36 logical replication - negative bitmapset member not allowed Tim Clarke <tim.clarke@minerva.info>
2019-04-01 14:02 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-04-01 14:53   ` Tim Clarke <tim.clarke@minerva.info>
2019-04-02 13:59     ` Tom Lane <tgl@sss.pgh.pa.us>
2019-04-02 14:26       ` Tim Clarke <tim.clarke@minerva.info>
2019-04-02 14:46         ` Tom Lane <tgl@sss.pgh.pa.us>
2019-04-02 15:04           ` Tim Clarke <tim.clarke@minerva.info>
2019-04-01 21:43   ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-04-04 21:37     ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-04-04 22:05       ` Tim Clarke <tim.clarke@minerva.info>
2019-10-10 13:15       ` Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
2019-10-25 15:38         ` Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
2019-11-05 15:02           ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-11-05 16:05             ` Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
2019-11-07 15:02               ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-11-07 15:18                 ` Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
2019-11-09 08:18                   ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-11-09 12:44                     ` Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
2019-11-05 16:18             ` Andres Freund <andres@anarazel.de>
2019-11-07 15:02               ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox