DEV Community

wanglei
wanglei

Posted on

Checking the Number of Database Connections

Background
If the number of connections reaches its upper limit, new connections cannot be created. Therefore, if a user fails to connect a database, the administrator must check whether the number of connections has reached the upper limit. The following are details about database connections:

The maximum number of global connections is specified by the max_connections parameter. Its default value is 5000.
The number of a user's connections is specified by CONNECTION LIMIT connlimit in the CREATE ROLE statement and can be changed using CONNECTION LIMIT connlimit in the ALTER ROLE statement.
The number of a database's connections is specified by the CONNECTION LIMIT connlimit parameter in the CREATE DATABASE statement.
Procedure
Log in as the OS user omm to the primary node of the database.

Run the following command to connect to the database:

""

gsql -d postgres -p 8000
Enter fullscreen mode Exit fullscreen mode

postgres is the name of the database to be connected, and 8000 is the port number of the database primary node.

If information similar to the following is displayed, the connection succeeds:

gsql ((openGauss 1.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

postgres=# 
Enter fullscreen mode Exit fullscreen mode

View the upper limit of the number of global connections.

postgres=# SHOW max_connections;
 max_connections
-----------------
 800
(1 row)
Enter fullscreen mode Exit fullscreen mode

800 is the maximum number of session connections.

View the number of connections that have been used.

For details, see Table 1.

NOTICE:
Except for database and usernames that are enclosed in double quotation marks (") during creation, uppercase letters are not allowed in the database and usernames in the commands in the following table.

Table 1 Viewing the number of session connections

Image description

Image description

Top comments (0)