检查连接是否在libpqxx(postgres)中处于活动状态

Check a Connection is still active or not in libpqxx (postgres)

本文关键字:活动状态 postgres 连接 是否 libpqxx 检查      更新时间:2023-10-16

如何检查特定连接是否已完成其工作或在 postgres 中仍处于活动状态?我正在创建与数据库的连接数组,并且我想获得一个不在任何事务中的连接。我正在使用C++和libpqxx库来连接数据库。谁能告诉我如何检查这个。

我想做这样的事情,

 connection* conList;
    for(int i=0;i<10;i++)
        {
            conList[i]=new connection("dbname=test user=postgres password=abc123 hostaddr=127.0.0.1 port=5432");
        }
    int i=0;
    while(true)
    {
      if(conList[i] has not any active transaction )
      {
       //do something   
      }
     i++;
    }

假设 tbis 是因为您有一个多线程应用程序,您将需要知道哪个线程具有哪个连接。就用它。