Skip to content

Commit

Permalink
Schema auto-reload instructions (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
begriffs committed Mar 11, 2018
1 parent 16cf1ef commit 7b2ab94
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,29 @@ To refresh the cache without restarting the PostgREST server, send the server pr
killall -HUP postgrest
In the future we're investigating ways to keep the cache updated without manual intervention.
The above is the manual way to do it. To automate the schema reloads, use a database trigger like this:

.. code-block:: postgresql
CREATE OR REPLACE FUNCTION public.notify_ddl_postgrest()
RETURNS event_trigger
LANGUAGE plpgsql
AS $$
BEGIN
NOTIFY ddl_command_end;
END;
$$;
CREATE EVENT TRIGGER ddl_postgrest ON ddl_command_end
EXECUTE PROCEDURE public.notify_ddl_postgrest();
Then run the `pg_listen <https://github.com/begriffs/pg_listen>`_ utility to monitor for that event and send a SIGHUP when it occurs:

.. code-block:: bash
pg_listen <db-uri> ddl_command_end "killall -HUP postgrest"
Now, whenever the structure of the database schema changes, PostgreSQL will notify the ``ddl_command_end`` channel, which will cause ``pg_listen`` to send PostgREST the signal to reload its cache.

Alternate URL Structure
=======================
Expand Down

0 comments on commit 7b2ab94

Please sign in to comment.