Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNLmb-00040X-RZ for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Sep 2021 21:04:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mNLma-0006SI-8h for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Sep 2021 21:04:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNLmZ-0006S9-MC for pgsql-hackers@lists.postgresql.org; Mon, 06 Sep 2021 21:04:00 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mNLmV-0007AL-Sy for pgsql-hackers@postgresql.org; Mon, 06 Sep 2021 21:03:58 +0000 Received: by mail-ej1-x62e.google.com with SMTP id me10so15561535ejb.11 for ; Mon, 06 Sep 2021 14:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=2+50T5k8JqLjRJBROFh0NRxtBTwbTKtg/nDYXegDvNM=; b=TVyJPLFGeH7Z/6sUUThiJgrH3jbmwBV0osuyPsrF/bvY8GovOQzGgHBC/7g68k3Cfw 4iG1ltCnhNpjCi2yDFDIdAW/Vafl+d82xE+yfx+wLktCQYK0a5u4ue3fRAx/XNMkIDPD ZeS8q7VLADez+tYvKo6ILTazQaSnNufVdP/b2E2sbbrU2aQnOVIp4wh2XJ/1/6t2V0st WlYCFhEC7s1w9ZLZc/mo+vg25uwvc3oB0rUJaWoxoMOfMpVSz4yziMdAsFBwwcjQhS9p otZjLEbvxmQuWPAkcOW9zqRZqJBIzFC9BvnlLhwJXuJQYgX2w/zP+yBfhA6hh2oNGxVj WLqA== 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=2+50T5k8JqLjRJBROFh0NRxtBTwbTKtg/nDYXegDvNM=; b=brRcMuXk441qozSBxNHi5HptNbZxj3j0BwKtCOg4g5VrZFD+bpoSNxzXwxu9Z+pmIi Eye4q4CkHu8DQPiD4ouQFXUJP3wj4p5u8qMqJIxBj6YLCJ/wiOoeEGHGa0LjJ/2qM2Be 9W+Xu/IFquf03js3OQGXhLU+6nEqBBhYWerKH44MKPyz0PYQFOSiB3Me4/PQzVlaaHTQ CsB3EQIYnib8q7qL4SbMYfrgYA+S/bA0rSAoXuUPklhBN5seEg/+ZdHAXxvkLV+oyGeV Y4rpRrspsSmfMuvzGX4g5PaxlLr/Yk96aawqudns0ZBqkri+jT+OZ8u3e6YbETsMxNJz cDMQ== X-Gm-Message-State: AOAM532BfzQApEoK8yGFFeCpRvM5503+FJ55ew89HAvdob11OJkiYmkE IP5xqARbfoY7NVyq6+DMIPBFfR6Kk5WXFSNQ79jVvPzUXNoVgw1q5zPc1DeDV4ozsP2VCbPyxmc U/cuwBteGFdGGN4okThFwi5kx1x8ItVsyOHXRUFwipVKAQtEu/0w/tI7cQONNvuLNG+T53SyXgR eL74uznm3dJXsXN077Haxe4BtxQGqAcV3cW80gLYsP33tROkBNtgUy01RL0fWvHTDH3TIXFX1P1 J4DWFa8JpN5UWlkaHE4JT66WsF0EadkTs43BA== X-Google-Smtp-Source: ABdhPJyWEA/dy1rIuAz1CRxgkSDlE+HUVOVYUV8zoRhycpYk/GrRx+VQKFlXNmurGYVbsQtuHIa2yw== X-Received: by 2002:a17:906:520b:: with SMTP id g11mr15477706ejm.502.1630962233370; Mon, 06 Sep 2021 14:03:53 -0700 (PDT) Received: from [10.137.0.19] (ip-86-49-241-1.net.upcbroadband.cz. [86.49.241.1]) by smtp.gmail.com with ESMTPSA id p23sm5465731edw.94.2021.09.06.14.03.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Sep 2021 14:03:52 -0700 (PDT) Subject: Re: Column Filtering in Logical Replication To: Alvaro Herrera , Rahila Syed Cc: Amit Kapila , Peter Smith , PostgreSQL-development References: <202109061751.3qz5xpugwx6w@alvherre.pgsql> From: Tomas Vondra Message-ID: <4804c901-3888-21cd-08ad-52c3e96858ed@enterprisedb.com> Date: Mon, 6 Sep 2021 23:03:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <202109061751.3qz5xpugwx6w@alvherre.pgsql> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/6/21 7:51 PM, Alvaro Herrera wrote: > On 2021-Sep-06, Rahila Syed wrote: > >>>> ... ugh. Since CASCADE is already defined to be a >>>> potentially-data-loss operation, then that may be acceptable >>>> behavior. For sure the default RESTRICT behavior shouldn't do it, >>>> though. >>> >>> That makes sense to me. >> >> However, the default (RESTRICT) behaviour of DROP TABLE allows >> removing the table from the publication. I have implemented the >> removal of table from publication on drop column (RESTRICT) on the >> same lines. > > But dropping the table is quite a different action from dropping a > column, isn't it? If you drop a table, it seems perfectly reasonable > that it has to be removed from the publication -- essentially, when the > user drops a table, she is saying "I don't care about this table > anymore". However, if you drop just one column, that doesn't > necessarily mean that the user wants to stop publishing the whole table. > Removing the table from the publication in ALTER TABLE DROP COLUMN seems > like an overreaction. (Except perhaps in the special case were the > column being dropped is the only one that was being published.) > > So let's discuss what should happen. If you drop a column, and the > column is filtered out, then it seems to me that the publication should > continue to have the table, and it should continue to filter out the > other columns that were being filtered out, regardless of CASCADE/RESTRICT. > However, if the column is *included* in the publication, and you drop > it, ISTM there are two cases: > > 1. If it's DROP CASCADE, then the list of columns to replicate should > continue to have all columns it previously had, so just remove the > column that is being dropped. > > 2. If it's DROP RESTRICT, then an error should be raised so that the > user can make a concious decision to remove the column from the filter > before dropping the column. > FWIW I think this is a sensible behavior. I don't quite see why dropping a column should remove the table from publication (assuming there are some columns still replicated). Of course, it may break the subscriber (e.g. when there was NOT NULL constraint on that column), but DROP RESTRICT (which I assume is the default mode) prevents that. And if DROP CASCADE is specified, I think it's reasonable to require the user to fix the fallout. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company