https://www.cockroachlabs.com/blog/high-cpu-usage-postgres/

Top five queries by total execution time

To enable pg_stat_statements, add pg_stat_statements to shared_preload_libraries in the DB parameter group

SELECT
	query,
	calls,
	total_exec_time,
	rows
FROM
	pg_stat_statements
ORDER BY
	total_exec_time DESC
LIMIT
	5;

в RDS Aurora нужно включить предварительно pg_stat_statements, добавив в группе параметров pg_stat_statements в список shared_preload_libraries

SELECT
	query,
	calls,
	total_exec_time,
	rows
FROM
	aurora_stat_statements()
ORDER BY
	total_exec_time DESC
LIMIT
	5;

Current active connections

SELECT * FROM pg_stat_activity WHERE state = ‘active’;
SHOW max_connections;
SELECT
  pid,
  now() - pg_stat_activity.query_start AS duration,
  query,
  state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
Enter your comment. Wiki syntax is allowed:
 
  • devops/postgres_investigating_slowness.txt
  • Last modified: 2025/05/19 10:26
  • by admin