8.3.2. Procedures for query management

This section describes the procedures available for viewing and terminating currently-executing queries.

The features described in this section are available in Neo4j Enterprise Edition.

Unless stated otherwise, all arguments to the procedures described in this section must be supplied.

8.3.2.1. Terminology

administrator
This is a user who has been assigned the admin role. Refer to Section 7.1.4, “Native user and role management” for managing users and roles.
current user
This is the currently logged-in user invoking the commands described in this chapter.
user
  • A user is composed of a username and credentials, where the latter is a unit of information, such as a password, verifying the identity of a user.
  • A user may represent a human, an application etc.

8.3.2.2. List all running queries

An administrator is able to view all queries that are currently executing within the instance. Alternatively, the current user may view all of their own currently-executing queries.

Syntax:

CALL dbms.listQueries()

Returns:

Name Type Description

queryId

String

This is the ID of the query.

username

String

This is the username of the user who is executing the query.

query

String

This is the query itself.

parameters

Map

This is a map containing all the parameters used by the query.

startTime

String

This is the time at which the query was started.

elapsedTime

String

This is the time that has elapsed since the query was started.

connectionDetails

String

These are the connection details pertaining to the query.

metaData

Map

This is any metadata associated with the transaction.

Example 8.2. Viewing queries that are currently executing

The following example shows that the user 'alwood' is currently running two queries; namely, the dbms.listQueries() procedure and a query creating many nodes. Some of the data has been trimmed for brevity.

CALL dbms.listQueries()
+-------------------------------------------------------------------------------------------------------------------------+
| queryId     | username | query                    | parameters | startTime | elapsedTime | connectionDetails | metaData |
+-------------------------------------------------------------------------------------------------------------------------+
| "query-271" | "alwood" | "... dbms.listQueries()" | (empty)    | "2016..." | "00:00:..." | "server-sess ..." | (empty)  |
| "query-272" | "alwood" | "WITH range(1, 3000...)" | (empty)    | "2016..." | "00:00:..." | "server-sess ..." | (empty)  |
+-------------------------------------------------------------------------------------------------------------------------+
2 rows

8.3.2.3. Terminate multiple queries

An administrator is able to terminate within the instance all transactions executing a query with any of the given query IDs. Alternatively, the current user may terminate all of their own transactions executing a query with any of the given query IDs.

Syntax:

CALL dbms.killQueries(ids)

Arguments:

Name Type Description

ids

List<String>

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

Returns:

Name Type Description

queryId

String

This is the ID of the terminated query.

username

String

This is the username of the user who was executing the (now terminated) query.

Example 8.3. Terminating multiple queries

The following example shows that the administrator has terminated the queries with IDs 'query-378' and 'query-765', started by the users 'joesmith' and 'annebrown', respectively.

CALL dbms.killQueries(['query-378','query-765'])
+---------------------------+
| queryId     | username    |
+---------------------------+
| "query-378" | "joesmith"  |
| "query-765" | "annebrown" |
+---------------------------+
2 rows

8.3.2.4. Terminate a single query

An administrator is able to terminate within the instance any transaction executing the query whose ID is provided. Alternatively, the current user may terminate their own transaction executing the query whose ID is provided.

Syntax:

CALL dbms.killQuery(id)

Arguments:

Name Type Description

id

String

This is the ID of the query to be terminated.

Returns:

Name Type Description

queryId

String

This is the ID of the terminated query.

username

String

This is the username of the user who was executing the (now terminated) query.

Example 8.4. Terminating a single query

The following example shows that the user 'joesmith' has terminated his query with the ID 'query-502'.

CALL dbms.killQuery('query-502')
+---------------------------+
| queryId     | username    |
+---------------------------+
| "query-502" | "joesmith"  |
+---------------------------+
1 row