Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am studying ways to implement audit tables to my PostgreSQL database and would like to know if it is possible to make a trigger for the data to be written to a table in a database other than the source database.

share|improve this question

You can do that with the help of the additional module dblink. Install once per database (the one where the trigger is executed):


You need superuser privileges (in the database cluster where the trigger runs) for some of the involved functionality.

Since you want to write to the external database, you will probably want to use dblink_exec(). The manual has code examples.

Or try a search here for more dblink examples.

Note that you cannot ROLLBACK what you have written with dblink to an external database. A local exception after the external write does not undo what's written in the foreign database.

share|improve this answer
Thank you, i'll read more about it and perform some tests. – Rafa Marques Nov 28 '12 at 17:55
Thank you so much! – Rafa Marques Mar 19 at 12:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.