admin管理员组

文章数量:1294341

I am working on a live dashboard which records changes in database and shows details related to it on the dashboard. Currently to get these live changes I am using a combination of triggers, functions and pg_notify to generate notifications from postgres when some tables have CRUD operations in them.

All of this is working okay for now, but based on some suggestions I read online many people do not recommend to use triggers if it is possible, as they are hard to maintain and don't sit best with rest of our code base. So for this reason I want to try updating my trigger based approach with something which fits with my code better and easier to maintain. But I don't know what I can use instead of triggers to get live changes from database.

Most triggers in my database are just used to send postgres notification back to my backend where I am handling the changes directly, so if I can get the changes from the database without using triggers I think I can make it work, but I can't figure out how to do so.

Also, if you think that trigger based approach is better for my case then please inform me the same with why.

I am working on a live dashboard which records changes in database and shows details related to it on the dashboard. Currently to get these live changes I am using a combination of triggers, functions and pg_notify to generate notifications from postgres when some tables have CRUD operations in them.

All of this is working okay for now, but based on some suggestions I read online many people do not recommend to use triggers if it is possible, as they are hard to maintain and don't sit best with rest of our code base. So for this reason I want to try updating my trigger based approach with something which fits with my code better and easier to maintain. But I don't know what I can use instead of triggers to get live changes from database.

Most triggers in my database are just used to send postgres notification back to my backend where I am handling the changes directly, so if I can get the changes from the database without using triggers I think I can make it work, but I can't figure out how to do so.

Also, if you think that trigger based approach is better for my case then please inform me the same with why.

Share Improve this question asked Feb 12 at 12:56 Tea TechTea Tech 1127 bronze badges 1
  • Online, people recommend a lot of things much of it nonsense. If you understand the process and it does what you want then you are way ahead of most Internet advice and you should consider staying with what you are doing. – Adrian Klaver Commented Feb 12 at 16:06
Add a comment  | 

1 Answer 1

Reset to default 0

You can use logical decoding to replicate data modifications. If you don't want to write your own logical decoding plugin, you can use existing solutions like wal2json or tools like Debezium that can use the built-in pgoutput plugin.

Note that you will only get data modifications that way. Data definition statements (CREATE, ALTER and DROP) are not captured.

本文标签: djangoGet table changes details without using triggers in postgresStack Overflow