File tree 1 file changed +7
-3
lines changed
packages/service-core/src/util
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -119,9 +119,13 @@ export async function createWriteCheckpoint(
119
119
bucketStorage : storage . BucketStorageFactory ,
120
120
user_id : string
121
121
) : Promise < bigint > {
122
- const [ { lsn } ] = pgwireRows (
123
- await retriedQuery ( db , `SELECT pg_logical_emit_message(false, 'powersync', 'ping') as lsn` )
124
- ) ;
122
+ // On most Postgres versions, pg_logical_emit_message() returns the correct LSN.
123
+ // However, on Aurora (Postgres compatible), it can return an entirely different LSN,
124
+ // causing the write checkpoints to never be replicated back to the client.
125
+ // For those, we need to use pg_current_wal_lsn() instead.
126
+ const [ { lsn } ] = pgwireRows ( await retriedQuery ( db , `SELECT pg_current_wal_lsn() as lsn` ) ) ;
127
+
128
+ await retriedQuery ( db , `SELECT pg_logical_emit_message(false, 'powersync', 'ping')` ) ;
125
129
126
130
const id = await bucketStorage . createWriteCheckpoint ( user_id , { '1' : lsn } ) ;
127
131
logger . info ( `Write checkpoint 2: ${ JSON . stringify ( { lsn, id : String ( id ) } ) } ` ) ;
You can’t perform that action at this time.
0 commit comments