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 1hdWF9-0004re-5z for pgsql-general@arkaria.postgresql.org; Wed, 19 Jun 2019 08:46:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdWF5-0001vZ-TY for pgsql-general@arkaria.postgresql.org; Wed, 19 Jun 2019 08:46:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdWF5-0001vQ-K0 for pgsql-general@lists.postgresql.org; Wed, 19 Jun 2019 08:46:55 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdWF1-0004l1-FN for pgsql-general@lists.postgresql.org; Wed, 19 Jun 2019 08:46:53 +0000 Received: from smadev.internal.net (pc131.internal.net [10.9.200.131]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTPS id x5J8khZY006188 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 19 Jun 2019 11:46:49 +0300 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id x5J8khMA085260 for ; Wed, 19 Jun 2019 11:46:43 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) Subject: Re: unexpected behavior with pglogical -- bug? To: pgsql-general@lists.postgresql.org References: From: Achilleas Mantzios Message-ID: Date: Wed, 19 Jun 2019 11:46:43 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------EA166C08787876CA9E36B1E9" Content-Language: en-US X-Virus-Scanned: clamav-milter 0.100.3 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-23.6 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_NAUTICAL,DYN_SPAM_SUBJ,DYN_SPAM_WATCHES8, HTML_FONT_FACE_BAD,HTML_MESSAGE,TW_TR autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------EA166C08787876CA9E36B1E9 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hello have you tried the same with logical replication in postgresql >= 10? On 16/6/19 11:45 μ.μ., Torsten Förtsch wrote: > Hi, > > out of curiosity I created the following setup, all with 9.6 and pglogical. > > D1 is configured as provider with a replication set that contains only 1 table. Only inserts are replicated. > > D2 is configured as subscriber for that replication set. Replication works, all inserts on D2 arrive also on D2. > > Now, I add the following always firing trigger to the table: > > CREATE OR REPLACE FUNCTION notify.trgfn () RETURNS trigger AS $def$ > BEGIN >     PERFORM pg_notify(NEW.channel, NEW.msg); >     RETURN NULL; > END > $def$ LANGUAGE plpgsql; > > CREATE TRIGGER trg BEFORE INSERT ON notify.notify > FOR EACH ROW > EXECUTE PROCEDURE notify.trgfn(); > > ALTER TABLE notify.notify ENABLE ALWAYS TRIGGER trg; > > As you can see, the trigger function should prevent the actual insert and only call pg_notify(). In principle this works but there is a catch. Notifications generated this way are only delivered > after another notification genuinely generated on the subscriber node. The channel of this notification does not matter. If I replace PERFORM pg_notify() by RAISE NOTICE I see the message > immediately in the log. > > First I thought this is related to session_replication_role=replica. So, I tried the direct insert on D2 with this setting using psql. The notification was fired immediately. Also, whether the > trigger prevents or allows the actual insert does not matter. I tried to create the trigger function as SECURITY DEFINER and with a specific search_path. That didn't help either. > > By now I am thinking there must be something missing in pglogical. > > Thanks, > Torsten -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt --------------EA166C08787876CA9E36B1E9 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Hello

have you tried the same with logical replication in postgresql >= 10?

On 16/6/19 11:45 μ.μ., Torsten Förtsch wrote:
Hi,

out of curiosity I created the following setup, all with 9.6 and pglogical.

D1 is configured as provider with a replication set that contains only 1 table. Only inserts are replicated.

D2 is configured as subscriber for that replication set. Replication works, all inserts on D2 arrive also on D2.

Now, I add the following always firing trigger to the table:

CREATE OR REPLACE FUNCTION notify.trgfn () RETURNS trigger AS $def$
BEGIN
    PERFORM pg_notify(NEW.channel, NEW.msg);
    RETURN NULL;
END
$def$ LANGUAGE plpgsql;

CREATE TRIGGER trg BEFORE INSERT ON notify.notify
FOR EACH ROW
EXECUTE PROCEDURE notify.trgfn();

ALTER TABLE notify.notify ENABLE ALWAYS TRIGGER trg;

As you can see, the trigger function should prevent the actual insert and only call pg_notify(). In principle this works but there is a catch. Notifications generated this way are only delivered after another notification genuinely generated on the subscriber node. The channel of this notification does not matter. If I replace PERFORM pg_notify() by RAISE NOTICE I see the message immediately in the log.

First I thought this is related to session_replication_role=replica. So, I tried the direct insert on D2 with this setting using psql. The notification was fired immediately. Also, whether the trigger prevents or allows the actual insert does not matter. I tried to create the trigger function as SECURITY DEFINER and with a specific search_path. That didn't help either.

By now I am thinking there must be something missing in pglogical.

Thanks,
Torsten


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt
--------------EA166C08787876CA9E36B1E9--