{"record":{"id":"e708c26dce4347a3","repo":"vitessio/vitess","slug":"failed-to-get-primary-position-v","errorCode":null,"errorMessage":"failed to get primary position: %v","messagePattern":"failed to get primary position: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/binlog/binlog_connection.go","lineNumber":111,"sourceCode":"\t\treturn nil, err\n\t}\n\t// Tell the server that we understand the format of events\n\t// that will be used if binlog_checksum is enabled on the server.\n\tif _, err := conn.ExecuteFetch(\"SET @source_binlog_checksum = @@global.binlog_checksum, @master_binlog_checksum=@@global.binlog_checksum\", 0, false); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to set @source_binlog_checksum=@@global.binlog_checksum: %v\", err)\n\t}\n\n\treturn conn, nil\n}\n\n// StartBinlogDumpFromCurrent requests a replication binlog dump from\n// the current position.\nfunc (bc *BinlogConnection) StartBinlogDumpFromCurrent(ctx context.Context) (replication.Position, <-chan mysql.BinlogEvent, <-chan error, error) {\n\tctx, bc.cancel = context.WithCancel(ctx)\n\n\tposition, err := bc.PrimaryPosition()\n\tif err != nil {\n\t\treturn replication.Position{}, nil, nil, fmt.Errorf(\"failed to get primary position: %v\", err)\n\t}\n\n\tc, e, err := bc.StartBinlogDumpFromPosition(ctx, \"\", position)\n\treturn position, c, e, err\n}\n\n// StartBinlogDumpFromPosition requests a replication binlog dump from\n// the replication source mysqld (typically the primary server in the cluster)\n// at the given Position and then sends binlog\n// events to the provided channel.\n// The stream will continue in the background, waiting for new events if\n// necessary, until the connection is closed, either by the replication source or\n// by canceling the context.\n//\n// Note the context is valid and used until eventChan is closed.\nfunc (bc *BinlogConnection) StartBinlogDumpFromPosition(ctx context.Context, binlogFilename string, startPos replication.Position) (<-chan mysql.BinlogEvent, <-chan error, error) {\n\tctx, bc.cancel = context.WithCancel(ctx)\n","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/binlog/binlog_connection.go#L93-L129","documentation":"StartBinlogDumpFromCurrent first asks the connected primary for its current replication position via PrimaryPosition() (typically a SHOW MASTER/ BINARY LOG STATUS query). If that query fails, no dump can be started, so it returns this wrapped error with nil channels. It indicates the position could not be established before streaming began.","triggerScenarios":"Calling BinlogConnection.StartBinlogDumpFromCurrent when the underlying PrimaryPosition() query fails — connection lost, server error, or the primary refuses the status query for this user.","commonSituations":"Primary failover/crash between connect and position query; replication user lacking REPLICATION CLIENT privilege; version mismatch where the status statement name differs (e.g. SHOW MASTER STATUS removed in MySQL 8.4+).","solutions":["Inspect the wrapped %v error: reconnect (NewBinlogConnection) and retry StartBinlogDumpFromCurrent if it is a connection error.","Grant the replication user REPLICATION CLIENT (and REPLICATION SLAVE/REPLICATION REPLICA) privileges.","On MySQL 8.4+/newer flavors, verify the server supports the status statement PrimaryPosition uses; use the correct flavor.","Check server logs for errors at the time of the query to rule out primary-side crashes."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// preflight: confirm the replication user can read the primary position\nqr, err := conn.ExecuteFetch(\"SHOW BINARY LOG STATUS\", 1, false) // or SHOW MASTER STATUS on older versions\nif err != nil {\n\treturn fmt.Errorf(\"replication user cannot read primary position: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"pos, chans, err := bc.StartBinlogDumpFromCurrent(ctx)\nif err != nil && strings.Contains(err.Error(), \"failed to get primary position\") {\n\t// reconnect and retry after backoff; check grants if it persists\n}","preventionTips":["Grant REPLICATION CLIENT and REPLICATION SLAVE/REPLICA to the streaming user.","Verify the status statement supported by the server flavor/version before streaming.","Check primary liveness (vttablet health) before starting dumps.","Alert on primary failovers so stream restarts are expected and handled."],"tags":["mysql","replication","binlog","gtid"],"backgroundTag":"binlog-position-unavailable","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}