Forum Discussion

Vaultnexus's avatar
Vaultnexus
Copper Contributor
Mar 28, 2024

Could I retrieve the value of the First LSN and the Last LSN?

Hello everyone,

 

I'm new to databases and I'm having some minor problems with the SQL server.

 

Let me explain: I'd like to automate a script written in Go that would facilitate the restoration of a database. My script would search for transaction logs in a folder, verify their presence, and then execute them to restore the database.

 

What I don't understand is how SQL Server validates their coherence to apply it in my code. How does SQL Server check that they are in the correct order and that they are all present?

 

When using the graphical interface for a restoration:

 

I've noticed that for the log files, the Last LSN corresponds to the First LSN of the next log file. Therefore, I wonder if it's possible to retrieve and compare them to validate coherence in my code.

 

So, I'm wondering if this is possible.

 

To give a more concrete example, I've created a similar script for the MySQL database, where to check the coherence of the files, I simply looked to see if the next binlog was greater than the current one by +1. For example:

  • binlog.000001, binlog.000002, binlog.000003: coherence is good.
  • binlog.000001, binlog.000003, binlog.000004: coherence is not validated, binlog.000002 is missing.

Thank you for your assistance. 🙂

Resources