收听者
Postgrest使用 LISTEN 重新加载 Schema Cache 和 Configuration 经由 NOTIFY .这在无法发送SIGUSR1或SIGUSR2 Unix信号的环境中很有用。比如在云托管容器或Windows系统上。
NOTIFY pgrst, 'reload schema'; -- reload schema cache
NOTIFY pgrst, 'reload config'; -- reload config
NOTIFY pgrst; -- reload both
By default, the LISTEN channel is enabled (数据库通道已启用) and named pgrst
(DB-通道).
打开阅读副本
的 LISTEN
和 NOTIFY
命令对PostgreSQL读取副本不起作用。因此,如果您将Postgrest连接到读复制副本,则收件箱将无法启动。
-- check if the instance is a replica
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
postgres=# LISTEN pgrst;
ERROR: cannot execute LISTEN during recovery
为了解决这个问题,您可以将收件箱连接到主服务器,同时仍使用 连接池 在复制品上。
这可以通过使用标准来完成 libpq multiple hosts 和 target_session_attrs 在你 connection string .
db-uri = "postgres://read_replica.host,primary.host/mydb?target_session_attrs=read-only"
这将导致 连接池 连接到读复制副本主机并 LISTEN
在备用主主机上。
备注
引擎盖下,Postgrest力量 target_session_attrs=read-write 为 LISTEN
上网时段
自动恢复
如果发生连接丢失,监听器将重新连接到数据库。
它将使用指数退避永远重试,两次重试之间的最大退避时间为32秒。每一次尝试都是 logged 。
可通过设置禁用自动恢复 数据库池-自动-恢复 至
false
。