10.4. Transaction management

This section describes facilities for transaction management.

This section describes the following:

10.4.1. Configure transaction timeout

It is possible to configure Neo4j to terminate transactions whose execution time has exceeded the configured timeout. To enable this feature, set dbms.transaction.timeout to some positive time interval value denoting the default transaction timeout. Setting dbms.transaction.timeout to 0 — which is the default value — disables the feature.

Example 10.8. Configure transaction timeout

Set the timeout to ten seconds.

dbms.transaction.timeout=10s

Configuring transaction timeout will have no effect on transactions executed with custom timeouts (via the Java API), as a custom timeout will override the value set for dbms.transaction.timeout.

The transaction timeout feature is also known as the transaction guard.

10.4.2. Configure lock acquisition timeout

An executing transaction may get stuck while waiting for some lock to be released by another transaction. A transaction in such state is not desirable, and in some cases it is better for the transaction to instead give up and fail.

To enable this feature, set dbms.lock.acquisition.timeout to some positive time interval value denoting the maximum time interval within which any particular lock should be acquired, before failing the transaction. Setting dbms.lock.acquisition.timeout to 0 — which is the default value — disables the lock acquisition timeout.

Example 10.9. Configure lock acquisition timeout

Set the timeout to ten seconds.

dbms.lock.acquisition.timeout=10s

10.4.3. List all running transactions

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

Syntax:

CALL dbms.listTransactions()

Returns:

Name Type Description

transactionId

String

This is the ID of the transaction.

username

String

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

metaData

Map

This is any metadata associated with the transaction.

startTime

String

This is the time at which the transaction was started.

protocol

String

The protocol used by connection issuing the transaction.

connectionId

String

The ID of the connection issuing the transaction. This field will be null if the transaction was issued using embedded API.

clientAddress

String

The client address of the connection issuing the transaction.

requestUri

String

The request URI used by the client connection issuing the transaction.

currentQueryId

String

This is the ID of the current query executed by transaction.

currentQuery

String

This is the current query executed by transaction.

activeLockCount

Integer

Count of active locks held by transaction.

status

String

Status of the executing transaction.

resourceInformation

Map

Information about what transaction is waiting for when it is blocked.

elapsedTimeMillis

Integer

This is the time in milliseconds that has elapsed since the transaction was started.

cpuTimeMillis

Integer

CPU time in milliseconds that has been actively spent executing the transaction.

waitTimeMillis

Integer

Wait time in milliseconds that has been spent waiting to acquire locks.

idleTimeMillis

Integer

Idle time in milliseconds.

allocatedBytes

Integer

Bytes allocated for the executing transaction. This number is cumulative over the duration of the transaction. For memory-intense or long-running transactions the value may be larger than the current memory allocation.

allocatedDirectBytes

Integer

Direct bytes used by the executing transaction.

pageHits

Integer

Page hits occurred during the execution.

pageFaults

Integer

Page faults occurred during the execution.

Example 10.10. Viewing transactions that are currently executing

The following example shows that the user 'alwood' is currently running dbms.listTransactions(). The procedure call yields specific information about the running transaction, namely transactionId, username, currentQuery, elapsedTimeMillis, requestUri, and status.

CALL dbms.listTransactions() YIELD transactionId, username, currentQuery, elapsedTimeMillis, requestUri, status
╒════════════════╤═══════════╤══════════════════════════════════════╤════════════════════╤════════════════╤═══════════════════╕
│"transactionId" │"username" │"currentQuery"                        │"elapsedTimeMillis" │"requestUri"    │"status"           │
╞════════════════╪═══════════╪══════════════════════════════════════╪════════════════════╪════════════════╪═══════════════════╡
│"transaction-22"│"alwood"   │"CALL dbms.listTransactions() YIELD   │"1"                 │"127.0.0.1:7687"│"Running"          │
│                │           │ transactionId, username, currentQuery│                    │                │                   │
│                │           │elapsedTime, requestUri, status"      │                    │                │                   │
└────────────────┴───────────┴──────────────────────────────────────┴────────────────────┴────────────────┴───────────────────┘
1 row