Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article6 min readViews1

How to Find Long-Running Transactions in MySQL 8.4 Without Terminating Connections

Transaction age and lock wait duration are distinct metrics. Two read-only queries help identify old InnoDB transactions and gather data for further investigation.

Comments 0

Unmarked clocks next to an external drive on a desk surface. Generated illustration.
In this article

The exchange with 1C has completed, yet the store database continues to experience delays. One possible culprit is a transaction that started long ago and remains unfinished. Its age does not equal the duration of the current query: between SQL operations, the application may be waiting for an external response while keeping the transaction open.

This guide targets MySQL 8.4 with InnoDB and assumes an existing, authorized session for diagnostics. It is not intended for MariaDB. Syntax and field values have been verified against the official MySQL 8.4 documentation as of September 26, 2026. The queries read only; they were not executed on a MySQL 8.4 testbed during material preparation. Terminating connections, modifying parameters, or fixing application code are outside the scope of this guide.

Reading INFORMATION_SCHEMA.INNODB_TRX requires the already granted privilege PROCESS. Use the dedicated diagnostic account. Do not elevate the permissions of a standard store account for this check. If access is denied, forward the request to an administrator; an access error does not indicate the absence of long-running transactions.

First, confirm the server and observation point

In the SQL session, execute:

SELECT VERSION();

You need the MySQL 8.4 server version, not the one installed on the client's local machine. If the connection points to a replica, the observation applies to that replica. It does not describe application transactions on another node. In a managed database, some diagnostic capabilities may be restricted by the provider; these restrictions must not be bypassed.

Before collecting data, record the incident time and the node role. The diagnostic session must use a consistent connection mode; do not intentionally open a long-running transaction for observation. Also preserve external signs of latency: which exchange stage or buyer action was waiting for a response, and when this occurred.

Select the oldest visible transactions

The following query returns up to twenty rows, starting with the earliest by start time. It does not read order contents and does not output the executing SQL text:

SELECT TRX_ID, TRX_MYSQL_THREAD_ID, TRX_STATE, TRX_STARTED, TIMESTAMPDIFF(SECOND, TRX_STARTED, NOW()) AS age_seconds, TRX_WAIT_STARTED FROM INFORMATION_SCHEMA.INNODB_TRX ORDER BY TRX_STARTED LIMIT 20;

The field TRX_STARTED contains the transaction start time. The expression TIMESTAMPDIFF(SECOND, TRX_STARTED, NOW()) calculates the difference in seconds at the moment of the query; age_seconds is the name of this column as defined by us. Preserve the original timestamp alongside the calculated age. When correlating with application logs, account for time zones, and before drawing conclusions regarding anomalous negative values, verify the time and observation context.

TRX_MYSQL_THREAD_ID links a transaction to a MySQL connection. This is not a Linux process ID or an order number. TRX_ID refers to the transaction; internal read optimizations affect how its identifier is assigned, so do not treat it as a universal counter for all database activity.

The limit LIMIT 20 reduces the result set, but does not guarantee that only twenty internal objects are viewed. For sorting, the server may need to process more diagnostic data. Do not run a query in a frequent infinite loop on an overloaded database. Start with a single snapshot and repeat it after a meaningful interval, if the server state allows.

Separate transaction age from lock wait time

In TRX_STATE, states such as RUNNING, LOCK WAIT, ROLLING BACK, and COMMITTING are possible. They describe different stages. The value of RUNNING alone does not prove that the connection continuously executed a single SQL query throughout. To find the current operation, an administrator may need additional information about the connection.

During LOCK WAIT, the field TRX_WAIT_STARTED shows the start of the lock wait. It can be significantly later than TRX_STARTED. A conditional example: a transaction has existed for 600 seconds, but the lock has been waited for only in the last 20 seconds. Attributing all ten minutes to a single lock would be an error. The reverse is also incorrect: an old transaction without a current wait is not necessarily harmless to others.

The presence of LOCK WAIT does not yet indicate who holds the required resource. To establish a connection between the waiting and blocking processes, MySQL 8.4 provides the Performance Schema tables data_lock_waits and data_locks. This is the next stage of the investigation. Do not simply assign blame to the first row with the highest age.

An old transaction may be an expected part of allowed processing, or it may remain open due to an application error. Long-running reads can also hold an old data snapshot and hinder the cleanup of unnecessary row versions. Therefore, the absence of order changes at the current moment does not rule out an impact on InnoDB operations. However, age alone does not determine the damage or the intervention method.

A repeat snapshot helps find the continuation of the history

Repeat the same query at a consistent interval and compare the connection ID, start time, and state. If the row is missing, the transaction may have completed between measurements. If it persists with the same start time, its age should have increased by approximately the interval duration. Do not merge records solely based on the connection ID after a disconnect and reconnection.

Transaction data and a separate list of connections do not form a guaranteed consistent, static snapshot. MySQL documentation warns of potential temporal inconsistencies between them. By the time you switch from one source to another, the query may already have finished. A missing row in the second source requires a time check, not an immediate conclusion about database corruption.

An empty result only indicates that no matching transactions were found in the accessible table at the moment of observation. It does not prove the absence of prior locks, slow queries outside the interval, or issues with other storage engines. The guidance is limited to the current InnoDB state on the selected server.

Correlate the finding with the application operation

For a responsible developer, prepare the snapshot time, server version and role, connection ID, transaction start time, its state, and the moment the wait began. Add an anonymized description of the operation, such as importing a specific group of products. Passwords, full order details, and active tokens are not included in this package.

The transaction table contains the TRX_QUERY field, but the provided query intentionally does not request it. The SQL text may include values from customer data. If the investigation cannot proceed without it, the administrator collects the necessary fragment using an authorized method and restricts the recipient list. First, it is useful to understand which application owns the connection and what it was waiting for.

Do not terminate a connection simply because it is the oldest. An abrupt termination can trigger a lengthy rollback, disrupt the exchange, and cause the application to retry the operation. The decision to intervene must be made only after identifying the owner, any uncommitted changes, and the recovery plan. The outcome of this guidance is a verified trail for diagnostics, not an automatically selected target for termination.

Discussion 0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.