Managing Database Connections
Scenario
By default, a database supports a certain number of connections. Administrators can manage database connections to learn about the connection performance of the current database or increase the connection limit so that more users or applications can connect to the database at the same time.
Maximum Number of Connections
The number of connections supported by a cluster depends on its node flavor.
| Parameter | Number of CN Connections | Number of DN Connections |
|---|---|---|
| max_connections | 800 | Number of VCPU cores/Number of DNs on a single node x 120 + 24 |
- The policies of max_max_stream, poolsize, and max_prepared_transactions are the same as those of max_connections.
- For details about CNs and DNs, see Logical Cluster Architecture.
Viewing the Maximum Number of Connections
- Use the SQL client tool to connect to the database in a cluster.
- Run the following command:
1SHOW max_connections;
Information similar to the following is displayed, showing that the maximum number of database connections is 200 by default.
max_connections ----------------- 200 (1 row)
Viewing the Number of Used Connections
- Use the SQL client tool to connect to the database in a cluster.
- View the number of connections in scenarios described in Table 2.
Except for database and user names that are enclosed with double quotation marks (") during creation, uppercase letters are not allowed in the database and user names in the commands in the following table.
Table 2 Viewing the number of connections Description
Command
View the maximum number of sessions connected to a specific user.
Run the following command to view the maximum number of sessions connected to user dbadmin.
1SELECT ROLNAME,ROLCONNLIMIT FROM PG_ROLES WHERE ROLNAME='dbadmin';
Information similar to the following is displayed. -1 indicates that the number of sessions connected to user dbadmin is not limited.
rolname | rolconnlimit ----------+-------------- dwsadmin | -1 (1 row)
View the number of session connections that have been used by a user.
Run the following command to view the number of session connections that have been used by dbadmin.
1SELECT COUNT(*) FROM V$SESSION WHERE USERNAME='dbadmin';
Information similar to the following is displayed. 1 indicates the number of session connections used by user dbadmin.
count ------- 1 (1 row)View the maximum number of sessions connected to a specific database.
Run the following command to view the upper limit of connections used by the gaussdb database:
1SELECT DATNAME,DATCONNLIMIT FROM PG_DATABASE WHERE DATNAME='gaussdb';
Information similar to the following is displayed. -1 indicates that the number of sessions connected to the gaussdb database is not limited.
datname | datconnlimit ----------+-------------- gaussdb | -1 (1 row)
View the number of session connections that have been used by a database.
Run the following command to view the number of session connections that have been used by the gaussdb database:
1SELECT COUNT(*) FROM PG_STAT_ACTIVITY WHERE DATNAME='gaussdb';
Information similar to the following is displayed. 1 indicates the number of session connections used by the gaussdb database.
count ------- 1 (1 row)View the number of session connections that have been used by all users.
Run the following command to view the number of session connections that have been used by all users:
1 2 3 4 5
SELECT COUNT(*) FROM PG_STAT_ACTIVITY; count ------- 10 (1 row)
Last Article: Using the Python Library PyGreSQL to Connect to a Cluster
Next Article: Monitoring and Alarms
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.