Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql - detect changes and call webservice

Tags:

postgresql

I have a PostgreSQL database. What I want to do is, detect any changes (insert, update) that happen in the database and then call a webservice. How could I do this?

Thanks in advance for any help.

like image 288
diego10 Avatar asked Mar 19 '13 16:03

diego10


People also ask

Does Postgres have a transaction log?

Write-Ahead Log (WAL) is a very important term in transaction processing. In PostgreSQL, it is also known as a transaction log. A log is a record of all the events or changes and WAL data is just a description of changes made to the actual data.

What is Createdb in PostgreSQL?

createdb creates a new PostgreSQL database. Normally, the database user who executes this command becomes the owner of the new database. However, a different owner can be specified via the -O option, if the executing user has appropriate privileges. createdb is a wrapper around the SQL command CREATE DATABASE .

Can Postgres call an API?

PostgreSQL REST API connection allows to create Restful applications with PostgreSQL as a database. A REST API (also known as RESTful API) is an application programming interface (API or web API) . The API follows the constraints of REST architectural style and allows for interaction with RESTful web services.


1 Answers

You should be able to use triggers and the listen/notify functionality in PostgreSQL to achieve something like this:

  1. A set of insert/update/delete triggers create a notification event whenever anything changes in your table, using the created/changed/deleted ID as the payload.

  2. A background process checks for notifications periodically (here's an example using Java/JDBC), and then loads the changed record from the database to do the web service call.

This is not in any way a real-time push-type system, but you have to poll the database for notification events to trigger the webservice call. It will do the trick, though.

like image 100
Henning Avatar answered Sep 19 '22 13:09

Henning