Check out PostgreSQL's LISTEN and NOTIFY:
https://www.postgresql.org/docs/9.6/static/sql-listen.html
https://www.postgresql.org/docs/9.6/static/sql-notify.html
A related HN discussion a few years ago: https://news.ycombinator.com/item?id=6689213