10.5. Connection management

This section describes facilities for connection management.

This section describes the following:

10.5.1. List all network connections

An administrator is able to view all network connections within the database instance. Alternatively, the current user may view all of their own network connections.

The procedure dbms.listConnections lists all accepted network connections for all configured connectors, including Bolt, HTTP, and HTTPS. Some listed connections might never perform authentication. For example, HTTP GET requests to the Neo4j Browser endpoint fetches static resources and does not need to authenticate. However, connections made using Neo4j Browser require the user to provide credentials and perform authentication.

Syntax:

CALL dbms.listConnections()

Returns:

Name Type Description

connectionId

String

This is the ID of the network connection.

connectTime

String

This is the time at which the connection was started.

connector

String

Name of the connector that accepted the connection.

username

String

This is the username of the user who initiated the connection. This field will be null if the transaction was issued using embedded API. It can also be null if connection did not perform authentication.

userAgent

String

Name of the software that is connected. This information is extracted from the User-Agent request header for HTTP and HTTPS connections. It is available natively for Bolt connections which supply the agent string in an initialization message.

serverAddress

String

The server address this connection is connected to.

clientAddress

String

The client address of the connection.

Example 10.11. List all network connections

The following example shows that the user 'alwood' is connected using Java driver and a Firefox web browser. The procedure call yields specific information about the connection, namely connectionId, connectTime, connector, username, userAgent, and clientAddress.

CALL dbms.listConnections() YIELD connectionId, connectTime, connector, username, userAgent, clientAddress
╒══════════════╤══════════════════════════╤═══════════╤══════════╤════════════════════════════════════════════════════════════════════════════════════╤═════════════════╤═════════╕
│"connectionId"│"connectTime"             │"connector"│"username"│"userAgent"                                                                         │"clientAddress"  │"status" │
╞══════════════╪══════════════════════════╪═══════════╪══════════╪════════════════════════════════════════════════════════════════════════════════════╪═════════════════╪═════════╡
│"bolt-21"     │"2018-10-10T12:11:42.276Z"│"bolt"     │"alwood"  │"neo4j-java/1.6.3"                                                                  │"127.0.0.1:53929"│"Running"│
├──────────────┼──────────────────────────┼───────────┼──────────┼────────────────────────────────────────────────────────────────────────────────────┼─────────────────┼─────────┤
│"http-11"     │"2018-10-10T12:37:19.014Z"│"http"     │null      │"Mozilla/5.0 (Macintosh; Intel macOS 10.13; rv:62.0) Gecko/20100101 Firefox/62.0"│"127.0.0.1:54118"│"Running"│
└──────────────┴──────────────────────────┴───────────┴──────────┴────────────────────────────────────────────────────────────────────────────────────┴─────────────────┴─────────┘
2 rows

10.5.2. Terminate multiple network connections

An administrator is able to terminate within the instance all network connections with any of the given IDs. Alternatively, the current user may terminate all of their own network connections with any of the given IDs.

Syntax:

CALL dbms.killConnections(connectionIds)

Arguments:

Name Type Description

ids

List<String>

This is a list of the IDs of all the connections to be terminated.

Returns:

Name Type Description

connectionId

String

This is the ID of the terminated connection.

username

String

This is the username of the user who initiated the (now terminated) connection.

message

String

A message stating whether the connection was successfully found.

Considerations:

Bolt connections are stateful. Termination of a Bolt connection results in termination of the ongoing query/transaction.

Termination of an HTTP/HTTPS connection can terminate the ongoing HTTP/HTTPS request.

Example 10.12. Terminate multiple network connections

The following example shows that the administrator has terminated the connections with IDs 'bolt-37' and 'https-11', started by the users 'joesmith' and 'annebrown', respectively. The administrator also attempted to terminate the connection with ID 'http-42' which did not exist.

CALL dbms.killConnections(['bolt-37', 'https-11', 'http-42'])
╒══════════════╤═══════════╤══════════════════════════════════╕
│"connectionId"│"username" │"message"                         │
╞══════════════╪═══════════╪══════════════════════════════════╡
│"bolt-37"     │"joesmith" │"Connection found"                │
├──────────────┼───────────┼──────────────────────────────────┤
│"https-11"    │"annebrown"│"Connection found"                │
├──────────────┼───────────┼──────────────────────────────────┤
│"http-42"     │"n/a"      │"No connection found with this id"│
└──────────────┴───────────┴──────────────────────────────────┘
3 rows

10.5.3. Terminate a single network connection

An administrator is able to terminate within the instance any network connection with the given ID. Alternatively, the current user may terminate their own network connection with the given ID.

Syntax:

CALL dbms.killConnection(connectionId)

Arguments:

Name Type Description

id

String

This is the ID of the connection to be terminated.

Returns:

Name Type Description

connectionId

String

This is the ID of the terminated connection.

username

String

This is the username of the user who initiated the (now terminated) connection.

message

String

A message stating whether the connection was successfully found.

Considerations:

Bolt connections are stateful. Termination of a Bolt connection results in termination of the ongoing query/transaction.

Termination of an HTTP/HTTPS connection can terminate the ongoing HTTP/HTTPS request.

Example 10.13. Terminate a single network connection

The following example shows that the user 'joesmith' has terminated his connection with the ID 'bolt-4321'.

CALL dbms.killConnection('bolt-4321')
╒══════════════╤═══════════╤══════════════════╕
│"connectionId"│"username" │"message"         │
╞══════════════╪═══════════╪══════════════════╡
│"bolt-4321"   │"joesmith" │"Connection found"│
└──────────────┴───────────┴──────────────────┘
1 row

The following example shows the output when trying to kill a connection with an ID that does not exist.

CALL dbms.killConnection('bolt-987')
╒══════════════╤═══════════╤══════════════════════════════════╕
│"connectionId"│"username" │"message"                         │
╞══════════════╪═══════════╪══════════════════════════════════╡
│"bolt-987"    │"n/a"      │"No connection found with this id"│
└──────────────┴───────────┴──────────────────────────────────┘
1 row