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 1r1AUZ-009jjc-5r for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Nov 2023 19:15:03 +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 1r1AUW-00GN31-TZ for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Nov 2023 19:15:00 +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 1r1AUW-00GN2j-IT for pgsql-bugs@lists.postgresql.org; Thu, 09 Nov 2023 19:15:00 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r1AUM-005a4T-LO for pgsql-bugs@lists.postgresql.org; Thu, 09 Nov 2023 19:14:57 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-52bd9ddb741so2031696a12.0 for ; Thu, 09 Nov 2023 11:14:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1699557288; x=1700162088; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=3VxPqZ+FJoVlmSk9oWPpRpIEkSXxhaWVdh970Rjk9B0=; b=K4IbCJGZ6BEGNf46QEMnDpO/SkXpztAb3Z9Rm87bbPlCJir3IWflsNsv/X6JX6JC/K 9GKwyfnwSvrrygIRm5dZQ8TSCqmc7pOQytl9GdYoM03IJMPA2fGtWZ+CCbekATkIDABa 3FA5GJdRpoXPqozLqZ8j48ikODn/nVqEwg3mAvg/LX5Y2uIZEX/SjKczOq0KPayi7fqS FAOv/mDqYglvYPoGtXehhuQnQKeFicKY9XeR1HAvJvJyzkN8oxpp/XHBvOoIO/fEWWn6 eydAYIrEJr0hf9UHjpwITruYCmZ/JA8D6YkHsxkHYnNCb/ILMvGGHjuUXXDujh7AN44M 1Lcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699557288; x=1700162088; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3VxPqZ+FJoVlmSk9oWPpRpIEkSXxhaWVdh970Rjk9B0=; b=GWXGtnxDy9N5oJ4koCp+YizWsq7HGt4iZoEVDGSjWjDzGL32zc3l3Mz+R/M7aNFbHH rG+KDsyeBVTl4GwBUx13P4VAqL9/yE0ZbGqvpIdjZtWFqVQfQvIW6FPW6YlRPRn+bSPK lkW4Cd9/YppV8UtfUO7eRKwi4rADvc1k3MqOMYZZg1jbTJRDNjjV+6mzSizcQ5eTznm3 FKPZlK3WYZCz2/kKr0n8ADAZfyWsB+y0WEtNEbToAWH0BrSyIHqTJ0iTvUvnORa4UM7I aQ2RFBszS9JDwoM9sZzWqXDWRL4wXt93v6kMf3sELGkxae/mk0mryr7F8blRIiCgiooI s+SA== X-Gm-Message-State: AOJu0YwSEJRhVhCNubWXLV4R/hP6E1PZJjZERYP/KC2nq4WoP9PnoCAv 9BcQl9wpYZVRdhOa6DnfHWJl7w== X-Google-Smtp-Source: AGHT+IEzT0loQ2PmkJCf0lxiIa9MVsb1+fmz4lHKBoV+zSidaZ6yEyqH4Sbvfs5frX5AQ3NdStSV6w== X-Received: by 2002:a50:d742:0:b0:540:3a46:cdcd with SMTP id i2-20020a50d742000000b005403a46cdcdmr4941174edj.29.1699557287934; Thu, 09 Nov 2023 11:14:47 -0800 (PST) Received: from [10.137.0.17] (ip-86-49-228-220.bb.vodafone.cz. [86.49.228.220]) by smtp.gmail.com with ESMTPSA id o2-20020a509b02000000b00542df4a03d0sm173917edi.16.2023.11.09.11.14.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Nov 2023 11:14:47 -0800 (PST) Message-ID: <2a638962-7a62-abd6-d9a4-3c322ec2a06d@enterprisedb.com> Date: Thu, 9 Nov 2023 20:14:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Logical replication is missing block of rows when sending initial sync? Content-Language: en-US To: depesz@depesz.com, Amit Kapila , Kyotaro Horiguchi , kuroda.hayato@fujitsu.com, pgsql-bugs@lists.postgresql.org References: <20231102.101713.170587046871054404.horikyota.ntt@gmail.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/8/23 15:02, hubert depesz lubaczewski wrote: >> OK. found another case (maybe two). > > OK, the other case is real. Different database. Same scenario. > > Errors (3 because we have 3 missing fkeys): > > #v+ > ALTER TABLE ONLY c44s16539.assignment_overrides ADD CONSTRAINT fk_rails_58f8ee369b FOREIGN KEY (assignment_id) REFERENCES c44s16539.assignments(id); > ERROR: insert or update on table "assignment_overrides" violates foreign key constraint "fk_rails_58f8ee369b" > DETAIL: Key (assignment_id)=(248083) is not present in table "assignments". > > ALTER TABLE ONLY c44s16539.post_policies ADD CONSTRAINT fk_rails_cf2d119863 FOREIGN KEY (assignment_id) REFERENCES c44s16539.assignments(id); > ERROR: insert or update on table "post_policies" violates foreign key constraint "fk_rails_cf2d119863" > DETAIL: Key (assignment_id)=(248083) is not present in table "assignments". > > ALTER TABLE ONLY c44s16539.submissions ADD CONSTRAINT fk_rails_61cac0823d FOREIGN KEY (assignment_id) REFERENCES c44s16539.assignments(id); > ERROR: insert or update on table "submissions" violates foreign key constraint "fk_rails_61cac0823d" > DETAIL: Key (assignment_id)=(248083) is not present in table "assignments". > #v- > > In all cases the problem is missing c44s16539.assignments with is = 248083. > > This time it looks that only one row is missing: > > #v+ > Pg14# select max(id) from c44s16539.assignments where id < 248083; > max > ──────── > 248082 > (1 row) > > Pg14# select min(id) from c44s16539.assignments where id > 248083; > min > ──────── > 248084 > (1 row) > #v- > > Schema is complicated. 76 columns. On pg12 side one column is dropped. > 22 indexes, 9 fkeys from this table (assignments) to others, ~ 35 fkeys > pointing to this table (but only 3 have rows that reference the > missing record. > > Some informationa bout the record: > > #v+ > Pg12# select ctid, xmin, cmin, xmax, cmax, id, created_at, updated_at from c44s16539.assignments where id = 248083 \gx > ─[ RECORD 1 ]────────────────────────── > ctid │ (24192,1) > xmin │ 472291499 > cmin │ 12 > xmax │ 472291499 > cmax │ 12 > id │ 248083 > created_at │ 2023-11-07 15:50:05.506077 > updated_at │ 2023-11-07 15:51:28.738893 > #v- > > logs for when it was added to replication: > > #v+ > 2023-11-07 15:47:27.898 UTC,"postgres","dbname",2333,"[local]",654a5c0f.91d,39,"ALTER PUBLICATION",2023-11-07 15:47:27 UTC,6/0,0,LOG,00000,"duration: 1.476 ms",,,,,,,,,"psql" > 2023-11-07 15:47:27.899 UTC,"postgres","dbname",2333,"[local]",654a5c0f.91d,40,"idle",2023-11-07 15:47:27 UTC,6/1209097693,0,LOG,00000,"statement: ALTER PUBLICATION focal14 ADD TABLE ONLY c247s1094.messages_2022_50;",,,,,,,,,"psql" > 2023-11-07 15:47:27.900 UTC,"postgres","dbname",2333,"[local]",654a5c0f.91d,41,"ALTER PUBLICATION",2023-11-07 15:47:27 UTC,6/0,0,LOG,00000,"duration: 1.493 ms",,,,,,,,,"psql" > 2023-11-07 15:47:27.900 UTC,"postgres","dbname",2333,"[local]",654a5c0f.91d,42,"idle",2023-11-07 15:47:27 UTC,6/1209097694,0,LOG,00000,"statement: ALTER PUBLICATION focal14 ADD TABLE ONLY c44s16539.assignments;",,,,,,,,,"psql" > 2023-11-07 15:47:27.902 UTC,"postgres","dbname",2333,"[local]",654a5c0f.91d,43,"ALTER PUBLICATION",2023-11-07 15:47:27 UTC,6/0,0,LOG,00000,"duration: 1.936 ms",,,,,,,,,"psql" > 2023-11-07 15:47:27.902 UTC,"postgres","dbname",2333,"[local]",654a5c0f.91d,44,"idle",2023-11-07 15:47:27 UTC,6/1209097695,0,LOG,00000,"statement: ALTER PUBLICATION focal14 ADD TABLE ONLY c39s5131.messages_2023_20;",,,,,,,,,"psql" > 2023-11-07 15:47:27.903 UTC,"postgres","dbname",2333,"[local]",654a5c0f.91d,45,"ALTER PUBLICATION",2023-11-07 15:47:27 UTC,6/0,0,LOG,00000,"duration: 1.292 ms",,,,,,,,,"psql" > #v- > > It is interesting that the time when the row was inserted (created_at) is > always "around" the time that the table was added to publication... > > Just like with the other case, I can leave it in current state for > a day, so if you'd need more information from it, let me know. > I think it'd be interesting to look at the WAL using pg_waldump, and see how it relates to the LSN used for the tablesync slot. I'll try reproducing this locally over the weekend. Should I use the test_1030.sh script that you shared a week ago, or do I need to do something more? One thing that puzzles me is that IIUC the script doesn't generate any changes while adding the tables to the subscription? I probably should have paid more attention to the details, instead of assuming there are concurrent changes - which seemed like there might be some race, or something. But this seems like there are no changes and the tablesync just fails to copy some subset of it. That's *really* strange. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company