Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a shell script when a database record is written to postgres

Tags:

postgresql

Is there some mechanism in postgres that can fire off a shell script when a database record is written? I can write a script to just monitor the database and table but before doing that I wanted to make sure there wasn't a "better" way.

like image 330
Ominus Avatar asked May 21 '26 19:05

Ominus


2 Answers

Write a trigger function using PL/sh. That's what it's for.

like image 155
Peter Eisentraut Avatar answered May 24 '26 08:05

Peter Eisentraut


You can probably use rule or trigger and start your shell script for whatever PL that supports it, but I think the better way is to use it for sending notification and monitor it from a separate process.

like image 36
Michael Krelin - hacker Avatar answered May 24 '26 07:05

Michael Krelin - hacker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!