Skip to content

Commit

Permalink
source-postgres: Don't use IDENTIFY_SYSTEM
Browse files Browse the repository at this point in the history
Apparently Google's AlloyDB added a gratuitous fifth field to the
IDENTIFY_SYSTEM command results, which currently breaks the helper
function pglogrepl.IdentifySystem which expects there to be exactly
the four fields one gets back from PostgreSQL.

The only thing we use IdentifySystem for is to establish the WAL
flush location on the server, and we already have our own function
(`queryLatestServerLSN`) which does precisely that and doesn't rely
on parsing the IDENTIFY_SYSTEM result, so let's just use that one
instead.
  • Loading branch information
willdonnelly committed Feb 19, 2025
1 parent 53c613c commit ac0dd64
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions source-postgres/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,12 @@ func (db *postgresDatabase) ReplicationStream(ctx context.Context, startCursor s
logrus.WithField("err", err).Debug("error recreating replication slot")
}

// Obtain the current WAL flush location via an IDENTIFY_SYSTEM command.
// Note: We use IDENTIFY_SYSTEM here for legacy reasons, it might be cleaner
// to get this information from the newly-recreated slot's confirmed_flush_lsn
// now that we do it that way.
var sysident, err = pglogrepl.IdentifySystem(ctx, conn)
// Obtain the current WAL flush location on the server and initialize the cursor to that point.
var flushLSN, err = queryLatestServerLSN(ctx, db.conn)
if err != nil {
return nil, fmt.Errorf("unable to read WAL flush LSN from database: %w", err)
return nil, fmt.Errorf("unable to initialize cursor to current server LSN: %w", err)
}
startLSN = sysident.XLogPos
startLSN = flushLSN
}

// Check that the slot's `confirmed_flush_lsn` is less than or equal to our resume cursor value.
Expand Down

0 comments on commit ac0dd64

Please sign in to comment.