pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Logical replication issue
4+ messages / 3 participants
[nested] [flat]

* Logical replication issue
@ 2019-11-19 00:09  Aleš Zelený <zeleny.ales@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Aleš Zelený @ 2019-11-19 00:09 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hello,

we are using logical replication from  PostgreSQL 10.8 (Ubuntu
10.8-1.pgdg14.04+1)  to PostgreSQL 11.3 (Ubuntu 11.3-1.pgdg18.04+1). Thre
are 1305 replicated tables within 3 schemas. The tables are from small
almost static lookup tables to larger tables up to ~40GB holding 44
millions of rows. In production, the replication works like a charm.

But we are experiencing an issue when we create clones of production
databases to the development environment. Development is in a separated
network, loaded from a testing data feed therefore development publisher
database contains data in almost identical volumes and the same structure,
but it is being continuously updated from the testing data feed.

To let all test work properly, replicated tables are truncated after
subscriber database is cloned to the development environment (all restored
subscriptions are dropped) and a new subscription to development publisher
database is created with copy_data =  true option to ensure data
consistency.

Such an approach works well for more than a year using 2 of the present 3
schemas (most of the above-mentioned table count is in the long-used two
schemas). While we have added the third schema with only 7 tables from 35
MB to 40 GB in size, we are experiencing an initial synchronization issue.
The total volume of the three schemas is several hundreds of GB, so the
initial table synchronization lasts usually for several hours.
surprisingly, all of the 7 tables in the third schema, despite their size
or row count fail due to primary key violation, like - duplicate key value
violates unique constraint "party_pkey".
Such behavior makes me very surprised - based on the docs:
https://www.postgresql.org/docs/11/logical-replication-architecture.html,
<https://www.postgresql.org/docs/11/logical-replication-architecture.html;
31.5.1. Initial Snapshot, I expect that after some time necessary for the
table copy and afterward applied changes from WAL, there can't be a chance
for duplicate rows, since both the publisher and the subscriber are using
the same primary key as replica identity.

LOG:  logical replication table synchronization worker for subscription
"sub_anl_dsos_usd", table "party" has started
ERROR:  duplicate key value violates unique constraint "party_pkey"
DETAIL:  Key (party_id)=(\x0003dd00131add0a) already exists.
CONTEXT:  COPY party, line 1

If, once this happens (the table was truncated before the subscription was
created) I truncate the table on the subscriber, copy succeeded and from
that moment replication works like a charm. I'm not aware of using
replication different way then than for the two schemas we stared with and
for them, the synchronization including the application of changes
subsequent to subscription creation works without any issues.

Thanks for any hints on how to diagnose this issue, I can't find where I
did a mistake and I did not expect that this might be related to higher
change rate on publisher tables than the other tables.

Ales

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

* Logical Replication Issue
@ 2020-06-30 11:55  Donzell White <whitedv@verizon.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Donzell White @ 2020-06-30 11:55 UTC (permalink / raw)
  To: pgsql-general

Hi,
I have set up logical replication from an AWS RDS instance to a postgreSQL database on an EC2 instance. I am getting an “out of memory” error during the initial for one of the tables. I have include a snippet of the error at the bottom of this email. The snippet below repeats every four or eight hours, depending on the work_mem and maintenance_work_mem values. The other 500 plus tables load with no problem. 

Does anyone have experience with this issue. Suggestions on what to try would be greatly appreciated.

Both databases are running PostgreSQL 11.5.
The database is 5 TB in size and has over 500 tables.  The "out of memory" error every eight hours.  The table is 578GB in the RDS database and ate up over 9TB before it ran out of space on the EC2 instance.  The table has a bytea column but there is no data in that column. It also has a text column and the largest text length is 978MB.  

The odd thing is that this is not the largest table in the database. The largest table took 57 hours to initial load and it does have bytea data.  The largest table is about 4 times larger from a size perspective.  I have increases the work_mem and the maintenance_work_mem parameters and tried loading only the problem table.  This resulted in the “out of memory” error occurring every 4 hours instead of every eight hours. Note that the source database is static (no changes).

020-06-17 07:52:28.618 UTC [8410] LOCATION:  LogCheckpointStart, xlog.c:8508
2020-06-17 07:52:52.505 UTC [8410] LOG:  00000: checkpoint complete: wrote 69088 buffers (1.6%); 0 WAL file(s) added, 0 removed, 42 recycled; write=23.548 s, sync=0.271 s, total=23.886 s; sync files=14, longest=0.165 s, average=0.019 s; distance=688856 kB, estimate=701162 kB
2020-06-17 07:52:52.505 UTC [8410] LOCATION:  LogCheckpointEnd, xlog.c:8590
2020-06-17 07:53:15.960 UTC [8410] LOG:  00000: checkpoint starting: xlog
2020-06-17 07:53:15.960 UTC [8410] LOCATION:  LogCheckpointStart, xlog.c:8508
2020-06-17 07:53:23.933 UTC [14390] ERROR:  XX000: could not receive data from WAL stream: ERROR:  out of memory
        DETAIL:  Cannot enlarge string buffer containing 1073741802 bytes by 28 more bytes.
2020-06-17 07:53:23.933 UTC [14390] CONTEXT:  COPY product, line 15568244
2020-06-17 07:53:23.933 UTC [14390] LOCATION:  libpqrcv_receive, libpqwalreceiver.c:772
2020-06-17 07:53:24.160 UTC [19873] LOG:  00000: logical replication table synchronization worker for subscription "subscription_test_tables", table “product" has started
2020-06-17 07:53:24.160 UTC [19873] LOCATION:  ApplyWorkerMain, worker.c:1662

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

* Re: Logical Replication Issue
@ 2020-06-30 17:05  Michael Lewis <mlewis@entrata.com>
  parent: Donzell White <whitedv@verizon.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Michael Lewis @ 2020-06-30 17:05 UTC (permalink / raw)
  To: Donzell White <whitedv@verizon.net>; +Cc: pgsql-general

Per the release notes, there are some enhancements to logical replication
that came after 11.5 like 11.8 particularly related to replication identity
full. Do you have a primary key or unique index that is being used for the
replication identity?

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

* Re: Logical Replication Issue
@ 2020-06-30 18:05  Donzell White <whitedv@verizon.net>
  parent: Michael Lewis <mlewis@entrata.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Donzell White @ 2020-06-30 18:05 UTC (permalink / raw)
  To: mlewis@entrata.com <mlewis@entrata.com>; +Cc: pgsql-general

My table has a primary key.  In addition, this is an initial load issue where the replication identity should not matter.


-----Original Message-----
From: Michael Lewis <mlewis@entrata.com>
To: Donzell White <whitedv@verizon.net>
Cc: pgsql-general <pgsql-general@postgresql.org>
Sent: Tue, Jun 30, 2020 1:05 pm
Subject: Re: Logical Replication Issue

Per the release notes, there are some enhancements to logical replication that came after 11.5 like 11.8 particularly related to replication identity full. Do you have a primary key or unique index that is being used for the replication identity?

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


end of thread, other threads:[~2020-06-30 18:05 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-19 00:09 Logical replication issue Aleš Zelený <zeleny.ales@gmail.com>
2020-06-30 11:55 Logical Replication Issue Donzell White <whitedv@verizon.net>
2020-06-30 17:05 ` Re: Logical Replication Issue Michael Lewis <mlewis@entrata.com>
2020-06-30 18:05   ` Re: Logical Replication Issue Donzell White <whitedv@verizon.net>

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