Skip to content

begriffs/pg_listen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg_listen: trigger a shell command on a Postgres event

Super fast and lightweight. Written in C using libpq.

Usage

pg_listen postgres://db-uri channel [/path/to/program] [args]

# for example, to note when NOTIFY happened on "hello" channel
# pg_listen postgres://localhost/postgres hello /bin/echo they said hi

# print payload from the channel
# (default action when no command is specified)
# pg_listen postgres://localhost/postgres fun

Note that pg_listen line-buffers its output, so the payload raised by NOTIFY needs to include a final newline ("\n"). The program won't output anything until a newline is encountered.

-- incorrect
NOTIFY foo, 'hi';

-- correct
NOTIFY foo, E'hi\n';

Building

Requirements:

  • PostgreSQL and libpq.
  • pkg-config
  • $PKG_CONFIG_PATH including the directory containing libpq.pc
  • C89 and POSIX

Just clone the repo and run:

./configure
make

About

Trigger shell command from NOTIFY

Resources

License

Stars

Watchers

Forks

Packages

No packages published