Guest User

Untitled

a guest
Jul 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. --On Master
  2. CREATE TABLE test (id SERIAL PRIMARY KEY, msg TEXT NOT NULL);
  3. CREATE PUBLICATION testpub FOR TABLE test
  4.  
  5. --On Replica
  6. CREATE TABLE test (id SERIAL PRIMARY KEY, msg TEXT NOT NULL);
  7. CREATE SUBSCRIPTION testsub CONNECTION 'host=<host> user=<user> password=<test>' PUBLICATION testpub;
  8. CREATE OR REPLACE FUNCTION notify_channel() RETURNS trigger AS $$
  9. BEGIN
  10. RAISE LOG 'Notify Triggered';
  11. PERFORM pg_notify('testchannel', 'Testing');
  12. RETURN NEW;
  13. END;
  14. $$ LANGUAGE 'plpgsql';
  15. DROP TRIGGER queue_insert ON TEST;
  16. CREATE TRIGGER queue_insert AFTER INSERT ON test FOR EACH ROW EXECUTE PROCEDURE notify_channel();
  17. ALTER TABLE test ENABLE ALWAYS TRIGGER queue_insert;
  18. LISTEN testchannel;
  19.  
  20. --Execute insert on master:
  21. INSERT INTO test (msg) VALUES ('test');
  22.  
  23. --Log from replica from postgresql-10-main.log:
  24. --2018-07-24 07:45:15.705 EDT [6701] LOG: 00000: Notify Triggered
  25. --2018-07-24 07:45:15.705 EDT [6701] CONTEXT: PL/pgSQL function notify_channel() line 3 at RAISE
  26. --2018-07-24 07:45:15.705 EDT [6701] LOCATION: exec_stmt_raise, pl_exec.c:3337
Add Comment
Please, Sign In to add comment