如何缩短/抑制“获取列属性”将 PostgreSQL 与 Rails 结合使用时在日志文件中查询
Rails 喜欢获取您正在使用的每个表的列属性。在 MySQL 上,这就像(如果我记得的话)类似 DESCRIBE mytable
的东西一样简单,它非常适合日志中的一行。
但对于 PostgreSQL,它会更加复杂,结果如下:
SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"mytable"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
问题在于,这会占用开发日志中的大量行,并使其难以阅读。
所以我想知道是否有一种好方法来抑制或总结此类查询的日志记录。
我觉得这是一个非常优先的第一世界问题,但有一段时间有点麻烦了。
Rails likes to get column attributes for each table you're using. On MySQL this was as simple as (if I recall) something like DESCRIBE mytable
, which fit nicely into one line in the log.
But with PostgreSQL, it's more involved and turns out to be the following:
SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"mytable"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
The trouble is that this takes up a heck of a lot of lines in the development log and makes it somewhat harder to peruse.
So I'm wondering if there's a good way to suppress or summarize the logging of this sort of query in particular.
I feel like this is such a privileged firstworldproblem, but it's been slightly troublesome for a while.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
silent-postgres
gem。您可以在 Rails 3 中通过将
gem "silent-postgres"
添加到Gemfile
中来执行此操作Try the
silent-postgres
gem.You can do this in Rails 3 by adding
gem "silent-postgres"
to yourGemfile