1

I have a windows service running which reads configurations from a table from PostgreSQL. These settings are read only once at the time of service startup and for any change in them, the service needs to be restarted. I am looking for a mechanism in C# to monitor any changes on database. So that I would then fetch back the settings on database change.

One approach I was looking for, is to write/modify a text file from PostgreSQL trigger and then use FileWatcher to update the settings. But no success there either.

2

1 Answer 1

4

First, I created a perpetual listening connection with command listen <channel_name> by referring npgsql documentation

Then I wrote a trigger that would fire command

PERFORM pg_notify('<channel_name>', format('Changed: %s ', NEW.column_name));

So any change on the particular database's table was captured by the trigger, which in turn sent the notification to the channel and the c# code listened and processed it

Sign up to request clarification or add additional context in comments.

Comments

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.