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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.