{"record":{"id":"a0f11900561d1bac","repo":"ankane/pghero","slug":"invalid-connection-url","errorCode":null,"errorMessage":"Invalid connection URL","messagePattern":"Invalid connection URL","errorType":"exception","errorClass":"PgHero::Error","httpStatus":null,"severity":"critical","filePath":"lib/pghero/database.rb","lineNumber":127,"sourceCode":"          rescue LoadError\n            raise Error, \"pg_query required for filter_data\"\n          end\n        end\n      end\n\n      @filter_data\n    end\n\n    private\n\n    # check adapter lazily\n    def connection_model\n      unless @adapter_checked\n        # rough check for Postgres adapter\n        # keep this message generic so it's useful\n        # when empty url set in Docker image pghero.yml\n        unless @connection_model.connection_db_config.adapter.to_s.match?(/postg/i)\n          raise Error, \"Invalid connection URL\"\n        end\n        @adapter_checked = true\n      end\n\n      @connection_model\n    end\n\n    # just return the model\n    # do not start a connection\n    def build_connection_model\n      url = config[\"url\"]\n\n      # resolve spec\n      if !url && config[\"spec\"]\n        config_options = {env_name: PgHero.env, name: config[\"spec\"], include_hidden: true}\n        resolved = ActiveRecord::Base.configurations.configs_for(**config_options)\n        raise Error, \"Spec not found: #{config[\"spec\"]}\" unless resolved\n        url = resolved.configuration_hash","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/ankane/pghero/blob/7edb57986ffd36f9d64f0830c4ccc90a5eac46d6/lib/pghero/database.rb#L109-L145","documentation":"The first time a PgHero::Database touches its connection, connection_model checks that the resolved ActiveRecord database config's adapter matches /postg/i. Anything else - mysql2, sqlite3, or a blank/default adapter produced by an empty or unparsable url - raises Error \"Invalid connection URL\". The comment in the source notes the message is deliberately generic because the common case is an empty url in the Docker image's pghero.yml.","triggerScenarios":"config/pghero.yml with url: \"\" or a url missing the postgres:// scheme, so Rails resolves a non-Postgres (default) adapter; a url starting with mysql:// or sqlite:; a spec: entry that resolves to a non-Postgres block in database.yml; running the pghero Docker image without setting PGHERO_DATABASE_URL/DATABASE_URL.","commonSituations":"Standalone pghero container deployments where the env var is forgotten; migrating an app from MySQL and pghero still pointed at the old url; ERB in pghero.yml evaluating to an empty string in a missing environment.","solutions":["Set a full Postgres URL in config/pghero.yml: url: postgres://user:pass@host:5432/dbname","For the Docker image, provide the URL via the PGHERO_DATABASE_URL (or DATABASE_URL) environment variable","If using spec:, confirm the matching database.yml entry uses the postgresql adapter in the current RAILS_ENV","Test the URL outside pghero, e.g. psql \"postgres://user:pass@host:5432/dbname\" -c 'select 1'"],"exampleFix":"# config/pghero.yml - before\ndatabases:\n  primary:\n    url: \"\"\n\n# after\ndatabases:\n  primary:\n    url: postgres://user:pass@host:5432/dbname","handlingStrategy":"validation","validationCode":"# validate the url shape before pghero tries to connect\nurl = PgHero.config.dig(\"databases\", \"primary\", \"url\").to_s\nraise \"pghero url must start with postgres:// or postgresql://\" unless url.start_with?(\"postgres://\", \"postgresql://\")","typeGuard":null,"tryCatchPattern":"begin\n  PgHero.database.connection_model\nrescue PgHero::Error => e\n  # catch at health-check level: configuration is wrong, retrying will not help\n  report_config_error(\"pghero database connection: #{e.message}\")\nend","preventionTips":["Always specify the full postgres:// or postgresql:// scheme in pghero.yml urls","For the Docker image, set PGHERO_DATABASE_URL explicitly and fail deploys when it is blank","Smoke-test the URL with psql before pointing pghero at it"],"tags":["pghero","config","database-connection","postgres"],"backgroundTag":"invalid-database-url","analyzedSha":"7edb57986ffd36f9d64f0830c4ccc90a5eac46d6","analyzedAt":"2026-08-21T17:33:54.942Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}