{"record":{"id":"495e71a97bdcc4c3","repo":"ory/hydra","slug":"could-not-query-database-version-to-verify-dialect","errorCode":null,"errorMessage":"could not query database version to verify dialect","messagePattern":"could not query database version to verify dialect","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/popx/dialect_check.go","lineNumber":32,"sourceCode":")\n\n// VerifyDialect makes sure the declared SQL dialect matches the actual\n// database server. It distinguishes PostgreSQL, CockroachDB, and YugabyteDB:\n// all three speak the Postgres wire protocol, so an operator can easily point\n// a service configured for one at a server running another. That mismatch\n// silently selects the wrong dialect-specific migrations and produces broken\n// schemas.\n//\n// Other dialects (MySQL, SQLite) are skipped.\nfunc VerifyDialect(ctx context.Context, conn *pop.Connection) error {\n\tdeclared := conn.Dialect.Name()\n\tif declared != namePostgres && declared != dbal.DriverCockroachDB && declared != dbal.DriverYugabyteDB {\n\t\treturn nil\n\t}\n\n\tvar version string\n\tif err := conn.WithContext(ctx).RawQuery(\"SELECT version() AS version\").First(&version); err != nil {\n\t\treturn errors.Wrap(err, \"could not query database version to verify dialect\")\n\t}\n\treturn checkDialect(declared, version, pop.DialectSupported(dbal.DriverYugabyteDB))\n}\n\nconst (\n\tnamePostgres = \"postgres\"\n\n\t// yugabyteVersionMarker identifies a YugabyteDB server in the output of\n\t// SELECT version() (e.g. \"PostgreSQL 11.2-YB-2025.2.4.0-b122 ...\").\n\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(","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/popx/dialect_check.go#L14-L50","documentation":"VerifyDialect validates that the declared DSN dialect (postgres, cockroach, yugabyte) matches the actual server by running SELECT version(). If the raw query fails to return a version row, the check cannot proceed and wraps the driver error with this message. It is a pre-flight guard, not a connection failure per se.","triggerScenarios":"Calling VerifyDialect with a connection whose query 'SELECT version() AS version' fails: connection dropped mid-check, insufficient permissions, or the target server does not support version().","commonSituations":"Network interruption between connect and the dialect check; user lacking permission to execute SELECT version(); pointing at a non-PostgreSQL-protocol server that accepts connections but rejects the query.","solutions":["Check the underlying wrapped error for the real cause (connection refused, auth, timeout)","Test connectivity manually: psql '<DSN>' -c 'SELECT version()'","Verify the DB user has permission to run SELECT version()","Confirm network/firewall/keepalives allow the connection to stay up during migration start"],"exampleFix":"// verify before starting\npsql \"postgres://user@host/db\" -c 'SELECT version();'\n// if it errors, fix network/credentials before running migrations","handlingStrategy":"try-catch","validationCode":"func checkDBReady(db *pop.Connection) error {\n    var v string\n    return db.WithContext(context.Background()).RawQuery(\"SELECT version() AS version\").First(&v)\n}","typeGuard":null,"tryCatchPattern":"if err := VerifyDialect(ctx, conn, dsn); err != nil {\n    if strings.Contains(err.Error(), \"could not query database version\") {\n        return fmt.Errorf(\"database unreachable or unauthorized during dialect check: %w\", err)\n    }\n    return err\n}","preventionTips":["Run psql '<DSN>' -c 'SELECT version()' as the same user before deploying","Grant the migration user permission to read version() (default for any authenticated user)","Check network/firewall/keepalive settings so connections survive startup checks","Log the wrapped driver error to distinguish auth vs connectivity causes"],"tags":["database","postgres","dialect","query"],"backgroundTag":"database-query-failed","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"}