---
title: 如何统计单个 OBProxy 当前的连接数-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于如何统计单个 OBProxy 当前的连接数相关的常见问题和使用技巧，帮助您快速解决如何统计单个 OBProxy 当前的连接数的难题。
---
切换语言

- 简体中文
- English

划线反馈

# 如何统计单个 OBProxy 当前的连接数

更新时间：2026-06-03 03:01

适用版本： V1.4.x、V2.1.x、V2.2.x、V3.1.x、V3.2.x、V4.0.x、V4.1.x、V4.2.x 内容类型：How-to  

实际生产和测试中，经常需要统计一个 OBProxy 集群中各个 OBProxy 的连接数，据此判断客户应用当前所有的连接是否均衡地发给了所有的 OBProxy，以及粗略判断当前系统的繁忙程度。

## 原理与实现

客户的应用程序连接到 OceanBase 数据库的完整链路一般包括 Client、LB 负载均衡设备、由多个 OBProxy 租户的 OBProxy 集群、OBServer 集群等多个组件，不难看出，从应用到 OceanBase 数据库的链路一般较长，中间会经过多次网络报文的转发：

![image001](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/knowledge-base/database/odp/20240429odp001.png)

这里 Client/LB -> OBProxy 维持的连接以及会话统称为 Client Session；OBProxy 可能和多个 OBServer 同时维持会话和连接，这里统称为 Server Session。

统计一个 OBProxy 当前的连接数时，一定要注意以下两点：

- 一个 OBProxy 集群本质上是一个个独立的 OBProxy 进程，多个 OBProxy 之间的连接是互不感知的，组成集群只是为了方便进行运维管理和参数的修改。
 - OBProxy 看到的连接是客户端连进来的，而 OBServer 看到的连接是 OBProxy 连进来的，这边的连接是两段不同的 TCP 连接。

可以使用如下几条 SQL 语句来查询统计某个 OBProxy 上当前所有的连接数：

- 方法一：通过 OBProxy IP+端口（默认的端口号：2883）连接到 root@sys 租户后，执行。

  ```shell
  MySQL [(none)]> show proxysession;

  ```
 - 方法二：通过 OBProxy IP+端口（默认的端口号：2883）连接到 root@sys 租户后，执行。

  ```shell
  MySQL [(none)]> show processlist; -- 注意不要使用show full processlist; 加了 full 以后看到的是整个 OBServer 集群所有 OBServer 的连接数。

  ```
 - 方法三：通过OBProxy IP+端口（默认的端口号：2883）连接到 root@sys 租户后，执行。

  ```shell
  MySQL [(none)]> show proxystat refresh; -- 输出的倒数第四行  `client_connections_currently_open` 字段对应的值统计的就是当前 OBProxy 的连接数。

  ```

### 场景示例

1. 测试准备，通过 sysbench 启动 10 个连接，连到单个 OBProxy IP，对OBServer 集群进行压测。

   ```shell
   [admin@localhost:~]$ sysbench /home/admin/sysbench-1.0.16/src/lua/oltp_point_select.lua --mysql-db=sbtest --mysql-host=xxx.xxx.xxx.111 --mysql-port=2883 --mysql-user=root@perfmysql#oio_cluster --mysql-password='xxx' --tables=30 --table_size=1000000 --report-interval=1 --threads=10 --db-driver=mysql --time=600 --skip-trx=off --db-ps-mode=disable --create-secondary=off --rand-type=uniform --mysql-ignore-errors=6002,6004,4012,2013,4016,1213,1020,1205,4030,1235,1062,6012 run ;date

   ```

   输出压测日志内容如下：

   ```shell
   sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

   Running the test with following options:

   Number of threads: 10

   Report intermediate results every 1 second(s)

   Initializing random number generator from current time

   Initializing worker threads...

   Threads started!

   [ 1s ] thds: 10 tps: 1161.82 qps: 1161.82 (r/w/o: 1161.82/0.00/0.00) lat (ms,95%): 10.09 err/s: 0.00 reconn/s: 0.00

   [ 2s ] thds: 10 tps: 1174.09 qps: 1174.09 (r/w/o: 1174.09/0.00/0.00) lat (ms,95%): 10.09 err/s: 0.00 reconn/s: 0.00

   [ 3s ] thds: 10 tps: 1172.01 qps: 1172.01 (r/w/o: 1172.01/0.00/0.00) lat (ms,95%): 10.09 err/s: 0.00 reconn/s: 0.00

   [ 4s ] thds: 10 tps: 1170.00 qps: 1170.00 (r/w/o: 1170.00/0.00/0.00) lat (ms,95%): 10.09 err/s: 0.00 reconn/s: 0.00

   [ 5s ] thds: 10 tps: 1168.98 qps: 1168.98 (r/w/o: 1168.98/0.00/0.00) lat (ms,95%): 9.91 err/s: 0.00 reconn/s: 0.00

   [ 6s ] thds: 10 tps: 1170.01 qps: 1170.01 (r/w/o: 1170.01/0.00/0.00) lat (ms,95%): 10.09 err/s: 0.00 reconn/s: 0.00

   [ 7s ] thds: 10 tps: 1169.01 qps: 1169.01 (r/w/o: 1169.01/0.00/0.00) lat (ms,95%): 10.09 err/s: 0.00 reconn/s: 0.00

   ```
 2. 统计单个 OBProxy 当前的连接数的方法。

      - 方法一：通过该 OBProxy 连接到 root@sys 租户后执行 `show proxysession;` 命令。

       ```shell
       $ mysql -hxxx.xxx.xxx.111 -uroot@sys#oio\_cluster -P2883 -pxxx -A -c

       Welcome to the MariaDB monitor. Commands end with ; or \g.

       Your MySQL connection id is 1442148

       Server version: 5.6.25 OceanBase 3.2.4.7 (r107010022023122913-1eba23192ff3365951f818121471f56a49b29a7f) (Built Dec 29 2023 13:55:55)

       Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

       Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

       MySQL [(none)\> show proxysession;

       ```

       输出结果如下：

       ```shell
       +--------------------+---------+-------------+-----------+------+----------------------+--------+-------------+-------------------+-------------------+-------+-------+-----------+

       | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session\_count | state | tid | pid | using_ssl |

       +--------------------+---------+-------------+-----------+------+----------------------+--------+-------------+-------------------+-------------------+-------+-------+-----------+

       | 839446818411728824 | 1442148 | oio_cluster | sys | root | xx.xxx.xx.xxx:49663 | NULL | 0 | 1 | MCS_ACTIVE_READER | 63333 | 63282 | 0 |

       | 839446818411728797 | 70018 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51380 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63282 | 63282 | 0 |

       | 839446818411728749 | 170964 | oio_cluster | oracle | sys | xx.xxx.xx.xxx:47821 | SYS | 0 | 3 | MCS_ACTIVE_READER | 63323 | 63282 | 0 |

       | 839446818411728798 | 337803 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51367 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63324 | 63282 | 0 |

       | 839446818411728799 | 447206 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51368 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63325 | 63282 | 0 |

       | 839446818411728802 | 542883 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51383 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63326 | 63282 | 0 |

       | 839446818411728801 | 661737 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51369 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63327 | 63282 | 0 |

       | 839446818411728800 | 787420 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51370 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63328 | 63282 | 0 |

       | 839446818411728803 | 920698 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51371 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63329 | 63282 | 0 |

       | 839446818411728804 | 1048828 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51382 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63330 | 63282 | 0 |

       | 839446818411728805 | 1179731 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51372 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63331 | 63282 | 0 |

       | 839446818411728806 | 1310733 | oio_cluster | perfmysql | root | xxx.xx.xxx.xxx:51381 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63332 | 63282 | 0 |

       +--------------------+---------+-------------+-----------+------+----------------------+--------+-------------+-------------------+-------------------+-------+-------+-----------+
       12 rows in set (0.00 sec)

       ```
      - 方法二：通过该 OBProxy 连接到 root@sys 租户后执行 `show processlist;` 命令。

       MySQL [(none)]> show processlist;

       ```

       输出结果如下：

       ```shell
       +---------+-----------+------+----------------------+--------+-------------+-------------------+-------------------+-------+-------+

       | Id | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid |

       +---------+-----------+------+----------------------+--------+-------------+-------------------+-------------------+-------+-------+

       | 1442148 | sys | root | xx.xxx.xx.xxx:49663 | NULL | 0 | 1 | MCS_ACTIVE_READER | 63333 | 63282 |

       | 70018 | perfmysql | root | xxx.xx.xxx.xxx:51380 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63282 | 63282 |

       | 170964 | oracle | sys | xx.xxx.xx.xxx:47821 | SYS | 0 | 3 | MCS_ACTIVE_READER | 63323 | 63282 |

       | 337803 | perfmysql | root | xxx.xx.xxx.xxx:51367 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63324 | 63282 |

       | 447206 | perfmysql | root | xxx.xx.xxx.xxx:51368 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63325 | 63282 |

       | 542883 | perfmysql | root | xxx.xx.xxx.xxx:51383 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63326 | 63282 |

       | 661737 | perfmysql | root | xxx.xx.xxx.xxx:51369 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63327 | 63282 |

       | 787420 | perfmysql | root | xxx.xx.xxx.xxx:51370 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63328 | 63282 |

       | 920698 | perfmysql | root | xxx.xx.xxx.xxx:51371 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63329 | 63282 |

       | 1048828 | perfmysql | root | xxx.xx.xxx.xxx:51382 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63330 | 63282 |

       | 1179731 | perfmysql | root | xxx.xx.xxx.xxx:51372 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63331 | 63282 |

       | 1310733 | perfmysql | root | xxx.xx.xxx.xxx:51381 | sbtest | 0 | 1 | MCS_ACTIVE_READER | 63332 | 63282 |

       +---------+-----------+------+----------------------+--------+-------------+-------------------+-------------------+-------+-------+
       12 rows in set (0.00 sec)

       ```
      - 方法三：通过该 OBProxy 连接到 root@sys 租户后执行 `show proxystat refresh;` 命令。

       MySQL \[(none)\]> show proxystat refresh;

       ```

       输出结果如下：

       ```shell
       +---------------------------------------------+------------------+--------------+

       | stat_name | value | persist_type |

       +---------------------------------------------+------------------+--------------+

       | async_flush_log_speed | 11 | NULL |

       | dropped_debug_log_count | 0 | NULL |

       | dropped_trace_log_count | 0 | NULL |

       ...

       ...

       ...

       | global_client_connections_currently_open | 12 | NULL |

       | client_connections_currently_open | 12 | NULL |

       | write_bytes | 4048726835 | PERSISTENT |

       | read_bytes | 5607077717 | PERSISTENT |

       | net_handler_run | 683472619414 | NULL |

       217 rows in set (0.00 sec)

       ```

在同一个时刻，通过上面三种方法统计出来的，当前 OBProxy 的连接数，均一致。

## 适用版本

OBProxy V1.x 版本、OBProxy V3.x 版本、OBProxy V4.x 版本。

Previous

[select a(a'') 断连接的问题](https://www.oceanbase.com/knowledge-base/oceanbase-database-20000036893)

Next

[easy_connection_on_timeout_conn 的问题原因](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000450150) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
