{"record":{"id":"f1e2891e64920e2e","repo":"ankane/pghero","slug":"space-stats-not-enabled","errorCode":null,"errorMessage":"Space stats not enabled","messagePattern":"Space stats not enabled","errorType":"exception","errorClass":"PgHero::NotEnabled","httpStatus":null,"severity":"warning","filePath":"lib/pghero/methods/space.rb","lineNumber":89,"sourceCode":"              relation,\n              sizes[1] AS size_bytes\n            FROM\n              t\n            ORDER BY\n              1, 2\n          SQL\n          stats = select_all_stats(sql, {id: id, start_at: start_at})\n\n          stats.each do |r|\n            relation = [r[:schema], r[:relation]]\n            if sizes[relation]\n              r[:growth_bytes] = sizes[relation] - r[:size_bytes]\n            end\n            r.delete(:size_bytes)\n          end\n          stats\n        else\n          raise NotEnabled, \"Space stats not enabled\"\n        end\n      end\n\n      def relation_space_stats(relation, schema: \"public\")\n        if space_stats_enabled?\n          relation_sizes ||= self.relation_sizes\n          sizes = relation_sizes.map { |r| [[r[:schema], r[:relation]], r[:size_bytes]] }.to_h\n          start_at = 30.days.ago\n\n          sql = <<~SQL\n            SELECT\n              captured_at,\n              size AS size_bytes\n            FROM\n              pghero_space_stats\n            WHERE\n              database = :id\n              AND captured_at >= :start_at","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/ankane/pghero/blob/7edb57986ffd36f9d64f0830c4ccc90a5eac46d6/lib/pghero/methods/space.rb#L71-L107","documentation":"PgHero raises this from PgHero::Methods::Space#space_growth when space_stats_enabled? is false. space_growth computes per-relation growth_bytes by diffing the earliest snapshot in pghero_space_stats (last `days` days) against current relation_sizes, so it needs the pghero_space_stats capture table, which only exists after running the optional space-stats migration. PgHero raises NotEnabled instead of returning fake zero growth when the table is missing.","triggerScenarios":"Calling PgHero.space_growth(days: 7) or rendering the web UI space/growth view before `rails generate pghero:space_stats && rails db:migrate` has run; or in an environment (e.g. production) where that optional migration was never applied even though it was applied in development.","commonSituations":"New PgHero setup where only the query-stats generator was run; multi-environment apps where the optional migration is missing on staging/prod; apps that enabled space stats in one database entry of pghero.yml but call PgHero.space_growth on the primary connection that lacks the table.","solutions":["Run `rails generate pghero:space_stats` followed by `rails db:migrate` to create pghero_space_stats.","Schedule `rake pghero:capture_space_stats` daily (it records one snapshot per day) so growth over `days` is measurable.","If the feature is intentionally off, guard callers with `PgHero.space_stats_enabled?` or rescue PgHero::NotEnabled and use PgHero.relation_sizes for current sizes only."],"exampleFix":"# before - raises PgHero::NotEnabled: Space stats not enabled\nPgHero.space_growth(days: 7)\n\n# after\n# terminal:\n#   rails generate pghero:space_stats\n#   rails db:migrate\n# config/schedule.rb:\n#   every :day do\n#     rake \"pghero:capture_space_stats\"\n#   end\ngrowth = PgHero.space_growth(days: 7) if PgHero.space_stats_enabled?","handlingStrategy":"validation","validationCode":"return unless PgHero.space_stats_enabled?\ngrowth = PgHero.space_growth(days: 7)","typeGuard":"def space_stats_available?\n  PgHero.space_stats_enabled?\nend","tryCatchPattern":"begin\n  PgHero.space_growth(days: 7)\nrescue PgHero::NotEnabled\n  PgHero.relation_sizes # current sizes only, no growth\nend","preventionTips":["Apply the pghero:space_stats migration in every environment, including replicas used for reporting.","Schedule `rake pghero:capture_space_stats` daily; growth over `days` needs at least two daily snapshots.","Feature-detect with space_stats_enabled? before rendering growth UI."],"tags":["pghero","postgresql","rails","space-stats","configuration","not-enabled"],"backgroundTag":"optional-feature-not-enabled","analyzedSha":"7edb57986ffd36f9d64f0830c4ccc90a5eac46d6","analyzedAt":"2026-08-21T17:33:54.942Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}