Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4dR1-005wdd-By for pgsql-general@arkaria.postgresql.org; Wed, 08 May 2024 09:17:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s4dQx-007frZ-7C for pgsql-general@arkaria.postgresql.org; Wed, 08 May 2024 09:17:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4dQw-007frR-RU for pgsql-general@lists.postgresql.org; Wed, 08 May 2024 09:17:55 +0000 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s4dQu-002ACf-T5 for pgsql-general@postgresql.org; Wed, 08 May 2024 09:17:54 +0000 Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-de45dba15feso4334204276.3 for ; Wed, 08 May 2024 02:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=curvedental.com; s=google; t=1715159871; x=1715764671; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Fohh4/EvK2YJkduP9YEaNz0FySw0uD1xpwGjx9SpB+Y=; b=CNB8hjLpU7YIDNQP7OTSWFJ6Y8fE11feEU7J3oUhsO6fJXvPTQ4B2bMoCXCJaQopPe UEEeJga4mkmwaCftMqB1m6ZP0uOJnOzM/P7UMkFBg2LKSd7tHeyZTtGEDmX6AtEPtjW9 VyWr6JsO8d4iGpkmwLNmo0xqsle8Ggtn51D3A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715159871; x=1715764671; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Fohh4/EvK2YJkduP9YEaNz0FySw0uD1xpwGjx9SpB+Y=; b=tQM15t4it4e+KaPzwDK6nFxfv50hDr8+++GC2lXB3vlJzOUBqwu21wg4lDlWvvoTj7 AxY6DhPHFaS3g3z19WnIt+gVHdLqEhvUh6QDGzbAVhba81ovJEyzw+nSLv2DB9BQxHG7 LvK13dn3ogZWJ+uO/l3Fo0AgY2noh4Zd1u6Gw81TOvrek+sejr+1uB4TMhyzTi/nFdEn yB32lraG/AynxK+fJ1+NWkOjDZhtXsPcwZlXeLonJa0di2aKInfkqIu/j9Rt+8+NgKx3 XgivvgYlhw+jg2425CN67uEQz1mgE7Q8nu0tNAaGy6BuaO5XK3p5tLa6QLpjEtM1ztHy EWbA== X-Gm-Message-State: AOJu0YyQbYnosrNdmaEi5tetJxIlhOovlAHM8qBjHULw9FOSrJwAVywq wNH7+VqCvxw63Syl7AY12Rwcd4mtASwTrEVst2NI4NIspVq4Ipl+0iNgrUEuxAYfln8Wt2HZVRC K3GpjiK7X0tMhEQpvozp7f30vZcTpjjYY9f3F7Z3JUAuE5ZSTjx4qeeY= X-Google-Smtp-Source: AGHT+IGI4ve34EDru4lIw7sGIhFH/TqIL69q2eLEVhAw3VlSnep0fCPqAO/Zps/EyZUJ+2AqLPDBNN2sOOrTLxgBkSA= X-Received: by 2002:a5b:981:0:b0:deb:a0a2:aad6 with SMTP id 3f1490d57ef6-debb9db1fe3mr2266304276.28.1715159870922; Wed, 08 May 2024 02:17:50 -0700 (PDT) MIME-Version: 1.0 From: Daniel McKenzie Date: Wed, 8 May 2024 10:17:40 +0100 Message-ID: Subject: Unexpected data when subscribing to logical replication slot To: pgsql-general@postgresql.org Content-Type: multipart/alternative; boundary="000000000000d6f74e0617edc69f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000d6f74e0617edc69f Content-Type: text/plain; charset="UTF-8" We have a .NET application which subscribes to a logical replication slot using wal2json. The purpose of the application is to publish events to AWS SQS. We are required to first "enrich" these events by querying the database. We have found that these queries will often find old data (i.e. the data that existed prior to the update) which is unexpected. For example, when I use a psql terminal to update a user's last name from "Jones" to "Smith" then I would expect the enrichment query to find "Smith" but it will sometimes still find "Jones". It finds the old data perhaps 1 in 50 times. To reproduce this I use a psql terminal to execute an update statement which changes a user's last name with \watch 1.5 and monitor our application logs for cases where the wal2json output and the enrichment query output have different last names. We have compared transaction ids by adding include-xids to pg_recvlogical and adding txid_current() to to the enrich query and the txid_current() is always the xid + 1. We have found two things that appear to resolve the problem - - Using a more powerful EC2 instance. We can reproduce the issue with a r7a.medium instance but not with a r7a.large EC2 instance. - Changing the Postgres synchronous_commit parameter from "on" to "off". We cannot reproduce the issue with synchronous_commit set to "off". We need help to understand this unexpected behaviour. We are using Postgres 14.10. Thanks, Daniel McKenzie --000000000000d6f74e0617edc69f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
We have a .NET application which subscribes to a logi= cal replication slot using wal2json. The purpose of the application is to p= ublish events to AWS SQS. We are required to first "enrich" these= events by querying the database.

We have found th= at these queries will often find old data (i.e. the data that existed prior= to the update) which is unexpected.

For example, = when I use a psql terminal to update a user's last name from "Jone= s" to "Smith" then I would expect the enrichment query to fi= nd "Smith" but it will sometimes still find "Jones". It= finds the old data perhaps 1 in 50 times.

To repr= oduce this I use a psql terminal to execute an update statement which chang= es a user's last name with \watch 1.5 and monitor our application logs = for cases where the wal2json output and the enrichment query output have di= fferent last names.

We have compared transaction i= ds by adding=C2=A0include-xids to pg_recvlogical and adding txid_current() = to to the enrich query and the txid_current() is always the xid=C2=A0+ 1.

We have found two things that appear to resolve the= problem -
  • Using a more powerful EC2 instance. We can rep= roduce the issue with a r7a.medium instance but not with a r7a.large EC2 in= stance.
  • Changing the Postgres=C2=A0synchronous_commit parameter fro= m "on" to "off". We cannot reproduce the issue with syn= chronous_commit set to "off".
We need help to under= stand this unexpected behaviour.

We are usin= g Postgres 14.10.

Thanks,
Daniel McKenzie
=
--000000000000d6f74e0617edc69f--