module PgsqlStats class Sequence attr_accessor :oid, :name, :schema_name, :blocks_read, :cache_hits def initialize(connection, row) @connection = connection load(row) end def refresh load(@connection.select_one("SELECT * FROM pg_statio_all_sequences WHERE relid = #{oid}")) end def cache_hit_rate cache_hits.to_f / (blocks_read + cache_hits) * 100 end private def load(row) self.oid = row["relid"].to_i self.name = row["relname"] self.schema_name = row["schemaname"] self.blocks_read = row["blks_read"].to_i self.cache_hits = row["blks_hit"].to_i end end end