Module inspect

Source
Expand description

Useful queries to inspect the state of a SQL Server instance.

StaticsΒ§

GET_COLUMNS_FOR_TABLES_WITH_CDC_QUERY πŸ”’

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 deleting max_deletes entries with a start_lsn less than low_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 provided client is currently connected to.
get_changes_asc
Queries the specified capture instance and returns all changes from [start_lsn, end_lsn), ordered by start_lsn in an ascending fashion.
get_latest_restore_history_id
Retrieves the largest restore_history_id from SQL Server for the current database. The restore_history_id column is of type IDENTITY(1,1) based on EXEC 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) from cdc.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_instances.
increment_lsn
Increments the log sequence number.
map_null_lsn_to_retry πŸ”’
parse_lsn πŸ”’
Parse an Lsn from the first column of the provided tiberius::Row.
parse_numeric_lsn πŸ”’
Parse an Lsn in Decimal(25,0) format of the provided tiberius::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.