【问题标题】:postgres listen notification generates error - 53300: sorry, too many clients alreadypostgres 监听通知生成错误 - 53300:抱歉,已经有太多客户端
【发布时间】: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


【解决方案1】:

您可以在 postgres 配置中增加允许的最大连接数

*max_connections (integer)*

Determines the maximum number of concurrent connections to the database server. The default is typically 100 connections, but might be less if your kernel settings will not support it (as determined during initdb). This parameter can only be set at server start.

When running a standby server, you must set this parameter to the same or higher value than on the master server. Otherwise, queries will not be allowed in the standby server.

here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-29
    • 2012-04-05
    • 2020-07-05
    • 2011-02-14
    • 2019-05-21
    • 2018-06-20
    • 2012-10-06
    相关资源
    最近更新 更多