Skip to main content

Description

Shows the open client connections of the native TCP and HTTP query interfaces. A connection is active when a query runs. A connection is idle when it waits for the next query. The table does not show these connections:
  • Connections of other protocols, for example MySQL, PostgreSQL, and gRPC.
  • Interserver connections.
  • HTTP connections that did not run a query, for example /ping and Prometheus connections.
The server collects the connections only if the server setting collect_connection_metrics is true. If the setting is false, the table is empty. You can change the setting without a restart (SYSTEM RELOAD CONFIG):
  • When you change the setting to false, the table becomes empty and the server stops the registration of new connections.
  • When you change the setting to true, an open connection shows in the table on its next query.
The server adds a TCP connection to the table after authentication. The server removes the connection when it closes. The server adds an HTTP connection to the table on its first query. The server removes the connection when the socket closes. Thus, the table shows an HTTP keep-alive connection as idle between the requests. A user without the SHOW CONNECTIONS privilege sees only the connections of this user. The check uses the user ID, not the name. Thus, a renamed user keeps its connections, and a new user with the old name does not get them. connection_id is a random UUID. Thus, it is unique across servers, and you can combine the tables of many replicas, for example with clusterAllReplicas. connected_time has the same meaning for TCP and HTTP: the time when the server started to handle the socket. This time is before the TCP handshake, the authentication, and the first query. Thus, it can be earlier than the time when the connection shows in the table.

Columns

  • connection_id (UUID) — Unique identifier of the connection: a random UUID. It is unique across servers, for example in clusterAllReplicas. A TCP connection gets the identifier after authentication. An HTTP connection gets the identifier on its first query.
  • protocol (LowCardinality(String)) — Protocol of the connection: TCP (native protocol) or HTTP.
  • client_address (IPv6) — IP address of the client. Behind a proxy, this is the address of the client if the server trusts the PROXY protocol or the X-Forwarded-For header. For HTTP, this is the address of the last request.
  • client_port (UInt16) — TCP port of the client. Behind a proxy, this is the port from the PROXY protocol or the X-Forwarded-For header if the server trusts them. For HTTP, this is the port of the last request.
  • server_port (UInt16) — Server port that accepted the connection.
  • user (String) — Name of the authenticated user. For an HTTP connection, this is the user of the last request. Each request on a keep-alive connection has its own authentication. If the user is renamed, this column shows the old name until the next authentication. The access check uses the user ID, not the name.
  • status (LowCardinality(String)) — Status of the connection. active: a query runs now. idle: the connection is open and waits for the next query or the next HTTP request.
  • query_id (String) — Identifier of the query that runs now. Empty if the connection is idle.
  • client_name (String) — Name of the client application. A TCP client sends this name in the handshake. For HTTP, this is the User-Agent header of the last request.
  • client_version_major (UInt64) — Major version of the client from the TCP handshake. 0 for HTTP connections.
  • client_version_minor (UInt64) — Minor version of the client from the TCP handshake. 0 for HTTP connections.
  • client_version_patch (UInt64) — Patch version of the client from the TCP handshake. 0 for HTTP connections.
  • connected_time (DateTime) — Time when the server started to handle the socket. This time is the same for TCP and HTTP: before the handshake, the authentication, and the first query.
  • last_query_time (Nullable(DateTime)) — Start time of the last query on this connection. NULL if the connection did not run a query.

Examples