[GENERAL] Potential bug with pg_notify - Mailing list pgsql-general

From François Beaulieu
Subject [GENERAL] Potential bug with pg_notify
Date
Msg-id 5CC14681-F93E-4B95-8D15-40284A5E9E6C@sbktelecom.com
Whole thread Raw
Responses Re: [GENERAL] Potential bug with pg_notify  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
Hi all,

I’m trying to feed a worker process on another server using pg_notify in a trigger. I’m running pgsql 9.4 and hitting
somebehaviour that I’m hoping is just a bug that can be solved with an upgrade, but I’m not finding any references to
itbeing a known bug and the uptime on my database server is critical so I can’t upgrade on a whim. Basically, the
triggerruns on every row insert and notifies me with a few fields from the row. This works perfectly most of the time,
butevery few hundred rows, the notify will return null values. Here are the details:
 

My database uses time-based partitioning (and subpartitioning) with pg_partman. This is done with a before insert
triggeron the main parent table. pg_partman creates subtables dynamically, so I can’t easily run my trigger on each
childtable. I also can’t run it after insert on my parent table because the row never makes it there. Thus, I ave
electedto run my trigger before insert on the parent table, and have named it so that it is alphabetically first and
willrun before the partitioning trigger. Works perfectly most of the time. Here are the trigger and associated plpgsql
function:

—CODE---
CREATE OR REPLACE FUNCTION notify_trigger() RETURNS trigger AS $$
DECLARE
BEGIN
  PERFORM pg_notify('watchers', TG_TABLE_NAME || ',' || NEW._id || ',' || NEW.userfield);
  RETURN new;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER aaa_notify BEFORE INSERT ON aaa FOR EACH ROW execute procedure notify_trigger();
—/CODE—

On my listener, every once in a while, this returns rows such as this:

AAA,17947227,XXX
AAA, , 
AAA,17947229,ZZZ 

Notice the second line, which appears to have even the autoincrement ‘_id' empty. It would seem to match _id = 17947228
andthat row does exist in the table and has data populated for all fields. 
 

Has anyone ever seen anything like this?

Thanks,
-=François Beaulieu
SBK Telecom


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] Fwd: Query parameter types not recognized
Next
From: rob stone
Date:
Subject: Re: [GENERAL] Fwd: Query parameter types not recognized