systemstap 追踪postgresql执行事务 transaction-start
要使用SystemTap跟踪PostgreSQL执行事务,可以使用以下脚本:
# stap -e 'probe begin { printf("Tracing PostgreSQL transactions...\n"); }
probe process("/usr/lib/postgresql/*/bin/postgres").function("StartTransactionCommand") {
printf("Transaction started at %d\n", gettimeofday_us());
}
probe process("/usr/lib/postgresql/*/bin/postgres").function("CommitTransactionCommand") {
printf("Transaction committed at %d\n", gettimeofday_us());
}
probe process("/usr/lib/postgresql/*/bin/postgres").function("AbortTransaction") {
printf("Transaction aborted at %d\n", gettimeofday_us());
}'
这个脚本会跟踪PostgreSQL进程中的三个函数:
- StartTransactionCommand:当一个新的事务开始时调用。
- CommitTransactionCommand:当一个事务提交时调用。
- AbortTransaction:当一个事务被中止时调用。
每个函数都会在它被调用时输出一个时间戳,以便您可以了解事务何时发生。
注意:在运行此脚本之前,请确保已安装SystemTap并具有足够的权限运行该命令
原文地址: https://www.cveoy.top/t/topic/hvOl 著作权归作者所有。请勿转载和采集!