如何删除postgresql噪音

时间:2011-12-09 16:13:39

标签: ruby-on-rails ruby

我正在使用Ruby on Rails 3.1.1,我正在使用pg gem。

在我的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'

2 个答案:

答案 0 :(得分:0)

我相信这个宝石应该有助https://github.com/dolzenko/silent-postgres

用法非常简单:只需在您的Gemfile中添加“silent-postgres”。

答案 1 :(得分:0)

这是一个monkeypatch我添加到配置/初始化程序,以沉默这一个令人讨厌的日志行:

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