How to remove postgresql noise

I am using Ruby on Rails 3.1.1 and I am using pg gem.

In my Gemfile.lock, this is what I have

pg (0.11.0)

My journal is filled with information like the one below. I do not get this noise with sqlite3. How can I suppress the noise.

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'
+5
source share
2 answers

I believe this gem should help https://github.com/dolzenko/silent-postgres

The usage is pretty simple: just add "silent-postgres" to your Gemfile.

0
source

Here's the monkeypatch I added to config / initialisers to disable only this annoying log line:

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
0
source

All Articles