标签: pg-notify

在 AWS Aurora/postgres 上监听/通知

我希望实现一个触发器,在 PostgreSQL 中的表更改时发出通知,但我无法找到它是否可以在集群中工作的任何明确答案。

PostgreSQL 监听/通知是否可以在 AWS Aurora(预配置和无服务器)上工作,我是否可以期望所有客户端都收到通知,无论它们连接到哪个实例?

如果是,是否存在任何主要的性能问题?

谢谢 :)

postgresql amazon-rds amazon-aurora pg-notify

9
推荐指数
1
解决办法
2717
查看次数

如何正确监听来自node.js的postgresql通知

目标:
当一条新记录插入到特定的 PostgreSQL 表中时,我希望 PostgreSQL 通知我的 Node.js Web 应用程序,以便它可以启动对外部服务的 API 调用。

据我了解,基本步骤是:

  1. 建立一个 PostgreSQL 触发器函数来执行 pg_notify() 方法。
  2. 建立一个PostgreSQL触发器,在表插入后执行触发器函数。
  3. 在 Node.js 中建立一种机制来监听特定于通道的 PostgreSQL 通知。

这是我对每一步的尝试:

  1. notification_app_after_table_insert.pgsql中的触发函数

    CREATE OR REPLACE FUNCTION notify_app_after_table_insert()
    RETURNS TRIGGER AS
    $BODY$
        BEGIN
            PERFORM pg_notify('channel', row_to_json(NEW)::text);
            RETURN new;
        END;
    $BODY$
    LANGUAGE plpgsql
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在trigger_notify_app_after_table_insert.sql中触发

    CREATE TRIGGER trigger_notify_app_after_table_insert
    AFTER INSERT
    ON table
    FOR EACH ROW
    EXECUTE PROCEDURE notify_app_after_table_insert();
    
    Run Code Online (Sandbox Code Playgroud)
  3. index.js 中的侦听器机制(在我的网络应用程序的后端内)

    //tools
    const express = require('express');
    const app = express();
    const cors = require('cors');
    const bodyParser = require('body-parser');
    const port = …
    Run Code Online (Sandbox Code Playgroud)

postgresql listen notify node.js pg-notify

6
推荐指数
1
解决办法
4293
查看次数

Postgred pg_notify/listen only working if channel name is lower case

I've read https://www.postgresql.org/docs/9.6/static/sql-notify.html and the channel name is just described as an 'identifier'.

I'm using NodeJS and pg https://www.npmjs.com/package/pg to access postgres.

If I use a lower case word in both, e.g. pg_notify('foo', ... and LISTEN foo it works. I've tested all combinations:

pg_notify  LISTEN  outcome
lower      lower   works
lower      upper   works
upper      lower   fails
upper      upper   fails
Run Code Online (Sandbox Code Playgroud)

Is this a bug, or is it a logical result of being an 'identifier'? (If so, should this be documented on pg_notify …

postgresql notify node.js pg-notify

2
推荐指数
1
解决办法
2232
查看次数