openGauss Checking the Number of Database Connections

·

3 min read

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

  1. Log in as the OS user omm to the primary node of the database.

  2. Run the following command to connect to the database:

     ""gsql -d postgres -p 8000
    

    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=#
    
  3. View the upper limit of the number of global connections.

     ""postgres=# SHOW max_connections;
      max_connections
     -----------------
      800
     (1 row)
    

    800 is the maximum number of session connections.

  4. 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

    | Description | Command | | --- | --- | | View the maximum number of sessions connected to a specific user. | Run the following commands to view the upper limit of the number of omm's session connections. -1 indicates that no upper limit is set for the number of omm's session connections. | | View the number of session connections that have been used by a user. | Run the following commands to view the number of session connections that have been used by omm. 1 indicates the number of session connections that have been used by omm. | | View the maximum number of sessions connected to a specific database. | Run the following commands to view the upper limit of the number of postgres's session connections. -1 indicates that no upper limit is set for the number of postgres's session connections. | | View the number of session connections that have been used by a specific database. | Run the following commands to view the number of session connections that have been used by postgres. 1 indicates the number of session connections that have been used by postgres. | | View the number of session connections that have been used by all users. | Run the following commands to view the number of session connections that have been used by all users: |