{"record":{"id":"036a6499ef32af12","repo":"ory/hydra","slug":"dsn-scheme-postgres-declares-a-postgresql-datab","errorCode":null,"errorMessage":"DSN scheme postgres:// declares a PostgreSQL database but the server is CockroachDB. Replace the scheme with cockroach:// so that the service picks the correct migrations and SQL dialect. Server reported: %q.","messagePattern":"DSN scheme postgres:// declares a PostgreSQL database but the server is CockroachDB\\. Replace the scheme with cockroach:// so that the service picks the correct migrations and SQL dialect\\. Server reported: %q\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/popx/dialect_check.go","lineNumber":60,"sourceCode":"\tyugabyteVersionMarker = \"-YB-\"\n)\n\nfunc checkDialect(declared, version string, yugabyteDialectSupported bool) error {\n\tdetectedCockroach := strings.Contains(version, \"CockroachDB\")\n\tdetectedYugabyte := strings.Contains(version, yugabyteVersionMarker)\n\tswitch {\n\tcase declared == dbal.DriverCockroachDB && !detectedCockroach:\n\t\treturn errors.Errorf(\n\t\t\t\"DSN scheme cockroach:// declares a CockroachDB database but the server is not CockroachDB. Server reported: %q. Use a postgres:// DSN, or point the service at a CockroachDB cluster.\",\n\t\t\tfirstLine(version),\n\t\t)\n\tcase declared == dbal.DriverYugabyteDB && !detectedYugabyte:\n\t\treturn errors.Errorf(\n\t\t\t\"DSN scheme yugabyte:// declares a YugabyteDB database but the server is not YugabyteDB. Server reported: %q. Use a DSN scheme matching the actual server, or point the service at a YugabyteDB cluster.\",\n\t\t\tfirstLine(version),\n\t\t)\n\tcase declared == namePostgres && detectedCockroach:\n\t\treturn errors.Errorf(\n\t\t\t\"DSN scheme postgres:// declares a PostgreSQL database but the server is CockroachDB. Replace the scheme with cockroach:// so that the service picks the correct migrations and SQL dialect. Server reported: %q\",\n\t\t\tfirstLine(version),\n\t\t)\n\tcase declared == namePostgres && detectedYugabyte && yugabyteDialectSupported:\n\t\treturn errors.Errorf(\n\t\t\t\"DSN scheme postgres:// declares a PostgreSQL database but the server is YugabyteDB. Replace the scheme with yugabyte:// (supported in Ory Enterprise License builds) so that the service picks the correct migrations. Server reported: %q\",\n\t\t\tfirstLine(version),\n\t\t)\n\t}\n\treturn nil\n}\n\nfunc firstLine(s string) string {\n\tif i := strings.IndexByte(s, '\\n'); i >= 0 {\n\t\treturn s[:i]\n\t}\n\treturn s\n}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/popx/dialect_check.go#L42-L78","documentation":"VerifyDialect distinguishes PostgreSQL, CockroachDB, and YugabyteDB, which all speak the Postgres wire protocol. When the DSN is declared as postgres:// but SELECT version() reports a CockroachDB server, checkDialect (oryx/popx/dialect_check.go:59) throws this error to prevent the wrong migrations and SQL dialect from being silently applied. Running with the wrong dialect can produce broken schemas.","triggerScenarios":"Calling VerifyDialect(ctx, conn) where conn's DSN scheme is postgres:// while the connected server's version() output contains \"CockroachDB\".","commonSituations":"Operator reuses a PostgreSQL DSN from another environment that actually points at a CockroachDB cluster; copy-pasted connection strings where only host/port were changed; managed-DB provisioning where a CockroachDB instance was created instead of Postgres.","solutions":["Change the DSN scheme in your config/DSN from postgres:// to cockroach:// so the service selects CockroachDB migrations and dialect","Verify you are connecting to the intended server: check host, port, and that SELECT version() matches the expected database","If the server really is CockroachDB but you need Postgres semantics, provision an actual PostgreSQL instance instead"],"exampleFix":"// before\nDSN=postgres://user:pass@roach-host:26257/defaultdb?sslmode=disable\n// after\nDSN=cockroach://user:pass@roach-host:26257/defaultdb?sslmode=disable","handlingStrategy":"validation","validationCode":"// before connecting, check the server matches the declared scheme\nvar version string\nif err := conn.RawQuery(\"SELECT version()\").First(&version); err != nil { return err }\nif strings.Contains(version, \"CockroachDB\") && conn.Dialect.Name() == \"postgres\" {\n    return errors.New(\"DSN scheme must be cockroach:// for this server\")\n}","typeGuard":null,"tryCatchPattern":"if err := popx.VerifyDialect(ctx, conn); err != nil {\n    log.Fatalf(\"dialect verification failed: %v\", err)\n}","preventionTips":["Derive the DSN scheme from the actual provisioned database type, not from a shared template","Run VerifyDialect at startup so mismatches fail fast","Keep separate DSN configs per environment and never copy across database engines","Pin database engine type in infrastructure-as-code to prevent accidental swaps"],"tags":["database","dsn","cockroachdb","postgresql","config"],"backgroundTag":"dsn-dialect-mismatch","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}