TPSQLNotify provides the interface to PostgreSQL Asynchronous Notification functionalities.
To learn how does PostgreSQL Asynchronous Notification work, please see Asynchronous Notification
section of PostgreSQL documentation.
Use TPSQLNotify to organize notifications between client applications about their actions
through Postgres database server.
To use TPSQLNotify you should do the following:
1. Create a rule for table on which changes you want to be notified:
create rule InsertDetect as on INSERT to notify_test do notify recinsert
2. Add recinsert to ListenList property of TPSQLNotify component;
3. Write event handler for OnNotify event:
procedure TForm1.PSQLNotify1Notify(Sender: TObject; Event: String; Pid : Integer);
if PID <> DB.GetBackendPID then // If it is not me...
Format('Client (PID=%d) just modified (event = %s) table notify_test. Press Refresh',
4. Link Database property of TPSQLNotify component to PSQLDatabase
5. To begin listen notifications, set Active property of TPSQLNotify to
After compilation you can see rows insertions in Memo1 component when other clients make
inserts in notify_test table. Also you can do the same for DELETE and UPDATE events.
Please note, that TPSQLNotify component is not thread-safe because of its internal implementation.