Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iQLx5-0000Ec-G8 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2019 01:42:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iQLx1-0000uz-M9 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2019 01:42:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iQLx1-0000us-7o for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2019 01:42:07 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iQLwy-0001BY-I0 for pgsql-hackers@postgresql.org; Fri, 01 Nov 2019 01:42:06 +0000 Received: by mail-pl1-x644.google.com with SMTP id x6so3605297pln.2 for ; Thu, 31 Oct 2019 18:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=GIelGlQ79xGKOFGkQLi+F7eQ6e5+RmKA3ivYhX8OfF0=; b=LKyN74VuEIKERQqUVPOuzyFydk3vV0hpRhkr/msQABScfIU8u44DphDomfyTzOyBZI Iab2MAbTxA83vFjEObKjFYE9iIk/tRvFzP1QLJYh/PP2OW1tlXQXzER8FJNff6u43Rtp e6pNBUfZGueTqIjolVTUFNyPw5EGgJ/r2sJA87DPvSRB80pmxXHZD9WeGVVZfLRnWnrk YACotYdv9r9pfk/UFtcc/Pz7UleZ57sblS0u1A62OflyIvZBUzDbFVznKf2pUoRn6IJB ygLWVgr3Z/GdO5XG8Hz0CQNpSKMap221ItbX5dmhIclxDRKX7MFi9b0DAK6iRC5ioZ48 gmdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=GIelGlQ79xGKOFGkQLi+F7eQ6e5+RmKA3ivYhX8OfF0=; b=cK8g8Kr34O1B7uIIST3UsearAlBKtNAz6FBaQIQN6uSfpJELeUfcyA2eLxpRVUJkly jFM2LaCEQj0Pj/SmtmB1aTpQYmBz/InVR7BeyDuPmwh2NE4mWpJ+m6WEj1ZlTg0edJxK 8elu6IUHKozArZSDA6VVbYPskxbtCwTSMeKzgKZit1xXJcECK/PAqMqK/KulnufGQTnr e6D/3VLDYJqRP9646dC6tP1vae1a5DkOHzfCLtQrPrIXpmFa/ZGQZ6dZxlQpwwefqftc u8SUkvag8I8cKdc6JyKwFgMgvVcWvQ4T8r9FuRU0xpVCsIBdf6RAKE4yUccPwOwl/oLk YX7g== X-Gm-Message-State: APjAAAVHigxfX5fEvjLITos/6lXmUAG9MWe0P+zOZlVg6Vdz0NjSWBgE Y8TdmNxL4hQhYOnB9u3VH1+pg7sr X-Google-Smtp-Source: APXvYqxpaaPqTM9LAYNSVe+GK4+ZLsyHLnsprCvDBul8DV7gUAsYuHZeviWk4cbxlcMaHD58K6h+8A== X-Received: by 2002:a17:902:fe8c:: with SMTP id x12mr9964484plm.55.1572572522575; Thu, 31 Oct 2019 18:42:02 -0700 (PDT) Received: from [192.168.0.108] ([111.167.185.220]) by smtp.googlemail.com with ESMTPSA id j24sm4480522pff.71.2019.10.31.18.42.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Oct 2019 18:42:01 -0700 (PDT) Subject: Re: Restore replication settings when modifying a field type To: Kyotaro Horiguchi Cc: pgsql-hackers@postgresql.org References: <20191028.133939.559712139043653003.horikyota.ntt@gmail.com> From: Quan Zongliang Message-ID: Date: Fri, 1 Nov 2019 09:41:57 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191028.133939.559712139043653003.horikyota.ntt@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019/10/28 12:39, Kyotaro Horiguchi wrote: > Hello. > > # The patch no longer applies on the current master. Needs a rebasing. > > At Sat, 26 Oct 2019 16:50:48 +0800, Quan Zongliang wrote in >> In fact, the replication property of the table has not been modified, >> and it is still 'i'(REPLICA_IDENTITY_INDEX). But the previously >> specified index property 'indisreplident' is set to false because of >> the rebuild. > > I suppose that the behavior is intended. Change of column types on the > publisher side can break the agreement on replica identity with > subscribers. Thus replica identity setting cannot be restored > unconditionally. For (somewhat artifitial :p) example: > > P=# create table t (c1 integer, c2 text unique not null); > P=# alter table t replica identity using index t_c2_key; > P=# create publication p1 for table t; > P=# insert into t values (0, '00'), (1, '01'); > S=# create table t (c1 integer, c2 text unique not null); > S=# alter table t replica identity using index t_c2_key; > S=# create subscription s1 connection '...' publication p1; > > Your patch allows change of the type of c2 into integer. > > P=# alter table t alter column c2 type integer using c2::integer; > P=# update t set c1 = c1 + 1 where c2 = '01'; > > This change doesn't affect perhaps as expected. > > S=# select * from t; > c1 | c2 > ----+---- > 0 | 00 > 1 | 01 > (2 rows) > > >> So I developed a patch. If the user modifies the field type. The >> associated index is REPLICA IDENTITY. Rebuild and restore replication >> settings. > > Explicit setting of replica identity premises that they are sure that > the setting works correctly. Implicit rebuilding after a type change > can silently break it. > > At least we need to guarantee that the restored replica identity > setting is truly compatible with all existing subscribers. I'm not > sure about potential subscribers.. > > Anyway I think it is a problem that replica identity setting is > dropped silently. Perhaps a message something like "REPLICA IDENTITY > setting is lost, please redefine after confirmation of compatibility > with subscribers." is needed. > In fact, the scene we encountered is like this. The field of a user's table is of type "smallint", and it turns out that this range is not sufficient. So change it to "int". At this point, the REPLICA IDENTITY is lost and the user does not realize it. When they found out, the logical replication for this period of time did not output normally. Users have to find other ways to get the data back. The logical replication of this user is to issue standard SQL statements to other relational databases using the plugin developed by himself. And they have thousands of tables to replicate. So I think this patch is appropriate in this scenario. As for the matching problem between publishers and subscribers, I'm afraid it's hard to solve here. If this is not a suitable modification, I can withdraw it. And see if there's a better way. If necessary, I'll modify it again. Rebase to the master branch. > regards. >