Expand description
Useful queries to inspect the state of a SQL Server instance.
StaticsΒ§
FunctionsΒ§
- check_
system_ πresult - Helper function to parse an expected result from a βsystemβ query.
- cleanup_
change_ table - Cleans up the change table associated with the specified
capture_instance
by deletingmax_deletes
entries with astart_lsn
less thanlow_water_mark
. - deserialize_
table_ πcolumns_ to_ raw_ tables - ensure_
database_ cdc_ enabled - Ensure change data capture (CDC) is enabled for the database the provided
client
is currently connected to. - ensure_
snapshot_ isolation_ enabled - Ensure the
SNAPSHOT
transaction isolation level is enabled for the database the providedclient
is currently connected to. - get_
changes_ asc - Queries the specified capture instance and returns all changes from
[start_lsn, end_lsn)
, ordered bystart_lsn
in an ascending fashion. - get_
latest_ restore_ history_ id - Retrieves the largest
restore_history_id
from SQL Server for the current database. Therestore_history_id
column is of typeIDENTITY(1,1)
based onEXEC sp_help restorehistory
. We expect it to start at 1 and be incremented by 1, with possible gaps in values. See: - get_
max_ lsn - Returns the maximum log sequence number for the entire database. This implementation relies on CDC, which is asynchronous, so may return an LSN that is less than the maximum LSN of SQL server.
- get_
max_ lsn_ retry - Returns the maximum log sequence number for the entire database, retrying if the log sequence number is not available. This implementation relies on CDC, which is asynchronous, so may return an LSN that is less than the maximum LSN of SQL server.
- get_
min_ lsn - Returns the minimum log sequence number for the specified
capture_instance
. - get_
min_ lsn_ retry - Returns the minimum log sequence number for the specified
capture_instance
, retrying if the log sequence number is not available. - get_
min_ lsns - Retrieves the minumum
Lsn
(start_lsn field) fromcdc.change_tables
for the specified capture instances. - get_
tables - get_
tables_ for_ capture_ instance - Returns the table metadata for the tables that are tracked by the specified
capture_instance
s. - increment_
lsn - Increments the log sequence number.
- map_
null_ πlsn_ to_ retry - parse_
lsn π - Parse an
Lsn
from the first column of the providedtiberius::Row
. - parse_
numeric_ πlsn - Parse an
Lsn
in Decimal(25,0) format of the providedtiberius::Row
. - snapshot
- Return a
Stream
that is the entire snapshot of the specified table. - snapshot_
size - Returns the total number of rows present in the specified table.
- validate_
source_ privileges - Return a Result that is empty if all tables, columns, and capture instances have the necessary permissions to and an error if any table, column, or capture instance does not have the necessary permissions for tracking changes.