0

I want to listen to every transaction that is recorded in the database And I noticed that there is a concept in Postgres under the title LISTEN and NOTIFY (Of course, I am not sure that this is the right way)

Now I want to write a trigger that sends a notification to the channel when any operation occurs in any table

Is it possible?

My way is right?

thanks

Postgres TRIGGER to call NOTIFY with a JSON payload

3
  • 2
    It surely is possible. You may have a look here for a close example. Instead of inserting into an audit table you may perform pg_notify('the_channel_name', to_json(new)::text) or similar. This SO thread is related to your question too so that you can figure out what is relevant for your case. Commented Dec 20, 2022 at 16:02
  • I want to write a service like Debezium debezium.io Do you think I should use this? datacater.io/blog/2021-09-02/… Commented Dec 21, 2022 at 12:19
  • 1
    I have not tried CDC using logical replication but it does look to me to be the a very good and powerful possibility. Might be a lot better than the trigger approach that I commented first. Commented Dec 21, 2022 at 12:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.