Module inspect

Source
Expand description

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

StructsΒ§

DDLEvent
A DDL event collected from the cdc.ddl_history table.

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_cdc_table_columns
Retrieves column metdata from the CDC table maintained by the provided capture instance. The resulting column information collection is similar to the information collected for the upstream table, with the exclusion of nullability and primary key constraints, which contain static values for CDC columns. CDC table schema is automatically generated and does not attempt to enforce the same constraints on the data as the upstream table.
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_ddl_history
Returns DDL changes made to the source table for the given capture instance. This follows the same convention as cdc.fn_cdc_get_all_changes_<capture_instance>, in that the range is inclusive, i.e. [from_lsn, to_lsn]. The events are returned in ascending order of LSN.
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.
get_value πŸ”’
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.