Help Center > > Developer Guide> SQL Reference> SQL Syntax> CLEAN CONNECTION

CLEAN CONNECTION

Updated at: Mar 13, 2020 GMT+08:00

Function

CLEAN CONNECTION clears database connections when a database is abnormal. You may use this statement to delete a specific user's connections to a specified database.

Precautions

None

Syntax

CLEAN CONNECTION 
    TO { COORDINATOR ( nodename [, ... ] ) | NODE ( nodename [, ... ] )| ALL [ CHECK ] [ FORCE ] }
    [ FOR DATABASE dbname ] 
    [ TO USER username ];

Parameter Description

  • CHECK

    This parameter can be specified only when the node list is specified as TO ALL. Setting this parameter will check whether a database is accessed by other sessions before its connections are cleared. If any sessions are detected before DROP DATABASE is executed, an error will be reported and the database will not be deleted.

  • FORCE

    This parameter can be specified only when the node list is specified as TO ALL. Setting this parameter will send SIGTERM signals to all the threads related to the specified dbname and username and forcibly shut them down.

  • COORDINATOR ( nodename ,nodename ... } ) | NODE ( nodename , nodename ... ) | ALL

    Deletes connections on a specified node. There are three scenarios:

    • Deletes connections to a specified CN.
    • Deletes connections to a specified DN.
    • Deletes connections to all CNs and DNs.

    Value range: nodename is an existing node name.

  • dbname

    Deletes connections to a specific database. If this parameter is not specified, connections to all databases will be deleted.

    Value range: An existing database name.

  • username

    Deletes connections of a specific user. If this parameter is not specified, connections of all users will be deleted.

    Value range: An existing user name.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
-- Create user jack:
CREATE USER jack PASSWORD 'Bigdata123@';

-- Clean connections to nodes dn1 and dn2 for the template1 database:
CLEAN CONNECTION TO NODE (dn_6001_6002,dn_6003_6004) FOR DATABASE template1;

-- Clean user jack's connections to dn1:
CLEAN CONNECTION TO NODE (dn_6001_6002) TO USER jack;

-- Clean all the connections to the postgres database:
CLEAN CONNECTION TO ALL FORCE FOR DATABASE postgres;

-- Delete user jack:
DROP USER jack;

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel