Run external program on trigger in Postgresql

半世苍凉 提交于 2020-01-07 02:47:07

问题


When a new row is added to our Postgres database, I want to run a bash script. Is there any sort of system() function in PostgreSQL that would allow me to do this?

To give more context, when a new row is created in the database, I need to make a new file containing information from that row on an external server via SSH.

An alternate solution would just be to have a cron job run every 5 minutes or so and check for new rows, but then it might not catch if someone deletes a row, and then adds a row.


回答1:


It looks like there is no way to do this. The simplest way I can find is to use Postgres' NOTIFY command, and then write a daemon in some other language to listen for those notifications.

The cool thing about those notifications is that you can send a 'payload' with them, which can include anything you want, so you could send "ROW CREATED: ID# 455029" and then your daemon would know to SELECT that row to get more info about it. Neato



来源:https://stackoverflow.com/questions/32337476/run-external-program-on-trigger-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!