Giuseppe
Giuseppe

Reputation: 393

PostgreSQL trigger execute operations on different database

How can I execute operation on a different database on specific trigger? When a value is inserted in my table, I want to insert the same data in another db and table (applying a logic before doing it).

Upvotes: 0

Views: 3373

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246318

You would update the table in the second database via postgres_fdw.

But stop and think before you implement a solution like that.

The consequence is that the transaction that inserts the value won't finish before the value is inserted in the remote table. That will slow down the transaction considerably, and if the remote database is down for some reason, your INSERT will fail.

Data duplication is normally a problem. Usually it is a better solution to store them only once. What keeps you from using postgres_fdw to access the data from another database?

Upvotes: 2

Related Questions