PQEventmonitor not working (LISTEN/NOTIFY) lazarus / 16-Databases ---------------------------------------------------------------------- heejit · 2018-07-28 19:52 No notification received Following is code Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);var  epq : PQEventMonitor.TPQEventMonitor;  pqcon : PQConnection.TPQConnection;begin  pqcon := PQConnection.TPQConnection.Create(nil);  pqcon.HostName:='127.0.0.1';  pqcon.DatabaseName:='db-name';  pqcon.UserName:='user-name';  pqcon.Connected:=True;   epq := PQEventMonitor.TPQEventMonitor.Create(pqcon);  epq.Connection := pqcon;  epq.Events.Add('info');  epq.Registered:=True;  epq.OnEventAlert:=@event_handler;  end; procedure TForm1.event_handler(Sender: TObject; EventName: string;  EventCount: longint; var CancelAlerts: boolean);begin  writeln(EventName);end; ---------------------------------------------------------------------- goodname · 2018-08-07 12:17 What server side triggers have you created? https://www.postgresql.org/docs/9.3/static/event-triggers.html https://www.postgresql.org/docs/9.3/static/triggers.html ---------------------------------------------------------------------- heejit · 2018-08-07 17:27 I thought this unit is Listener of postgresql Notify command How is related to trigger? ---------------------------------------------------------------------- goodname · 2018-08-07 19:29 Have just looked at the Lazarus code and TPQEventMonitor uses the LISTEN and UNLISTEN commands which means your right it has nothing to do with event triggers. Have not used this feature so someone else will have to answer. ---------------------------------------------------------------------- griff365 · 2021-08-28 14:28 You have to explicitly set the KeepConnection option on the Postgres DB Connection to True. The default is False.   pqcon := PQConnection.TPQConnection.Create(nil);   pqcon.HostName:='127.0.0.1';   pqcon.DatabaseName:='db-name';   pqcon.UserName:='user-name';   pqcon.KeepConnection := true;   pqcon.Connected:=True; The PQEventMonitor.Poll code only checks for NOTIFY events if the database is currently connected. Setting KeepConnection := true ensures that the connection will remain open even if there are no open datasets. This shouldn't be required, because PQEventMonitor creates it's own dedicated persistent connection anyway. PQEventMonitor only reads the connection information from the Postgres DB Connection component for establishing it's own connection, and doesn't use it for any other purpose. The problem in the PQEventMonitor code is here: procedure TPQEventMonitor.Poll; var   notify:PpgNotify;   CancelAlerts:boolean; begin   if FConnection.Connected and FRegistered and (PQconsumeInput(FDBHandle)=1) then     begin     CancelAlerts:=false;     repeat       notify:=PQnotifies(FDBHandle);       if assigned(notify) then I'm thinking this line of code could be changed as follows and the KeepConnection flag wouldn't need to be set.   if FRegistered and (PQconsumeInput(FDBHandle)=1) then