{"record":{"id":"af6b0e810b0bfdfc","repo":"temporalio/temporal","slug":"rowsaffected-returned-error-when-initializing-dlq","errorCode":null,"errorMessage":"rowsAffected returned error when initializing DLQ metadata  %v: %v","messagePattern":"rowsAffected returned error when initializing DLQ metadata  (.+?): (.+?)","errorType":"exception","errorClass":"Unavailable","httpStatus":null,"severity":"error","filePath":"common/persistence/sql/queue.go","lineNumber":368,"sourceCode":") error {\n\t_, err := q.DB.SelectFromQueueMetadata(ctx, sqlplugin.QueueMetadataFilter{\n\t\tQueueType: q.getDLQTypeFromQueueType(),\n\t})\n\tswitch err {\n\tcase nil:\n\t\treturn nil\n\tcase sql.ErrNoRows:\n\t\tresult, err := q.DB.InsertIntoQueueMetadata(ctx, &sqlplugin.QueueMetadataRow{\n\t\t\tQueueType:    q.getDLQTypeFromQueueType(),\n\t\t\tData:         blob.Data,\n\t\t\tDataEncoding: blob.EncodingType.String(),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn serviceerror.NewUnavailablef(\"initializeDLQMetadata operation failed. Error %v\", err)\n\t\t}\n\t\trowsAffected, err := result.RowsAffected()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"rowsAffected returned error when initializing DLQ metadata  %v: %v\", q.queueType, err)\n\t\t}\n\t\tif rowsAffected != 1 {\n\t\t\treturn fmt.Errorf(\"rowsAffected returned %v DLQ metadata instead of one\", rowsAffected)\n\t\t}\n\t\treturn nil\n\tdefault:\n\t\treturn err\n\t}\n}\n\nfunc newQueueRow(\n\tqueueType persistence.QueueType,\n\tmessageID int64,\n\tblob *commonpb.DataBlob,\n) sqlplugin.QueueMessageRow {\n\n\treturn sqlplugin.QueueMessageRow{\n\t\tQueueType:       queueType,","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/sql/queue.go#L350-L386","documentation":"Thrown by initializeDLQMetadata in the SQL queue store after an INSERT of DLQ metadata succeeds, but result.RowsAffected() returns a driver error. Temporal expects exactly one metadata row to be created during DLQ initialization; if the driver cannot report affected-row counts, initialization cannot be verified and fails. This usually signals a database driver that does not support RowsAffected for this statement.","triggerScenarios":"Init() -> initializeDLQMetadata on a queue with no existing metadata row: SELECT returns sql.ErrNoRows, INSERT succeeds, then result.RowsAffected() itself returns an error from the SQL driver.","commonSituations":"Using a database or driver whose RowsAffected implementation is unsupported for INSERT statements; driver/connection issues right after the insert; non-MySQL/Postgres backends with partial driver support.","solutions":["Check that the SQL driver in use (go-sql-driver/mysql, lib/pq, sqlite) supports RowsAffected on INSERT — upgrade the driver to the latest version.","Inspect the wrapped driver error (%v at the end of the message) for the root cause (connection reset, unsupported method).","Verify the database backend is one of the officially supported ones (MySQL, PostgreSQL, SQLite).","Retry queue Init; if transient connection issues caused it, the next attempt may find the row already inserted and return nil early."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := q.Init(); err != nil {\n    if strings.Contains(err.Error(), \"rowsAffected returned error\") {\n        // transient driver issue; retry with backoff\n    }\n    return err\n}","preventionTips":["Use only supported SQL drivers (MySQL, Postgres, SQLite) with current versions.","Monitor DB connection health to catch drivers failing mid-statement.","Read the trailing wrapped driver error to pinpoint root cause before retrying."],"tags":["database","sql-driver","dlq","persistence"],"backgroundTag":"rows-affected-unsupported","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}