使用 SystemTap 追踪 PostgreSQL 事务执行
要使用 SystemTap 跟踪 PostgreSQL 执行事务,可以使用以下脚本:
# stap -e 'probe begin { printf('Tracing PostgreSQL transactions...
'); }
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/oYE3 著作权归作者所有。请勿转载和采集!