Transaction commands

This section explains the SHOW TRANSACTIONS and TERMINATION 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 will produce a table with the following columns:

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 OF 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, et.c., 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.

LONG

currentQueryActiveLockCount

Count of active locks held by the query currently executing in this transaction, or null if no query is currently executing.

LONG

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.

LONG

allocatedDirectBytes

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

LONG

estimatedUsedHeapMemory

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

LONG

pageHits

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

LONG

pageFaults

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

LONG

currentQueryPageHits

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

LONG

currentQueryPageFaults

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

LONG

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

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 strings or as an expression resolving to a string or a list of strings.

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 output columns, use the SHOW TRANSACTIONS command. If all columns 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-4"

"query-5093"

""

""

""

"MATCH (n) RETURN n"

"2022-11-28T10:05:22.628Z"

"Running"

PT0.056S

"neo4j"

"neo4j-transaction-6"

"query-5094"

""

""

""

"SHOW TRANSACTIONS"

"2022-11-28T10:05:22.642Z"

"Running"

PT0.042S

Rows: 2

Listing transactions with filtering on output columns

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"

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

"neo4j"

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

Rows: 2

Several of the output columns 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-9"

275

261

0

0

120

111

0

0

"neo4j-transaction-4"

1005

15

0

0

837

15

0

0

"neo4j-transaction-5"

1016

679

0

0

835

679

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.

For the TERMINATE TRANSACTIONS command there is no difference between the default output and full output, all columns are default.

This command will produce a table with the following columns:

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

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 strings or as an expression resolving to a string or a list of strings.

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 columns

The output from the TERMINATE TRANSACTIONS command can be filtered using the YIELD and WHERE clauses. For example, returning the transaction ids and message for the transactions that didn’t 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

In difference to SHOW TRANSACTIONS, TERMINATE TRANSACTIONS doesn’t allow WHERE without YIELD:

Query
TERMINATE TRANSACTIONS "neo4j-transaction-1","neo4j-transaction-2"
WHERE message <> "Transaction terminated."

WHERE is not allowed by itself, please use TERMINATE TRANSACTION …​ YIELD …​ WHERE …​ instead (line 2, column 1 (offset: 67))
"WHERE message <> "Transaction terminated.""
^

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.

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.

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.

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.

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