Transaction commands

This page explains the SHOW TRANSACTIONS and TERMINATE TRANSACTIONS commands.

SHOW TRANSACTIONS

The SHOW TRANSACTIONS command is used to display running transactions within the instance. This also includes fabric transactions. For remote database aliases, transactions can be tracked by running SHOW TRANSACTIONS when connected to the remote database alias.

The command SHOW TRANSACTIONS returns only the default output. For a full output use the optional YIELD command. Full output: SHOW TRANSACTIONS YIELD *.

This command returns the following outputs:

Table 1. List transactions output
Column Description Type

database

The name of the database the transaction is executing against. Default Output

STRING

transactionId

The transaction ID. Default Output

STRING

currentQueryId

The ID of the query currently executing in this transaction, or an empty STRING if no query is currently executing. Default Output

STRING

connectionId

The ID of the database connection attached to the transaction or an empty STRING for embedded connections. Default Output

STRING

clientAddress

The client address of the connection issuing the transaction or an empty STRING if unavailable. Default Output

STRING

username

The username of the user executing the transaction. Default Output

STRING

currentQuery

The query text of the query currently executing in this transaction, or an empty STRING if no query is currently executing. Default Output

STRING

startTime

The time at which the transaction was started. Default Output

STRING

status

The current status of the transaction (Terminated, Blocked, Closing, or Running). Default Output

STRING

elapsedTime

The time that has elapsed since the transaction was started. Default Output

DURATION

outerTransactionId

The ID of this transaction’s outer transaction, if such exists, otherwise an empty STRING. For details, see CALL { …​ } IN TRANSACTIONS.

STRING

metaData

Any metadata associated with the transaction, or an empty map if there is none.

MAP

parameters

A map containing all the parameters used by the query currently executing in this transaction, or an empty map if no query is currently executing.

MAP

planner

The name of the Cypher planner used to plan the query currently executing in this transaction, or an empty STRING if no query is currently executing. For details, see Cypher planner.

STRING

runtime

The name of the Cypher runtime used by the query currently executing in this transaction, or an empty STRING if no query is currently executing. For details, see Cypher runtime.

STRING

indexes

The indexes utilised by the query currently executing in this transaction, or an empty list if no query is currently executing.

LIST<MAP>

currentQueryStartTime

The time at which the query currently executing in this transaction was started, or an empty STRING if no query is currently executing.

STRING

protocol

The protocol used by the connection issuing the transaction. This is not necessarily an internet protocol, such as http, etc., although it could be. It might also be "embedded", for example, if this connection represents an embedded session.

STRING

requestUri

The request URI used by the client connection issuing the transaction, or null if the URI is not available.

STRING

currentQueryStatus

The current status of the query currently executing in this transaction (parsing, planning, planned, running, or waiting), or an empty STRING if no query is currently executing.

STRING

statusDetails

Provide additional status details from the underlying transaction or an empty STRING if none is available.

STRING

resourceInformation

Information about any blocked transactions, or an empty map if there is none.

MAP

activeLockCount

Count of active locks held by the transaction.

INTEGER

currentQueryActiveLockCount

Count of active locks held by the query currently executing in this transaction.

INTEGER

cpuTime

CPU time that has been actively spent executing the transaction or null if unavailable.

DURATION

waitTime

Wait time that has been spent waiting to acquire locks.

DURATION

idleTime

Idle time for this transaction, or null if unavailable.

DURATION

currentQueryElapsedTime

The time that has elapsed since the query currently executing in this transaction was started, or null if no query is currently executing.

DURATION

currentQueryCpuTime

CPU time that has been actively spent executing the query currently executing in this transaction, or null if unavailable or no query is currently executing.

DURATION

currentQueryWaitTime

Wait time that has been spent waiting to acquire locks for the query currently executing in this transaction, or null if no query is currently executing.

DURATION

currentQueryIdleTime

Idle time for the query currently executing in this transaction, or null if unavailable or no query is currently executing.

DURATION

currentQueryAllocatedBytes

The number of bytes allocated on the heap so far by the query currently executing in this transaction, or null if unavailable or no query is currently executing.

INTEGER

allocatedDirectBytes

Amount of off-heap (native) memory allocated by the transaction in bytes or null if unavailable.

INTEGER

estimatedUsedHeapMemory

The estimated amount of used heap memory allocated by the transaction in bytes or null if unavailable.

INTEGER

pageHits

The total number of page cache hits that the transaction performed.

INTEGER

pageFaults

The total number of page cache faults that the transaction performed.

INTEGER

currentQueryPageHits

The total number of page cache hits that the query currently executing in this transaction performed.

INTEGER

currentQueryPageFaults

The total number of page cache faults that the query currently executing in this transaction performed.

INTEGER

initializationStackTrace

The initialization stacktrace for this transaction, or an empty STRING if unavailable.

STRING

The SHOW TRANSACTIONS command can be combined with multiple SHOW TRANSACTIONS and TERMINATE TRANSACTIONS, see transaction commands combination.

Syntax

More details about the syntax descriptions can be found here.

List transactions on the current server
SHOW TRANSACTION[S] [transaction-id[,...]]
[YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
[WHERE expression]
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]

The format of transaction-id is <databaseName>-transaction-<id>. Transaction IDs must be supplied as one or more comma-separated quoted STRING values, or as an expression resolving to a STRING or a LIST<STRING>.

When using the RETURN clause, the YIELD clause is mandatory and must not be omitted.

A user with the SHOW TRANSACTION privilege can view the currently executing transactions in accordance with the privilege grants. All users may view all of their own currently executing transactions.

Listing all transactions

To list all available transactions with the default outputs, use the SHOW TRANSACTIONS command. If all outputs are required, use SHOW TRANSACTIONS YIELD *.

Query
SHOW TRANSACTIONS
Table 2. Result
database transactionId currentQueryId connectionId clientAddress username currentQuery startTime status elapsedTime

"neo4j"

"neo4j-transaction-6"

"query-664"

""

""

""

"SHOW TRANSACTIONS"

"2022-06-14T10:02:45.568Z"

"Running"

PT0.038S

"neo4j"

"neo4j-transaction-4"

"query-663"

""

""

""

"MATCH (n) RETURN n"

"2022-06-14T10:02:45.546Z"

"Running"

PT0.06S

Rows: 2

Listing transactions with filtering on output

The listed transactions can be filtered by using the WHERE clause. For example, getting the databases for all transactions where the currently executing query contains 'Mark':

Query
SHOW TRANSACTIONS YIELD database, currentQuery WHERE currentQuery contains 'Mark'
Table 3. Result
database currentQuery

"neo4j"

"MATCH (p:Person) WHERE p.name='Mark' RETURN p"

"neo4j"

"SHOW TRANSACTIONS YIELD database, currentQuery WHERE currentQuery contains 'Mark'"

Rows: 2

Several of the outputs have the duration type, which can be hard to read. They can instead be returned in a more readable format:

Query
SHOW TRANSACTIONS
YIELD transactionId, elapsedTime, cpuTime, waitTime, idleTime,
  currentQueryElapsedTime, currentQueryCpuTime, currentQueryWaitTime, currentQueryIdleTime
RETURN
  transactionId AS txId,
  elapsedTime.milliseconds AS elapsedTimeMillis,
  cpuTime.milliseconds AS cpuTimeMillis,
  waitTime.milliseconds AS waitTimeMillis,
  idleTime.seconds AS idleTimeSeconds,
  currentQueryElapsedTime.milliseconds AS currentQueryElapsedTimeMillis,
  currentQueryCpuTime.milliseconds AS currentQueryCpuTimeMillis,
  currentQueryWaitTime.microseconds AS currentQueryWaitTimeMicros,
  currentQueryIdleTime.seconds AS currentQueryIdleTimeSeconds
Table 4. Result
txId elapsedTimeMillis cpuTimeMillis waitTimeMillis idleTimeSeconds currentQueryElapsedTimeMillis currentQueryCpuTimeMillis currentQueryWaitTimeMicros currentQueryIdleTimeSeconds

"neo4j-transaction-5"

1055

767

0

0

1012

767

0

0

"neo4j-transaction-9"

156

155

0

0

97

97

0

0

"neo4j-transaction-4"

1082

17

0

1

1013

17

0

0

Rows: 3

Listing specific transactions

It is possible to specify which transactions to return in the list by transaction ID.

Query
SHOW TRANSACTIONS "neo4j-transaction-3"
Table 5. Result
database transactionId currentQueryId connectionId clientAddress username currentQuery startTime status elapsedTime

"neo4j"

"neo4j-transaction-3"

"query-1"

""

""

""

"MATCH (n) RETURN n"

"2021-10-20T08:29:39.423Z"

"Running"

PT2.603S

Rows: 1

TERMINATE TRANSACTIONS

The TERMINATE TRANSACTIONS command is used to terminate running transactions by their IDs.

The outputs for the TERMINATE TRANSACTIONS command there is no difference between the default output and full output (YIELD *), all outputs are default.

This command returns the following outputs:

Table 6. Terminate transactions output
Column Description Type

transactionId

The transaction ID.

STRING

username

The username of the user executing the transaction.

STRING

message

The result of the TERMINATE TRANSACTION command as applied to this transaction.

STRING

The TERMINATE TRANSACTIONS command can be combined with multiple SHOW TRANSACTIONS and TERMINATE TRANSACTIONS, see transaction commands combination.

Syntax

More details about the syntax descriptions can be found here.

Terminate transactions by ID on the current server
TERMINATE TRANSACTION[S] transaction_id[, ...]
[YIELD { * \| field[, ...] }
  [ORDER BY field[, ...]]
  [SKIP n]
  [LIMIT n]
  [WHERE expression]
  [RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
]

The format of transaction-id is <databaseName>-transaction-<id>. Transaction IDs must be supplied as one or more comma-separated quoted STRING values, or as an expression resolving to a STRING or a LIST<STRING>.

When using the WHERE or RETURN clauses, the YIELD clause is mandatory and must not be omitted.

A user with the TERMINATE TRANSACTION privilege can terminate transactions in accordance with the privilege grants. All users may terminate their own currently executing transactions.

Terminate transactions

To end running transactions without waiting for them to complete on their own, use the TERMINATE TRANSACTIONS command.

Query
TERMINATE TRANSACTIONS "neo4j-transaction-1","neo4j-transaction-2"
Table 7. Result
transactionId username message

"neo4j-transaction-1"

"neo4j"

"Transaction terminated."

"neo4j-transaction-2"

null

"Transaction not found."

Rows: 2

Terminate transactions with filtering on output

The output from the TERMINATE TRANSACTIONS command can be filtered using the YIELD and WHERE clauses.

Example 1. TERMINATE TRANSACTION YIELD

For example, returning the transaction IDs and message for the transactions that did not terminate.

Query
TERMINATE TRANSACTIONS "neo4j-transaction-1","neo4j-transaction-2"
YIELD transactionId, message
WHERE message <> "Transaction terminated."
Table 8. Result
transactionId message

"neo4j-transaction-2"

"Transaction not found."

Rows: 1

Example 2. TERMINATE TRANSACTION error

In difference to SHOW TRANSACTIONS; the TERMINATE TRANSACTIONS does not allow WHERE without YIELD.

Query
TERMINATE TRANSACTIONS "neo4j-transaction-1","neo4j-transaction-2"
WHERE message <> "Transaction terminated."
Error message
`WHERE` is not allowed by itself, please use `TERMINATE TRANSACTION ... YIELD ... WHERE ...`

Combining transaction commands

In difference to other show commands, the SHOW and TERMINATE TRANSACTIONS commands can be combined in the same query.

When combining multiple commands the YIELD and RETURN clauses are mandatory and must not be omitted. In addition, YIELD * is not permitted. Instead, the YIELD clause needs to explicitly list the yielded columns.

At this point in time, no other cypher clauses are allowed to be combined with the transaction commands.

Terminating all transactions by a given user

To terminate all transactions by a user, first find the transactions using SHOW TRANSACTIONS, then pass them onto TERMINATE TRANSACTIONS.

Example 3. TERMINATE TRANSACTIONS
Query
SHOW TRANSACTIONS
YIELD transactionId AS txId, username AS user
WHERE user = "Alice"
TERMINATE TRANSACTIONS txId
YIELD message
RETURN txId, message
Table 9. Result
txId message

"neo4j-transaction-1"

"Transaction terminated."

"neo4j-transaction-2"

"Transaction terminated."

Rows: 2

Terminating starving transactions

To terminate transactions that have been waiting for more than 30 minutes, first find the transactions using SHOW TRANSACTIONS, then pass them onto TERMINATE TRANSACTIONS.

Example 4. TERMINATE TRANSACTIONS

The following example shows a transaction that has been waiting for 40 minutes.

Query
SHOW TRANSACTIONS
YIELD transactionId, waitTime
WHERE waitTime > duration({minutes: 30})
TERMINATE TRANSACTIONS transactionId
YIELD username, message
RETURN *
Table 10. Result
transactionId waitTime username message

"neo4j-transaction-1"

PT40M

"Alice"

"Transaction terminated."

Rows: 1

Listing other transactions by the same user that were terminated

To list remaining transactions by users whose transactions were terminated, first terminate the transactions using TERMINATE TRANSACTIONS, then filter users through SHOW TRANSACTIONS.

Example 5. TERMINATE TRANSACTIONS
Query
TERMINATE TRANSACTION 'neo4j-transaction-1', 'neo4j-transaction-2'
YIELD username AS terminatedUser
SHOW TRANSACTIONS
YIELD username AS showUser, transactionId AS txId, database, currentQuery, status
WHERE showUser = terminatedUser AND NOT status STARTS WITH 'Terminated'
RETURN txId, showUser AS user, database, currentQuery
Table 11. Result
txId user database currentQuery

"neo4j-transaction-3"

"Alice"

"neo4j"

"MATCH (n) RETURN n"

"mydb-transaction-1"

"Bob"

"mydb"

"MATCH (n:Label) SET n.prop=false"

"system-transaction-999"

"Bob"

"system"

"SHOW DATABASES"

Rows: 2

Listing other transactions by the same user as a given transaction

To list other transactions by the same user as a given transaction, first find the transactions using SHOW TRANSACTIONS, then filter users through a second SHOW TRANSACTIONS.

Example 6. SHOW TRANSACTIONS
Query
SHOW TRANSACTION 'neo4j-transaction-1'
YIELD username AS originalUser, transactionId AS originalTxId
SHOW TRANSACTIONS
YIELD username AS newUser, transactionId AS txId, database, currentQuery, status
WHERE newUser = originalUser AND NOT txId = originalTxId
RETURN txId, newUser AS user, database, currentQuery, status
Table 12. Result
txId user database currentQuery status

"mydb-transaction-1"

"Bob"

"mydb"

"MATCH (n:Label) SET n.prop=false"

"Running"

"system-transaction-999"

"Bob"

"system"

"SHOW DATABASES"

"Running"

Rows: 2