{"record":{"id":"b1512c744480dc31","repo":"ankane/pghero","slug":"suggested-indexes-not-enabled","errorCode":null,"errorMessage":"Suggested indexes not enabled","messagePattern":"Suggested indexes not enabled","errorType":"exception","errorClass":"PgHero::NotEnabled","httpStatus":null,"severity":"warning","filePath":"lib/pghero/methods/suggested_indexes.rb","lineNumber":58,"sourceCode":"                  indexes += existing_columns[\"gist\"][index[:table]]\n\n                  # hash indexes work for equality\n                  indexes += existing_columns[\"hash\"][index[:table]] if best_index[:structure][:where].all? { |v| v[:op] == \"=\" }\n\n                  # brin indexes work for all\n                  indexes += existing_columns[\"brin\"][index[:table]]\n                end\n\n                covering_index = indexes.find { |e| index_covers?(e.map { |v| v.delete_suffix(\" inet_ops\") }, index[:columns]) }\n                if covering_index\n                  best_index[:covering_index] = covering_index\n                  best_index[:explanation] = \"Covered by index on (#{covering_index.join(\", \")})\"\n                end\n              end\n            end\n          end\n        else\n          raise NotEnabled, \"Suggested indexes not enabled\"\n        end\n\n        best_indexes\n      end\n\n      def suggested_indexes(suggested_indexes_by_query: nil, **options)\n        indexes = []\n\n        (suggested_indexes_by_query || self.suggested_indexes_by_query(**options)).select { |_s, i| i[:found] && !i[:covering_index] }.group_by { |_s, i| i[:index] }.each do |index, group|\n          details = {}\n          group.map(&:second).each do |g|\n            details = details.except(:index).deep_merge(g)\n          end\n          indexes << index.merge(queries: group.map(&:first), details: details)\n        end\n\n        indexes.sort_by { |i| [i[:table], i[:columns]] }\n      end","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/ankane/pghero/blob/7edb57986ffd36f9d64f0830c4ccc90a5eac46d6/lib/pghero/methods/suggested_indexes.rb#L40-L76","documentation":"PgHero raises this from PgHero::Methods::SuggestedIndexes#suggested_indexes_by_query when suggested_indexes_enabled? is false. That predicate requires three things: the PgQuery gem is loaded, its version is >= 6, and query_stats_enabled? is true (pg_stat_statements is installed and readable). Suggested indexes work by parsing the SQL text of your most time-consuming queries (historical query stats from the last 24 hours), so without a modern pg_query parser and query stats there is nothing to analyze.","triggerScenarios":"Calling PgHero.suggested_indexes or PgHero.suggested_indexes_by_query when the pg_query gem is absent from the bundle (it is an optional dependency) or pinned below version 6; or when pg_stat_statements is not installed/preloaded so query_stats_enabled? returns false; the web UI suggested-indexes tab hits the same path.","commonSituations":"Upgrading pghero to a version requiring pg_query 6 while Gemfile.lock still holds pg_query 4/5; deploying to production where pg_stat_statements was never in shared_preload_libraries; using a managed Postgres plan that disallows the extension; JRuby or platforms where the pg_query native extension failed to build.","solutions":["Add `gem \"pg_query\", \">= 6\"` to your Gemfile and run `bundle install` (verify with PgHero.suggested_indexes_enabled?).","Make pg_stat_statements available: ensure shared_preload_libraries includes it in postgresql.conf (restart required), then PgHero.enable_query_stats or `CREATE EXTENSION pg_stat_statements`.","Confirm queries exist to analyze: query_stats_enabled? must be true and there must be captured stats (for historical input, the pghero_query_stats capture job must have run).","If intentionally disabled, guard with `PgHero.suggested_indexes_enabled?` or rescue PgHero::NotEnabled."],"exampleFix":"# before - raises PgHero::NotEnabled: Suggested indexes not enabled\nPgHero.suggested_indexes\n\n# after\n# Gemfile:\n#   gem \"pg_query\", \">= 6\"\n# postgresql.conf:\n#   shared_preload_libraries = 'pg_stat_statements'\n# then: CREATE EXTENSION pg_stat_statements; (or PgHero.enable_query_stats)\nindexes = PgHero.suggested_indexes if PgHero.suggested_indexes_enabled?","handlingStrategy":"validation","validationCode":"return unless PgHero.suggested_indexes_enabled?\nsuggestions = PgHero.suggested_indexes","typeGuard":"def suggested_indexes_available?\n  PgHero.suggested_indexes_enabled? # pg_query >= 6 present AND query stats readable\nend","tryCatchPattern":"begin\n  PgHero.suggested_indexes\nrescue PgHero::NotEnabled\n  Rails.logger.info(\"Suggested indexes unavailable (needs pg_query >= 6 and pg_stat_statements)\")\n  []\nend","preventionTips":["Pin `gem \"pg_query\", \">= 6\"` explicitly so bundler can't resolve to an older major.","Add pg_stat_statements to shared_preload_libraries in your infrastructure templates.","Run PgHero.suggested_indexes_enabled? in CI smoke tests against a production-like database."],"tags":["pghero","postgresql","rails","pg-query","suggested-indexes","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"}