Connections consume resources and a large number of persistent connections affect the stability of a tenant with limited resources. OceanBase Database allows you to set the maximum number of connections allowed for a tenant by using parameters or system variables.
Parameters and variables related to the maximum number of connections allowed for a tenant:
max_connectionsThe
max_connectionssystem variable specifies the maximum number of connections allowed for the entire tenant. This variable is supported only in MySQL mode. The value range is [1,2147483647]. The default value is2147483647. The modification of this variable takes effect after the OBServer node is restarted.max_user_connectionsThe
max_user_connectionssystem variable specifies the maximum number of concurrent connections allowed for a single user in a tenant. This variable is supported only in MySQL mode. The value range is [0,4294967295]. The default value is0, which specifies not to limit the number of connections. The modification of this variable takes effect after the OBServer node is restarted._resource_limit_max_session_numThe tenant-level hidden parameter
_resource_limit_max_session_numspecifies the maximum number of concurrent connections allowed for a regular user in a user tenant. The modification of this parameter takes effect immediately. The value range is [0,1000000]. The default value is0. Generally, you do not need to modify this parameter.When the value of the hidden parameter
_resource_limit_max_session_numis greater than0, the specified value is used. When the value of the_resource_limit_max_session_numhidden parameter is0, the system will calculate the maximum number of connections allowed based on the following formula:Maximum number of concurrent connections allowed for a user tenant = MAX(100, Memory for the tenant × 5%/(100 KB))
The size of memory for a user tenant depends on the memory in the resource units of the resource pool allocated to the tenant when it was created. 100 KB is the size of memory that may be occupied by a single session and is calculated based on experience.
100is the smallest number of connections allowed. If the size of memory for a tenant is 2 GB, the maximum number of connections for the tenant isMAX(100, 2 GB × 5%/(100 KB)) = 1000.
Considerations
In OceanBase Database, parameters whose names start with an underscore (_) are hidden parameters and are used by developers only for troubleshooting or emergency O&M.
Limitations
You can use the
max_connectionsormax_user_connectionssystem variable to adjust the maximum number of connections only for a MySQL tenant or a single user in a MySQL tenant.The
_resource_limit_max_session_numparameter does not take effect on thesystenant and the administrator user of a user tenant. This is to avoid logon failures of the administrators due to a large number of persistent connections. The default administrator user isrootin MySQL mode andSYSin Oracle mode.
Procedure
Log on to the
systenant or a user tenant of the database as the administrator.Query the maximum number of connections allowed for the current tenant in a view.
Sample code:
obclient [oceanbase]> SELECT * FROM GV$OB_PARAMETERS WHERE NAME LIKE '_resource_limit_max_session_num'\G *************************** 1. row *************************** SVR_IP: 172.XX.XX.XX SVR_PORT: 2882 ZONE: zone1 SCOPE: TENANT TENANT_ID: 1004 NAME: _resource_limit_max_session_num DATA_TYPE: NULL VALUE: 0 INFO: the maximum number of sessions that can be created concurrently SECTION: RESOURCE_LIMIT EDIT_LEVEL: DYNAMIC_EFFECTIVE 1 row in setFor more information about the
GV$OB_PARAMETERSview, see GV$OB_PARAMETERS.Set the maximum number of connections for the tenant.
Oracle tenants
obclient [SYS]> ALTER SYSTEM SET "_resource_limit_max_session_num" = 100;MySQL tenants
obclient [(none)]> SET GLOBAL max_connections = 1000; obclient [(none)]> SET GLOBAL max_user_connections = 50; obclient [(none)]> ALTER SYSTEM SET _resource_limit_max_session_num = 100;
More information
For more information about parameters and variables, see the following topics: