Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page
Help Center/ GaussDB/ Developer Guide(Centralized_2.x)/ Database Security Management/ Checking the Number of Database Connections

Checking the Number of Database Connections

Updated on 2023-10-23 GMT+08:00

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.
  • 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. Connect to a database. For details, see Connecting to a Database.
  2. View the upper limit of the number of global connections.

    1
    2
    3
    4
    5
    openGauss=# SHOW max_connections;
     max_connections
    -----------------
     800
    (1 row)
    

    800 is the maximum number of session connections.

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

    1
    2
    3
    4
    5
    openGauss=# SELECT ROLNAME,ROLCONNLIMIT FROM PG_ROLES WHERE ROLNAME='omm';
     rolname  | rolconnlimit
    ----------+--------------
     omm |           -1
    (1 row)
    

    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.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    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)
    

    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.

    1
    2
    3
    4
    5
    6
    openGauss=# SELECT DATNAME,DATCONNLIMIT FROM PG_DATABASE WHERE DATNAME='postgres';
    
     datname  | datconnlimit
    ----------+--------------
     postgres |           -1
    (1 row)
    

    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.

    1
    2
    3
    4
    5
    openGauss=# SELECT COUNT(*) FROM PG_STAT_ACTIVITY WHERE DATNAME='postgres';
     count 
    -------
         1
    (1 row)
    

    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:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    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)
    

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback