Content-type: text/html Manpage of PGNOTIFYD

PGNOTIFYD

Section: Misc. Reference Manual Pages (1)
Index Return to Main Contents

 

NAME

pgnotifyd - Execute a command on PostgreSQL asyncronous notification

 

SYNOPSIS

pgnotifyd [-b] [-d <conninfo>] <event> [--] <command> [ <arg> ... ]

 

DESCRIPTION

pgnotifyd connects to the current PostgreSQL database, listening for the named asynchronous notification. When notification is received, it executes the given command.

pgnotifyd is useful as an alternative to running a script from a crontab(5) to poll PostgreSQL database for changes.

 

OPTIONS

-b
Fork to background

-d conninfo
Specify a PostgreSQL connection string. See the PostgreSQL documentation for more information.

Note that there are no options for emailing output to administrators. See the EXAMPLES sections for information on how to do this.

 

ENVIRONMENT

The database connection is set using the environment variables and a connection string. The variables used are fully documented in the PostgreSQL manual, the most useful ones being:

PGHOST
Name of host to connect to.

PGPORT
Port number to connect to at the server host, or socket file name extension for Unix-domain connections.

PGDATABASE
The database name.

PGUSER
PostgreSQL user name to connect as.

PGPASSWORD
Password to be used if the server demands password authentication.

The envrionment variables are also inherited by the command run by pgnotifyd, and this can be useful.

 

BUFFERING OF NOTIFICATIONS

Asynchronous notifications are despatched when the transaction completes. When pgnotifyd receives multiple notifications (perhaps due to blocking caused by a previous execution) it will call the command only once.

 

EXAMPLES

Wait for user_change notification, and run the sync-htpasswd scripts.

pgnotifyd user_change sync-htpasswd

As above, connecting to a specific database (/bin/sh syntax):

PGDATABASE=members pgnotifyd user_change sync-htpasswd

Call a shell command on passwd_change notification:

pgnotifyd user_change sh -c 'list-users | sync-mail list'

Call a command and email any output to to the administrator, similar to crond(8) behaviour:

pgnotifyd user_change sh -c 'sync-htpasswd 2>&1 | mail -E root'

Asynchronous notifications can be sent using a trigger; eg.

CREATE OR REPLACE FUNCTION async_notify()
RETURNS TRIGGER
AS $$
BEGIN
    EXECUTE 'NOTIFY ' || TG_ARGV[0];
    RETURN NEW;
END
$$ LANGUAGE plpgsql;

CREATE TRIGGER user_change
    AFTER INSERT OR UPDATE OR DELETE ON user
    EXECUTE PROCEDURE async_notify('user_change');

 

HOMEPAGE

http://www.pogo.org.uk/~mark/pgnotifyd/

 

AUTHOR

Mark Hills <mark@pogo.org.uk>


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
ENVIRONMENT
BUFFERING OF NOTIFICATIONS
EXAMPLES
HOMEPAGE
AUTHOR

This document was created by man2html, using the manual pages.
Time: 19:32:55 GMT, October 27, 2017