Are you an LLM? You can read better optimized documentation at /zh/docs/latest-lite/database_administration_guide/checking_the_number_of_database_connections.md for this page in Markdown format
gsql((openGauss x.x.x build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release)Non-SSL connection (SSL connection is recommended when requiring high-security)Type "help" for help.openGauss=#
查看全局会话连接数限制。
openGauss=# SHOW max_connections; max_connections----------------- 800(1 row)
openGauss=# SELECT ROLNAME,ROLCONNLIMIT FROM PG_ROLES WHERE ROLNAME='omm';
rolname | rolconnlimit
----------+--------------
omm | -1
(1 row)
查看指定用户已使用的会话连接数。
执行如下命令查看指定用户omm已使用的会话连接数。其中,1表示omm已使用的会话连接数。
openGauss=# CREATE OR REPLACE VIEW DV_SESSIONS AS
SELECT
sa.sessionid AS SID,
0::integer AS SERIAL#,
sa.usesysid AS USER#,
ad.rolname AS USERNAME
FROM pg_stat_get_activity(NULL) AS sa
LEFT JOIN pg_authid ad ON(sa.usesysid = ad.oid)
WHERE sa.application_name <> 'JobSchedul
openGauss=# SELECT COUNT(*) FROM DV_SESSIONS WHERE USERNAME='omm';
count
-------
1
(1 row)
openGauss=# SELECT COUNT(*) FROM PG_STAT_ACTIVITY WHERE DATNAME='postgres';
count
-------
1
(1 row)
查看所有用户已使用会话连接数。
执行如下命令查看所有用户已使用的会话连接数。
openGauss=# CREATE OR REPLACE VIEW DV_SESSIONS AS
SELECT
sa.sessionid AS SID,
0::integer AS SERIAL#,
sa.usesysid AS USER#,
ad.rolname AS USERNAME
FROM pg_stat_get_activity(NULL) AS sa
LEFT JOIN pg_authid ad ON(sa.usesysid = ad.oid)
WHERE sa.application_name <> 'JobSchedul
openGauss=# SELECT COUNT(*) FROM DV_SESSIONS;
count
-------
10
(1 row)