Postgresql 中文操作指南

DISCONNECT

DISCONNECT — 终止数据库连接

Synopsis

DISCONNECT connection_name
DISCONNECT [ CURRENT ]
DISCONNECT ALL

Description

DISCONNECT 关闭与数据库的连接(或所有连接)。

Parameters

  • connection_name #

    • CONNECT 命令建立的数据库连接名称。

  • CURRENT #

    • 关闭“当前”连接,该连接要么是最近打开的连接,要么是 SET CONNECTION 命令设置的连接。如果未向 DISCONNECT 命令提供参数,这也是默认情况。

  • ALL #

    • Close all open connections.

Examples

int
main(void)
{
    EXEC SQL CONNECT TO testdb AS con1 USER testuser;
    EXEC SQL CONNECT TO testdb AS con2 USER testuser;
    EXEC SQL CONNECT TO testdb AS con3 USER testuser;

    EXEC SQL DISCONNECT CURRENT;  /* close con3          */
    EXEC SQL DISCONNECT ALL;      /* close con2 and con1 */

    return 0;
}

Compatibility

DISCONNECT 在 SQL 标准中指定。

See Also