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 1s4fYc-0009no-4R for pgsql-general@arkaria.postgresql.org; Wed, 08 May 2024 11:33:58 +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 1s4fXb-000C73-9t for pgsql-general@arkaria.postgresql.org; Wed, 08 May 2024 11:32:55 +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 1s4fXa-000C6I-UN for pgsql-general@lists.postgresql.org; Wed, 08 May 2024 11:32:55 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s4fXT-0000xE-EV for pgsql-general@postgresql.org; Wed, 08 May 2024 11:32:53 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-34f0e55787aso2427219f8f.2 for ; Wed, 08 May 2024 04:32:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1715167967; x=1715772767; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=t2vmYM6qjK6saml9ep46/n5mueg7LWFHIE/fmd0rDVM=; b=L54ryBm0Tb3nUxUoOPazAyLsHrGseFXsAZn0pQ1K/7YzZzsadLjaSGtIOOXwSMIrD3 myYXWZXqpZKkSTUjgXf60//lzQq/VmEGiEcR9emBOcfupZUvB58evBaf7Bb6TesAhcyz CD7ByV2J6FoJyE6ahM/O5ZKfBd4S2/GojWQab7ToYHJjBUAcFdruN+SX8MBaq8HxZ29B Magqj3aX8c//4MoXhtFWU2yCUUN8jGUtYagDT2l9fq1tulwYhBHsRH0hKgxcHMLFiMGU ajhzTMZCSeeBlbhMbfTVm+QRjO3N2Ol5fL1GMNAKrH3U3jd8OxLEjEhh/n4vNmKXU4+A unCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715167967; x=1715772767; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t2vmYM6qjK6saml9ep46/n5mueg7LWFHIE/fmd0rDVM=; b=OCzTHB0BkjepLuCnD0Bhtn4fd9FhEYgtJd2r6OoOmB8r2lg+fltYyyvoeWoBRJXcQl AB1WAHTYWy7B+gf1jkUi9CzZQuWkXc4IbNWZ9HlS8DYfGOZiV8Zyq1dpEsJiSZd0rh/H km/sb97tiZinERYb0xRarILwpDK1/vdAZE12RozisDxPoK1Hx6S3sH96UfS2juTXmJHV 9V05FHxnrGp9VNd2Pq0vTc/71QhCJOlJ6+DhYDBDjlUfIbqKcKy0ZaJmkj/PvEkgRFx5 vsZ+Ybf75UR1/kTi5Kgq6Q5mMZqHAR5wXnan11xom1kR9GT2Rn4mscE5zyH/aA3CUlte YtKw== X-Forwarded-Encrypted: i=1; AJvYcCW4v2BP9jTy7QcO/4D5IedPqrM3Ljwy6ofKc16MWhFDYcsXxRlC2Y+123vSy3u4rJOa/i5K3vcVSarih6Nt1H+rzpEzElUmZIXmaAnq X-Gm-Message-State: AOJu0YzXEspB0ke60BAq/EFGV7h3EAkED/srde4IIu35o+xiU4tu4/O1 VBzGdJbh8OTTzj9hnBPPND2UsfKuU4+Vt5XhDzc2RKlflOx6JA+DV7Bx8P3BsyHgUSHPSHMCcwu SNg== X-Google-Smtp-Source: AGHT+IFbPdCN0k79FgGIfqfEXxsoZ01bKoG1acdXMxuMSKBspYs8+s4Uc8v5iqljPJkd02PxKHLpIw== X-Received: by 2002:a5d:44d2:0:b0:34c:a023:d9b4 with SMTP id ffacd0b85a97d-34fca80edb7mr1527227f8f.69.1715167966607; Wed, 08 May 2024 04:32:46 -0700 (PDT) Received: from [10.137.0.18] ([84.198.244.197]) by smtp.gmail.com with ESMTPSA id g18-20020a5d5412000000b00346bda84bf9sm15178795wrv.78.2024.05.08.04.32.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 May 2024 04:32:46 -0700 (PDT) Message-ID: <448c5c84-52db-470f-a01c-57776a9914aa@enterprisedb.com> Date: Wed, 8 May 2024 13:32:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Unexpected data when subscribing to logical replication slot To: Daniel McKenzie , pgsql-general@postgresql.org References: Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 5/8/24 11:17, Daniel McKenzie wrote: > 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. > Where/how does the enrichment query run? How does the whole process look like? I guess an application is receiving decoded changes as JSON, and then querying the database? > 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. > Would be good to have some sort of reproducer - ideally a script that sets up an instance + replication, and demonstrates the issue. Or at least a sufficiently detailed steps to reproduce it without having to guess what exactly you did. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company