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 1t1C2s-00F7JH-CV for pgsql-general@arkaria.postgresql.org; Wed, 16 Oct 2024 21:59:06 +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 1t1C2p-00B6KF-2i for pgsql-general@arkaria.postgresql.org; Wed, 16 Oct 2024 21:59:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t1C2o-00B6K6-JO for pgsql-general@lists.postgresql.org; Wed, 16 Oct 2024 21:59:03 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t1C2m-001Fjc-1t for pgsql-general@lists.postgresql.org; Wed, 16 Oct 2024 21:59:01 +0000 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-539e63c8678so357866e87.0 for ; Wed, 16 Oct 2024 14:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729115938; x=1729720738; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=gD8h9M9ainrf9WMPFxuoVG5XiclfQEJV7qtLDhRpzOI=; b=OtaAvrl2fjMY0dszdzA7YMSbI+8bQF5sTRVxPgFg/KKSpRQwiTI6yxBw7l8R++FQvZ KuEyRtT6I4cf99f5SGJGqXpBaVRuYiE41mzx+los7UdmGGyo83nm2Me2R17e3USRVzLv 0vxzNHQQAB63/KG1NczfrRILKGaS16przapTTIyGp8svVTTZR5/ggu/LJ7O4MiFMLMzN FDE+2GSd/Xk7Ls+Gn9srBtYQgMWJYRvEKFLoa2275pUY9peWeFEo5psn7JvV+p+m2uZZ CroWIu+/ZA5Q2E7BXRwrR9JfqevQ0hfnHuGHPciBrf1y9DZRlgl1XboL0K0k4XDI7mnE GmtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729115938; x=1729720738; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gD8h9M9ainrf9WMPFxuoVG5XiclfQEJV7qtLDhRpzOI=; b=AiEj94lsJIkwe6da6QpiHyHkk1SZ2TvDFY9RPW9iVufI89c3y+BgfobXL7VkMk82dZ 5M2pz5qYmO7Zufpiy80Mpv0uyhO3O8fiV4fjEFfggqdaZO9xsnjtthVku5YJLNGrpoT7 v4k0ipZWNSEc2+Iy7v4EKKuGCsLgc6GBpNp4adONA228NoCRBXB52VoLMlcYb5Lug4Cp dlbTSX4v1MAjRWXQ+4in0U3HRd4RUyMfODOZvDKeK471lRPCLsyxXCITgIT8XpEGv3iz 2F8Zv2mwb4Z3xbSBApra1PyAJ2SGkegKxxWvFgfUBh8QLPjD99qyChcNYZVCNR3cBQhM m09A== X-Gm-Message-State: AOJu0YxDgY3a7yV47crBlw5k2NS/deOljk7UPFZKFWHeALOkWlDv2UT5 8vTia+y3dbcpOjZgyzJHYmsJbjOI7EZFegeLQOwbDyC4r9yJKZzwwEnj+NNeJyZR7MALl4vp3GD QeXlcjjR7v8g/HQJjtxFEhW/gSU54jjc/ X-Google-Smtp-Source: AGHT+IFGt5cxTTGF9FrKK0S8Ct52iCHIy3/DfEo9ghtyNNXvmnTAIHFwE48ikgeZRTiGK0fJNpO/7B5ap8y1CJ/Bxjo= X-Received: by 2002:a05:6512:3e06:b0:536:54fd:275b with SMTP id 2adb3069b0e04-539e5728fd4mr8834749e87.54.1729115938137; Wed, 16 Oct 2024 14:58:58 -0700 (PDT) MIME-Version: 1.0 From: Koen De Groote Date: Wed, 16 Oct 2024 23:58:46 +0200 Message-ID: Subject: Logical replication disabled, recovery not possible because of 1 large transaction with schema changes? To: PostgreSQL General Content-Type: multipart/alternative; boundary="00000000000044b28706249f2dd2" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000044b28706249f2dd2 Content-Type: text/plain; charset="UTF-8" If this question is more suitable for another mailing list, please let me know. I've set up the following table on both publisher and subscriber, both are pg16: CREATE TABLE dummy_table ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, age INT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); Added to publication, refreshed subscription. Add some data on the publisher side: INSERT INTO dummy_table (name, email, age) VALUES ('John Doe', 'john.doe@example.com', 25), ('Jane Smith', 'jane.smith@example.com', 30), ('Michael Johnson', 'michael.j@example.com', 45), ('Emily Davis', 'emily.d@example.com', 27), ('Robert Brown', 'robert.brown@example.com', 40); The data can be seen on the subscriber. So far, so good. I then execute the following patch on the publisher: https://gist.github.com/KoenDG/d1c06d8c740c64e4e5884d0c64b81f11 It is a single transaction that does the following: 1/ Insert data, 1000 items 2/ Drop a column 3/ Alter a column name 4/ Add 2 columns, nullable 5/ Add a column and give it a unique constraint 6/ Update values for a column with NULL values, added in step 4. 7/ Set the column updated in step 6 to be NOT NULL 8/ Create a unique index with the columns from step 3 and 6 9/ Insert a column with a default value 10/ Insert data for this schema, another 1000 items. The subscription disabled, this is to be expected, there are new columns names, the schema needs to be updated on the subscriber side. However, it seems I'm stuck. I can't enable the subscription. This is to be expected, it will try to resume and run into the same issues. Ok, I update the schema and enable again. It runs into an error for the inserts of step 1. These set values for columns dropped in step 2. I revert to the old schema and enable again. It runs into an error again, this time for values that don't exist yet at step 1. I tried dropping the table at the subscriber side, recreating the correct schema, but this runs into the same error. I remove the table from the publication and retry. Same error. Even with the table no longer in the publication, and the table on the subscriber side dropped and re-created, I'm still getting the exact same errors of "logical replication target relation "public.dummy_table" is missing replicated columns: "contact_email", "status", "phone_number", "username"" The only solution I've found is to drop the table from the publication, and then drop the entire subscription and set it back up again, with the correct schema. Am I making a mistake? Or does putting all these commands in a single transaction ruin my chances? Clarification much appreciated. Regards, Koen De Groote --00000000000044b28706249f2dd2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
If this question is more suitable for another mailing= list, please let me know.

I've set up the fol= lowing table on both publisher and subscriber, both are pg16:
CREATE TABLE dummy_table (
id SERIAL PRIMARY KEY,
name = VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
age INT,=
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Added to publication, refreshed subscription.

<= div>Add some data on the publisher side:
INSERT INTO dummy_table = (name, email, age)
VALUES
('John Doe', 'john.doe@example.com', 25),
('Jane Sm= ith', 'jane.smith@example= .com', 30),
('Michael Johnson', 'michael.j@example.com', 45),
('Emily D= avis', 'emily.d@example.com<= /a>', 27),
('Robert Brown', '
robert.brown@example.com', 40);

The data can be seen on the subscriber. So far, so good.
<= br>
I then execute the following patch on the publisher:=C2=A0ht= tps://gist.github.com/KoenDG/d1c06d8c740c64e4e5884d0c64b81f11

It is a single transaction that does the following:

1/ Insert data, 1000 items
2/ Drop a column
3/ Alter a column name
4/ Add 2 columns, nullable
5/ Add a column and give it a unique constraint
6/ Update value= s for a column with NULL values, added in step 4.
7/ Set the colu= mn updated in step 6 to be NOT NULL
8/ Create a unique index with= the columns from step 3 and 6
9/ Insert a column with a default = value
10/ Insert data for this schema, another 1000 items.
<= div>
The subscription disabled, this is to be expected, there= are new columns names, the schema needs to be updated on the subscriber si= de.

However, it seems I'm stuck.
I can't enable the subscription. This is to be expected, it= will try to resume and run into the same issues.

= Ok, I update the schema and enable again. It runs into an error for the ins= erts of step 1. These set values for columns dropped in step 2.
<= br>
I revert to the old schema and enable again. It runs into an = error again, this time for values that don't exist yet at step 1.
=

I tried dropping the table at the subscriber side, recr= eating the correct schema, but this runs into the same error.
I remove the table from the publication and retry. Same error. = Even with the table no longer in the publication, and the table on the subs= criber side dropped and re-created, I'm still getting the exact same er= rors of "logical replication target relation "public.dummy_table&= quot; is missing replicated columns: "contact_email", "statu= s", "phone_number", "username""

The only solution I've found is to drop the = table from the publication, and then drop the entire subscription and set i= t back up again, with the correct schema.

Am I mak= ing a mistake? Or does putting all these commands in a single transaction r= uin my chances?

Clarification much appreciated.

Regards,
Koen De Groote

--00000000000044b28706249f2dd2--