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

allocatedBytes

The number of bytes allocated on the heap so far by the transaction, or 0 if unavailable. Default Output

LONG

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

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

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

cpuTime

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

DURATION

waitTime

Wait time that has been spent waiting to acquire locks.

DURATION

idleTime

Idle time for this transaction, or 0 if unavailable.

DURATION

allocatedDirectBytes

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

LONG

estimatedUsedHeapMemory

The estimated amount of used heap memory allocated by the transaction in bytes, or 0 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

initializationStackTrace

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

STRING

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 a comma-separated list of one or more quoted strings, a string parameter, or a list parameter.

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 allocatedBytes

"neo4j"

"neo4j-transaction-6"

"query-664"

""

""

""

"SHOW TRANSACTIONS"

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

"Running"

PT0.038S

0

"neo4j"

"neo4j-transaction-4"

"query-663"

""

""

""

"MATCH (n) RETURN n"

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

"Running"

PT0.06S

0

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"

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

"neo4j"

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

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
RETURN
  transactionId AS txId,
  elapsedTime.milliseconds AS elapsedTimeMillis,
  cpuTime.milliseconds AS cpuTimeMillis,
  waitTime.milliseconds AS waitTimeMillis,
  idleTime.seconds AS idleTimeSeconds
Table 4. Result
txId elapsedTimeMillis cpuTimeMillis waitTimeMillis idleTimeSeconds

"neo4j-transaction-5"

692

19

0

0

"neo4j-transaction-4"

700

577

0

0

"neo4j-transaction-9"

113

110

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 allocatedBytes

"neo4j"

"neo4j-transaction-3"

"query-1"

""

""

""

"MATCH (n) RETURN n"

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

"Running"

PT2.603S

0

Rows: 1

TERMINATE TRANSACTIONS

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

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

Syntax

More details about the syntax descriptions can be found here.

Terminate transactions by ID on the current server
TERMINATE TRANSACTION[S] transaction_id[, ...]

The format of transaction-id is <databaseName>-transaction-<id>. Transaction IDs must be supplied as a comma-separated list of one or more quoted strings, a string parameter, or a list parameter.

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