{"record":{"id":"16fb9e07f4f8beb4","repo":"benbjohnson/litestream","slug":"check-database-behind-replica-w","errorCode":null,"errorMessage":"check database behind replica: %w","messagePattern":"check database behind replica: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db.go","lineNumber":1122,"sourceCode":"\t} else if db.pageSize <= 0 {\n\t\treturn fmt.Errorf(\"invalid db page size: %d\", db.pageSize)\n\t}\n\n\t// Ensure meta directory structure exists.\n\tif err := internal.MkdirAll(db.metaPath, db.dirInfo); err != nil {\n\t\treturn err\n\t}\n\n\t// Ensure WAL has at least one frame in it.\n\tif err := db.ensureWALExists(ctx); err != nil {\n\t\treturn fmt.Errorf(\"ensure wal exists: %w\", err)\n\t}\n\n\t// Check if database is behind replica (issue #781).\n\t// This must happen before replica.Start() to detect restore scenarios.\n\tif db.Replica != nil {\n\t\tif err := db.checkDatabaseBehindReplica(ctx); err != nil {\n\t\t\treturn fmt.Errorf(\"check database behind replica: %w\", err)\n\t\t}\n\t}\n\n\t// If we have an existing replication files, ensure the headers match.\n\t// if err := db.verifyHeadersMatch(); err != nil {\n\t// \treturn fmt.Errorf(\"cannot determine last wal position: %w\", err)\n\t// }\n\n\t// TODO(gen): Generate diff of current LTX snapshot and save as next LTX file.\n\n\t// Start replication.\n\tif db.Replica != nil {\n\t\tdb.Replica.Start(db.ctx)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":1104,"sourceCodeEnd":1140,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/db.go#L1104-L1140","documentation":"db.Open's checkDatabaseBehindReplica (issue #781) failed. This pre-replica-start check reads the replica's TXID to detect a local database that is older than the remote backup (e.g. after a restore from an old copy); failure means the remote TXID could not be queried.","triggerScenarios":"Thrown at db.go:1122 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check replica connectivity and credentials","Inspect the wrapped replica client error","If the local DB is genuinely behind, restore from the replica or delete the stale database file"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}