2011-12-09 67 views
5

我正在使用Ruby on Rails 3.1.1,並且使用pg gem。如何清除postgresql噪音

在我Gemfile.lock的,這是我有

pg (0.11.0) 

我的日誌充滿了類似下面給出的信息。我沒有得到與sqlite3的噪音。我怎樣才能抑制噪音。

PK and serial sequence (1.6ms) SELECT attr.attname, seq.relname 
FROM pg_class seq, 
pg_attribute attr, 
pg_depend dep, 
pg_namespace name, 
pg_constraint cons 
WHERE seq.oid = dep.objid 
AND seq.relkind = 'S' 
AND attr.attrelid = dep.refobjid 
AND attr.attnum = dep.refobjsubid 
AND attr.attrelid = cons.conrelid 
AND attr.attnum = cons.conkey[1] 
AND cons.contype = 'p' 
AND dep.refobjid = '"companies_users"'::regclass 
    PK and custom sequence (0.8ms) SELECT attr.attname, 
CASE 
WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN 
substr(split_part(def.adsrc, '''', 2), 
strpos(split_part(def.adsrc, '''', 2), '.')+1) 
ELSE split_part(def.adsrc, '''', 2) 
END 
FROM pg_class t 
JOIN pg_attribute attr ON (t.oid = attrelid) 
JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum) 
JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1]) 
WHERE t.oid = '"companies_users"'::regclass 
AND cons.contype = 'p' 
AND def.adsrc ~* 'nextval' 

回答

0

我相信這種寶石應該幫助https://github.com/dolzenko/silent-postgres

的用法很簡單:只需添加「無聲的Postgres」到你的Gemfile。

+0

'無聲postgres'抑制'注意:'線和相似。問題是關於由ActiveRecord生成和運行的查詢,具體爲'ActiveRecord :: ConnectionAdapters :: PostgreSQLAdapter#pk_and_sequence_for'。 – willglynn

+0

我也不明白爲什麼rails會一直問。我沒有看到任何改變。 – mcr

0

這裏有一個猴補丁我加入到配置/ initialisers沉默只是這一個惱人的日誌行:

if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) 
    module ActiveRecord 
    module ConnectionAdapters 
     class PostgreSQLAdapter 
     def pk_and_sequence_for_with_silenced_logging(table) 
      log_level = ActiveRecord::Base.logger.level 
      ActiveRecord::Base.logger.level = Logger::WARN 
      pk_and_sequence_for_without_silenced_logging(table) 
     ensure 
      ActiveRecord::Base.logger.level = log_level 
     end 
     alias_method_chain(:pk_and_sequence_for, :silenced_logging) 
     end 
    end 
    end 
end