【发布时间】:2021-12-30 07:32:11
【问题描述】:
在来自 postgres 触发器的监听通知期间,我们遇到错误 53300:抱歉,已经有太多客户端。请建议,如果我们能以某种方式解决它。在关闭连接对象时,它会停止发送通知。我们正在使用 Signal R 接收通知。
public async Task BrokerConfig()
{
var con = new NpgsqlConnection("host=x.x.x.x;Port=5432;Database=Ticket;User Id=someid;Password=pwd;Connection Idle Lifetime=0;Timeout=0;;Command Timeout=0;");
con.Notification += LogNotificationHelper;
con.Open();
using (var cmd = new NpgsqlCommand())
{
cmd.CommandText = "LISTEN notifytickets;";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
cmd.ExecuteNonQuery();
}
// Waiting for Event
con.WaitAsync();
}
static void LogNotificationHelper(object sender, NpgsqlNotificationEventArgs e)
{
///further code to read notification values..
}
【问题讨论】:
-
看看这似乎是相似的。 stackoverflow.com/questions/43725343/…
-
不是真的,我们正在使用通知,为此我们需要保持我的连接打开,直到发出通知。但是如果我们关闭我们的连接通知就不会再收到了。
-
一种解决方案是不打开与数据库的那么多连接。可以缓解这种情况的另一件事是 KeepAlive npgsql.org/doc/…
标签: c# notifications postgresql-9.1 listen