Skip to content

Instantly share code, notes, and snippets.

@beatak
Last active September 27, 2023 00:07
Show Gist options
  • Save beatak/f678538da4cbb5e089315c82be6e3ecc to your computer and use it in GitHub Desktop.
Save beatak/f678538da4cbb5e089315c82be6e3ecc to your computer and use it in GitHub Desktop.
Convert PostgreSQL's WAL_LSN to bytes (int, possibly 64-bit width?)
/**
* Logic is from:
* https://stackoverflow.com/questions/66797767/lsn-external-representation
* You may also look at:
* https://www.crunchydata.com/blog/postgres-wal-files-and-sequuence-numbers
*/
function lsn2int (str) {
return parseInt(
str.split('/').map((n) => n.padStart(8, '0')).join(''),
16
);
};
console.log(lsn2int('16/374D848'));
// => 94547269704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment