开发者

How to shorten/suppress the "get column attributes" query in the log file when using PostgreSQL with Rails

开发者 https://www.devze.com 2023-02-28 06:11 出处:网络
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 m开发者_开发知识库ytable, which fit nicely into one line in the

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 m开发者_开发知识库ytable, 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.


Try the silent-postgres gem.

You can do this in Rails 3 by adding gem "silent-postgres" to your Gemfile

0

精彩评论

暂无评论...
验证码 换一张
取 消