2

我一直在尝试解决 Heroku 上一些反复出现的 H12/13 错误。在用尽我可以在 Google/Heroku/Stack Overflow 上找到的所有内容后,我现在正在检查是否有一些长期运行的数据库查询导致了 Heroku 支持建议的问题。

更新:我在生产 Crane 实例上。根据下面接受的答案...看来您无法在 Heroku 上执行此操作。我能做的最好的就是按照下面的 SQL 过滤掉它们:

SELECT u.usename, (total_time / 1000 / 60) as total_minutes, 
       (total_time/calls) as average_time, query 
FROM pg_stat_statements p 
JOIN pg_user u ON (u.usesysid = p.userid) 
WHERE query != '<insufficient privilege>'
ORDER BY 2 
DESC LIMIT 10;  

我正在尝试使用 Craig Kerstien 非常有用的帖子 http://www.craigkerstiens.com/2013/01/10/more-on-postgres-performance/但遇到了一些权限问题。

当我查询 pg_stat_statements 表时,我得到一些运行时间较长的查询的“权限不足”,而且 Heroku 似乎不允许您更改用户权限。

有谁知道我如何更改权限在 Heroku 上查看这些查询?

heroku pg:psql --remote production
psql (9.2.2, server 9.2.4)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

d4k2qvm4tmu579=> SELECT 
d4k2qvm4tmu579->   (total_time / 1000 / 60) as total_minutes, 
d4k2qvm4tmu579->   (total_time/calls) as average_time, 
d4k2qvm4tmu579->   query 
d4k2qvm4tmu579-> FROM pg_stat_statements 
d4k2qvm4tmu579-> ORDER BY 1 DESC 
d4k2qvm4tmu579-> LIMIT 10;
  total_minutes   |   average_time    |          query           
------------------+-------------------+--------------------------
 121.755079699998 |  11.7572250919775 | <insufficient privilege>
 17.9371053166656 |  1.73208859315089 | <insufficient privilege>
 13.8710526000023 |  1.33945202190106 | <insufficient privilege>
 6.98494270000089 | 0.674497883626922 | <insufficient privilege>
 6.75377774999972 | 0.652175543095124 | <insufficient privilege>
 6.55192439999995 | 0.632683664174224 | <insufficient privilege>
 3.84014626666634 |  1.12786802880252 | <insufficient privilege>
 3.40574066666667 |  1399.61945205479 | <insufficient privilege>
 3.16332020000008 | 0.929081204384053 | <insufficient privilege>
 2.30192519999944 | 0.222284382614463 | <insufficient privilege>
(10 rows)
4

2 回答 2

2

I can't answer your question directly but maybe take a look at the pg-extra's plugin which brings a lot of this goodness directly to the Heroku CLI and returns data :)

https://github.com/heroku/heroku-pg-extras

于 2013-10-10T08:01:27.493 回答
1

您需要运行 Heroku Postgres 的生产级实例才能使用 pg_stat_statements。即使这样,它也只能向您显示由您的应用程序(或使用 heroku 提供的凭据的任何客户端)运行的查询的统计信息。您将无法查看对超级用户的查询(海报、collectd)。生产计划是起重机及以上(我相信)。

您可以通过加入 pg_user 来查看用户名:

SELECT u.usename, (total_time / 1000 / 60) as total_minutes, 
       (total_time/calls) as average_time, query 
FROM pg_stat_statements p 
JOIN pg_user u ON (u.usesysid = p.userid) ORDER BY 2 DESC LIMIT 10;
于 2013-10-10T18:54:49.617 回答