Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swedishborgie/454275c7a668ae8b42150d1aba79de12 to your computer and use it in GitHub Desktop.
Save swedishborgie/454275c7a668ae8b42150d1aba79de12 to your computer and use it in GitHub Desktop.
--On Master
CREATE TABLE test (id SERIAL PRIMARY KEY, msg TEXT NOT NULL);
CREATE PUBLICATION testpub FOR TABLE test
--On Replica
CREATE TABLE test (id SERIAL PRIMARY KEY, msg TEXT NOT NULL);
CREATE SUBSCRIPTION testsub CONNECTION 'host=<host> user=<user> password=<test>' PUBLICATION testpub;
CREATE OR REPLACE FUNCTION notify_channel() RETURNS trigger AS $$
BEGIN
RAISE LOG 'Notify Triggered';
PERFORM pg_notify('testchannel', 'Testing');
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
DROP TRIGGER queue_insert ON TEST;
CREATE TRIGGER queue_insert AFTER INSERT ON test FOR EACH ROW EXECUTE PROCEDURE notify_channel();
ALTER TABLE test ENABLE ALWAYS TRIGGER queue_insert;
LISTEN testchannel;
--Execute insert on master:
INSERT INTO test (msg) VALUES ('test');
--Log from replica from postgresql-10-main.log:
--2018-07-24 07:45:15.705 EDT [6701] LOG: 00000: Notify Triggered
--2018-07-24 07:45:15.705 EDT [6701] CONTEXT: PL/pgSQL function notify_channel() line 3 at RAISE
--2018-07-24 07:45:15.705 EDT [6701] LOCATION: exec_stmt_raise, pl_exec.c:3337
@seregayoga
Copy link

@swedishborgie
Copy link
Author

Yep! That's the one.

@seregayoga
Copy link

Thanks! Sadly I still can reproduce it on 14beta1 postgres version (compiled from source).

@swedishborgie
Copy link
Author

Yep, the bug is still open. There's a patch available in the comment chain which worked, but it wasn't accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment