简体   繁体   中英

Is it possible to add a postgresql trigger to notify my Django app when a table changes?

My Django app connects to a PostgreSQL 9.x database. To this database, a legacy Java app is connected, too. So two different apps use the same database.

Is it possible for PostgreSQL to notify my Django (2.2.x) app when a table changes? I know that I can create a cron job to check on tables on a timely basis, but the Server administrator does not let me do cron jobs (why?) and the Java guy is too busy on other things to do code rewiring (so I can't ask him him to send me url requests after table changes).

Or any other idea would be much appreciated. Thanks.

EDIT: After some google-search I found this tool: pgsql-http but the database admin won't install it.

You can use triggers to NOTIFY when INSERTs, UPDATEs, or DELETEs occur. But something needs to LISTEN to the notices, on a persistent connection. I don't know how easy it is arrange for that to happen under Django.

I know that I can create a cron job to check on tables on a timely basis, but the Server administrator does not let me do cron jobs

You can run cron on any other box on the network you have access to, and have it use curl or wget to hit an endpoint on Django on production, which then does whatever it is you want done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM