{"record":{"id":"ea1e77eda304a933","repo":"vitessio/vitess","slug":"getpreviousgtids-previous-gtids-not-found","errorCode":null,"errorMessage":"GetPreviousGTIDs: previous GTIDs not found","messagePattern":"GetPreviousGTIDs: previous GTIDs not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/replication.go","lineNumber":1217,"sourceCode":"\treturn binaryLogs, err\n}\n\n// GetPreviousGTIDs is part of the MysqlDaemon interface.\nfunc (mysqld *Mysqld) GetPreviousGTIDs(ctx context.Context, binlog string) (previousGtids string, err error) {\n\tquery := fmt.Sprintf(\"SHOW BINLOG EVENTS IN '%s' LIMIT 2\", binlog)\n\tqr, err := mysqld.FetchSuperQuery(ctx, query)\n\tif err != nil {\n\t\treturn previousGtids, err\n\t}\n\tpreviousGtidsFound := false\n\tfor _, row := range qr.Named().Rows {\n\t\tif row.AsString(\"Event_type\", \"\") == \"Previous_gtids\" {\n\t\t\tpreviousGtids = row.AsString(\"Info\", \"\")\n\t\t\tpreviousGtidsFound = true\n\t\t}\n\t}\n\tif !previousGtidsFound {\n\t\treturn previousGtids, errors.New(\"GetPreviousGTIDs: previous GTIDs not found\")\n\t}\n\treturn previousGtids, nil\n}\n\nvar ErrNoSemiSync = errors.New(\"semi-sync plugin not loaded\")\n\nfunc (mysqld *Mysqld) SemiSyncType(ctx context.Context) mysql.SemiSyncType {\n\tif mysqld.semiSyncType == mysql.SemiSyncTypeUnknown {\n\t\tmysqld.semiSyncType, _ = mysqld.SemiSyncExtensionLoaded(ctx)\n\t}\n\treturn mysqld.semiSyncType\n}\n\nfunc (mysqld *Mysqld) enableSemiSyncQuery(ctx context.Context) (string, error) {\n\tswitch mysqld.SemiSyncType(ctx) {\n\tcase mysql.SemiSyncTypeSource:\n\t\treturn \"SET GLOBAL rpl_semi_sync_source_enabled = %v, GLOBAL rpl_semi_sync_replica_enabled = %v\", nil\n\tcase mysql.SemiSyncTypeMaster:","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/replication.go#L1199-L1235","documentation":"GetPreviousGTIDs scans binlog events (SHOW BINLOG EVENTS) looking for the Previous_gtids event that records the set of GTIDs executed before the current binlog file. If no such event exists in the scanned binlog, this error is returned. This usually means the binlog file is empty, freshly rotated, or the server has GTIDs disabled.","triggerScenarios":"Calling Mysqld.GetPreviousGTIDs when SHOW BINLOG EVENTS on the target binlog file contains no row with Event_type == 'Previous_gtids' (previousGtidsFound stays false), producing \"GetPreviousGTIDs: previous GTIDs not found\".","commonSituations":"Point-in-time recovery / GTID position calculation against a brand-new binlog file with no prior events; GTID mode disabled (gtid_mode=OFF) so Previous_gtids events never exist; purged or truncated binlogs on the server.","solutions":["Verify gtid_mode=ON on the server; Previous_gtids events only exist when GTIDs are enabled.","Query the first binlog file in the series (SHOW BINARY LOGS) rather than a file that may be empty/rotated.","Fall back to reading executed GTIDs from @@GLOBAL.gtid_executed if the binlog event is unavailable.","If the binlog was purged, restore from a backup that still has the needed binlogs."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"gtidMode, err := mysqld.FetchSuperQuery(ctx, \"SELECT @@GLOBAL.gtid_mode\")\n// proceed only if gtidMode == \"ON\" and the target binlog file has events\n","typeGuard":null,"tryCatchPattern":"gtids, err := mysqld.GetPreviousGTIDs(ctx, binlogFile)\nif err != nil {\n    if strings.Contains(err.Error(), \"previous GTIDs not found\") {\n        gtids, err = readFromGtidExecuted(ctx, mysqld) // fallback to @@GLOBAL.gtid_executed\n    }\n    if err != nil {\n        return vterrors.Wrapf(err, \"resolving previous GTIDs\")\n    }\n}","preventionTips":["Require gtid_mode=ON for workloads that depend on Previous_gtids events.","Target the correct (non-empty, unrotated) binlog file when scanning events.","Prevent binlog purging of files still needed for GTID position computation."],"tags":["mysql","gtid","binlog","replication"],"backgroundTag":"gtid-position-lookup-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}