Dashboard + SSE feed for visualizing latency and rate metrics from PostgreSQL
channels you LISTEN on.
-
Make sure your database emits
NOTIFYevents.The app listens on PostgreSQL channels and expects JSON payloads with a
created_atfield formatted as RFC3339 or RFC3339Nano.Example trigger function:
CREATE OR REPLACE FUNCTION notify_row_change() RETURNS trigger LANGUAGE plpgsql AS $$ DECLARE ts timestamptz; BEGIN ts := COALESCE(NEW.created_at, OLD.created_at, NOW()); PERFORM pg_notify( 'channel_name', json_build_object( 'created_at', to_char(ts, 'YYYY-MM-DD"T"HH24:MI:SS.USOF') )::text ); RETURN COALESCE(NEW, OLD); END; $$;
Attach it to a table:
CREATE TRIGGER my_table_notify_trigger AFTER INSERT OR UPDATE OR DELETE ON my_table FOR EACH ROW EXECUTE FUNCTION notify_row_change();
-
Create a
pg-notify.cfg.{ "database_url": "postgres://user:pass@your-host:5432/your_db?sslmode=require", "port": 8080, "event_names": ["channel_name", "channel_name2"] } -
Run the service.
go run .Or build it first:
go build ./pg-notify
-
Open the dashboard.
Visit:
http://localhost:<port>
For demoing the repository includes a small Postgres
image and helper scripts in db/.
Follow db/README.md to build and run the container, then run:
make demoThis starts the app and pushes synthetic activity into the demo database.
