Allow schema cache reloading with NOTIFY (#1542)

Fixes https://github.com/PostgREST/postgrest/issues/1512

Helps on environments where you can't send unix signals(Windows, managed
containers). Also provides better UX for schema reloads - NOTIFY
can be sent from pg clients(psql, pgadmin).

`NOTIFY pgrst` - with no payload - should be done to reload the schema cache.
Notifications with a payload will be ignored.

The channel can be enabled with `db-channel-enabled`(false by default)
and its name can be configured with `db-channel`.

The LISTEN thread uses a dedicated pg connection.
This connection is recovered if it fails.
A debounce of 1ms is done in case too many NOTIFYs arrive.
This commit is contained in:
Steve Chavez
2020-06-24 19:00:02 -05:00
committed by GitHub
parent 24064f8626
commit 43d71e95ac
13 changed files with 169 additions and 57 deletions
+2
View File
@@ -29,6 +29,8 @@ let
"PGRST_DB_POOL=100"
"PGRST_DB_POOL_TIMEOUT=10"
"PGRST_DB_EXTRA_SEARCH_PATH=public"
"PGRST_DB_CHANNEL=pgrst"
"PGRST_DB_CHANNEL_ENABLED=false"
"PGRST_SERVER_HOST=*4"
"PGRST_SERVER_PORT=3000"
"PGRST_OPENAPI_SERVER_PROXY_URI="
+3
View File
@@ -12,6 +12,9 @@ db-pool = "$(PGRST_DB_POOL)"
db-pool-timeout = "$(PGRST_DB_POOL_TIMEOUT)"
db-extra-search-path = "$(PGRST_DB_EXTRA_SEARCH_PATH)"
db-channel = "$(PGRST_DB_CHANNEL)"
db-channel-enabled = "$(PGRST_DB_CHANNEL_ENABLED)"
server-host = "$(PGRST_SERVER_HOST)"
server-port = "$(PGRST_SERVER_PORT)"
+13
View File
@@ -12,6 +12,19 @@ let
ver = "0.3.0";
sha256 = "0iwh4wsjhb7pms88lw1afhdal9f86nrrkkvv65f9wxbd1b159n72";
} { };
# To get the sha256
# nix-prefetch-url --unpack https://hackage.haskell.org/package/hasql-notifications-0.1.0.0/hasql-notifications-0.1.0.0.tar.gz
hasql-notifications =
self.haskell.lib.overrideCabal
(
prev.callHackageDirect
{
pkg = "hasql-notifications";
ver = "0.1.0.0";
sha256 = "1z17gsqvvzzi0yipc3qy3jz8vzpww4vsc4vaj2kbzr2mfliq6fx3";
} { }
)
(old: { doCheck = false; });
} // extraOverrides final prev;
in
{
+3
View File
@@ -31,4 +31,7 @@
# https://github.com/nh2/static-haskell-nix/pull/91
static-haskell-nix-postgrest-openssl-linking-fix =
./static-haskell-nix-postgrest-openssl-linking-fix.patch;
static-haskell-nix-hasql-notifications-openssl-linking-fix =
./static-haskell-nix-hasql-notifications-openssl-linking-fix.patch;
}
@@ -0,0 +1,28 @@
From 49ecb703d9d0bfd38eb69ba5cb63a8262bd03f96 Mon Sep 17 00:00:00 2001
From: steve-chavez <stevechavezast@gmail.com>
Date: Thu, 11 Jun 2020 13:18:07 -0500
Subject: [PATCH] Add hasql-notifications openssl linking fix
---
survey/default.nix | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/survey/default.nix b/survey/default.nix
index 828beaa..9c2d5f6 100644
--- a/survey/default.nix
+++ b/survey/default.nix
@@ -1054,6 +1054,11 @@ let
super.squeal-postgresql
[ final.openssl ]
"--libs openssl";
+ hasql-notifications =
+ addStaticLinkerFlagsWithPkgconfig
+ super.hasql-notifications
+ [ final.openssl ]
+ "--libs openssl";
xml-to-json =
addStaticLinkerFlagsWithPkgconfig
--
2.19.3
+1
View File
@@ -18,6 +18,7 @@ let
static-haskell-nix
[
patches.static-haskell-nix-postgrest-openssl-linking-fix
patches.static-haskell-nix-hasql-notifications-openssl-linking-fix
];
patchedNixpkgs =