Oracle、MySQL、PostGreSQL、SQL Server-查询每秒事务数
在Oracle、MySQL、PostgreSQL和SQL Server中,查询每秒事务数(TPS - Transactions Per Second)通常需要使用数据库的内置性能监控工具或视图。以下是针对这几种数据库的查询示例:
Oracle:
SELECT ROUND(SUM(tps) / (SUM(end_time) - SUM(start_time)), 2) AS tps
FROM (
SELECT COUNT(*) AS tps,
(end_time - start_time) * 86400 AS end_time,
(end_time - start_time) * 86400 + 1 AS start_time
FROM v$transaction
GROUP BY end_time, start_time
);
MySQL:
SELECT ROUND(COUNT(*) / (TIMESTAMPDIFF(SECOND, MIN(time), MAX(time))), 2) AS tps
FROM information_schema.INNODB_TRX;
PostgreSQL:
SELECT ROUND(COUNT(*) / EXTRACT(EPOCH FROM (MAX(time) - MIN(time))), 2) AS tps
FROM pg_stat_activity
WHERE state = 'active';
SQL Server:
SELECT ROUND(COUNT(*) / DATEDIFF(second, MIN(transaction_begin_time), MAX(transaction_begin_time)), 2) AS tps
FROM sys.dm_tran_active_transactions;
请注意,这些查询假设您有足够的权限来访问相关的性能监控视图或信息模式。在实际应用中,您可能需要根据您的具体需求调整这些查询,例如,通过添加过滤条件或者调整时间范围等。
评论已关闭