What is a big deal? Transactions that run for a long time and are not committed for a long time can be called large transactions. The causes of big business
The impact of big events
How to query large transactions **Note**: The SQL operations in this article are based on MySQL version 5.7 Take the query execution time of more than 10 seconds as an example: select \* from information\_schema.innodb\_trx where TIME\_TO\_SEC(timediff(now(),trx\_started))>10 How to avoid big transactions General solution
Solution based on mysql5.7
Appendix Query Transaction Related Statements **Note**: SQL statements are based on MySQL 5.7 version # Query all running transactions and their running time select t.\*,to\_seconds(now())-to\_seconds(t.trx\_started) idle\_time from INFORMATION\_SCHEMA.INNODB\_TRX t # Query transaction details and executed SQL select now(),(UNIX\_TIMESTAMP(now()) - UNIX\_TIMESTAMP(a.trx\_started)) diff\_sec,b.id,b.user,b.host,b.db,d.SQL\_TEXT from information\_schema.innodb\_trx a inner join information\_schema.PROCESSLIST b on a.TRX\_MYSQL\_THREAD\_ID=b.id and b.command = 'Sleep' inner join performance\_schema.threads c ON b.id = c.PROCESSLIST\_ID inner join performance\_schema.events\_statements\_current d ON d.THREAD\_ID = c.THREAD\_ID; # Query all historical SQL records executed by the transaction SELECT ps.id 'PROCESS ID', ps.USER, ps.HOST, esh.EVENT_ID, trx.trx_started, esh.event\_name 'EVENT NAME', esh.sql\_text 'SQL', ps.time FROM PERFORMANCE\_SCHEMA.events\_statements\_history esh JOIN PERFORMANCE\_SCHEMA.threads th ON esh.thread\_id = th.thread\_id JOIN information\_schema.PROCESSLIST ps ON ps.id = th.processlist\_id LEFT JOIN information\_schema.innodb\_trx trx ON trx.trx\_mysql\_thread\_id = ps.id WHERE trx.trx_id IS NOT NULL AND ps.USER != 'SYSTEM\_USER' ORDER BY esh.EVENT_ID; # Simple query transaction lock select \* from sys.innodb\_lock\_waits #Query transaction lock detailsSELECT tmp.\*, c.SQL\_Text blocking\_sql\_text, p.HOST blocking\_host FROM ( SELECT r.trx_state watching_trx_state, r.trx_id waiting_trx_id, r.trx\_mysql\_thread\_Id waiting\_thread, r.trx_query waiting_query, b.trx_state blocking_trx_state, b.trx_id blocking_trx_id, b.trx\_mysql\_thread\_id blocking\_thread, b.trx_query blocking_query FROM information\_schema.innodb\_lock\_waits w INNER JOIN information\_schema.innodb\_trx b ON b.trx\_id = w.blocking\_trx\_id INNER JOIN information\_schema.innodb\_trx r ON r.trx\_id = w.requesting\_trx\_id ) tmp, information\_schema.PROCESSLIST p, PERFORMANCE\_SCHEMA.events\_statements\_current c, PERFORMANCE\_SCHEMA.threads t WHERE tmp.blocking_thread = p.id AND t.thread_id = c.THREAD_ID AND t.PROCESSLIST_ID = p.id The above is the details of how to avoid large transactions in MySQL and how to solve large transactions. For more information about MySQL large transactions, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Implementation of multiple instances of tomcat on a single machine
>>: Implementation of TypeScript in React project
1. Download the pip installation package accordin...
Analyze four common methods and principles: float...
When deploying uwsgi+nginx proxy Django, access u...
As one of the most commonly used and important ut...
This article example shares the specific code of ...
This example takes the installation of Python 3.8...
Table of contents What is Routing Basic use of pu...
DIV+css structure Are you learning CSS layout? Sti...
1. Download the virtual machine version 15.5.1 I ...
Table of contents Why is addEventListener needed?...
In a recent problem, there is such a phenomenon: ...
Under the requirements of today's responsive ...
Preface "High Performance MySQL" mentio...
In Linux operations, we often replace and count s...
1 Check whether the kernel has a tun module modin...