PostgreSQL Notifications and QGIS

Feb 22, 2024 | QGIS

This usually turns up in the QGIS world every two years – So it’s my turn to talk about it. This month I did an emergency install of the TN 911 database. Basically client had a problem, we solved it in the most elegant way possible, and I’m still sorting out a few things. Generally it went smooth. We went from no database to being able to edit the existing data in half a day.

There were a few problems and I decided to sit down today and fix what I could. I think I’ve been actively using postgis for like 8 years now and there’s still things I learn. So after rewriting a couple of functions that recorded time stamps for metadata I started thinking about “multiuser”. When I did the first install we had about 4 people editing one fateful summer and I learned a lot on the human side of editing.

Today I added three more triggers to the setup which reference this post kartoza did a few years ago. I set up a signal/notification so that anytime an edit happens (be it insert, delete, or update) it fire’s off a signal to update qgis. Usually you have to manually refresh.

CREATE FUNCTION public.notify_qgis() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
        BEGIN NOTIFY qgis;
        RETURN NULL;
        END;
    $$;

CREATE TRIGGER notify_qgis_address_edit
  AFTER INSERT OR UPDATE OR DELETE ON tn911.address_points
    FOR EACH STATEMENT EXECUTE PROCEDURE public.notify_qgis();

Once that is set up, updates are visible if you have two people editing. I pulled up two QGIS sessions to show you editing. All this happens on a Save:

So that’s this years look at notifications. Make an edit. Have postgresql fire off a notification. QGIS Updates.

You may also like

Watershed GIS Part 1

Watershed GIS Part 1

I typically spend June wondering about what I'm doing, have done, and need to do work wise. One thing I keep thinking about is "the old days". By old days I mean the start of my career which was doing a lot of Watershed Mapping. Back in the mid 90's we would be...

Mergin Maps Training Class

Mergin Maps Training Class

I had a boss that would always start off with "So the Short story is...." and you'd be stuck for at least 30 minutes and maybe an hour listening to a story that didn't go anywhere. So the short story on the Mergin Maps Class.......... NRGS is a Mergin Maps partner. A...

Unintended Joy

Unintended Joy

I was originally going to call this unintended consequences but - there was a small amount of joy at the end. In Tennessee you have 6 layers that are required by the NG 911 group. So you end up with a lot of information depending on the county being poured into the...