https://github.com/supabase/pg_listen
Trigger shell command from NOTIFY
https://github.com/supabase/pg_listen
Last synced: 10 months ago
JSON representation
Trigger shell command from NOTIFY
- Host: GitHub
- URL: https://github.com/supabase/pg_listen
- Owner: supabase
- License: mit
- Archived: true
- Fork: true (begriffs/pg_listen)
- Created: 2020-04-23T14:54:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-22T04:01:03.000Z (over 5 years ago)
- Last Synced: 2024-04-13T21:54:15.820Z (over 2 years ago)
- Language: C
- Size: 35.2 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## pg_listen: trigger a shell command on a Postgres event
Super fast and lightweight. Written in C using libpq.
### Usage
```bash
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.
```sql
-- incorrect
NOTIFY foo, 'hi';
-- correct
NOTIFY foo, E'hi\n';
```
### Building
For Supabase/KPS on Ubuntu use `make kps`
For everything else use:
Just clone the repo and run `make`. The makefile is compatible with BSD and GNU
Make and requires only that libpq be installed on the system.
If you use NixOS you can run `nix-shell` to build it.
If you installed PostgreSQL on Mac using homebrew or Macports, note that
pkg-config is not installed by default and needs to be installed by running
`brew install pkg-config` prior to running `make`. Additionally you may need to
update `$PKG_CONFIG_PATH` and add the directory containing `libpq.pc` for your
system.