Postgresql – ADD and DROP triggers frequently on a database

postgresqltrigger

I have a table from which I am deleting the data. Whenever a row is deleted, the row matching the data from other tables must also be deleted. So I am planning to achieve the same using triggers. The trigger will be only on DELETE condition.

The application from which I am achieving the same runs 4-5 times a day. So, at the start of the application, I am adding the triggers and on exit of application, I am dropping the triggers (because triggers slow down the database performance).

This too much frequent adding and dropping triggers is OK for Postgres or is there any better idea to achieve the same?

There are other applications as well which keep on running and they are using the database. Other applications do only INSERT and UPDATE operations. Only my application does the deletion part. It is a utility for daily cleanups.

Best Answer

You may use

ALTER TABLE tblname ENABLE\DISABLE TRIGGER