16209831ca
Coordinated central-pair window for #107 item 4: range analysis, ordered idempotent migration script (SHA-256 488da93d...), read-only SQL preflight results from wonder-sql-vq03, procedure, gates, rollback, downtime estimate. QA is on0e540291/ 58 migrations (notb3021e7c/ 57). Hash-chain enablement after the window is gated on #139. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
57 lines
3.0 KiB
SQL
57 lines
3.0 KiB
SQL
-- Read-only preflight for the QA vq03/vq04 window (ScadaBridge#107 item 4). SELECTs only.
|
|
-- Run against the QA config DB:
|
|
-- SQLCMDPASSWORD=... sqlcmd -S wonder-sql-vq03.zmr.zimmer.com,1433 -U <login> -C -d ScadaBridge -W -s '|' -i preflight.sql
|
|
-- Re-run it right before the window and compare with README.md section 3.
|
|
SET NOCOUNT ON;
|
|
|
|
-- 1. Migration level: expect 58 rows, last = 20261022133907_ReviewRemediationIndexes.
|
|
SELECT COUNT(*) AS migrations FROM dbo.__EFMigrationsHistory;
|
|
SELECT TOP 3 MigrationId, ProductVersion FROM dbo.__EFMigrationsHistory ORDER BY MigrationId DESC;
|
|
|
|
-- 2. Recovery model and log reuse.
|
|
SELECT name, recovery_model_desc, log_reuse_wait_desc, compatibility_level
|
|
FROM sys.databases WHERE name = DB_NAME();
|
|
|
|
-- 3. AuditLog size (sizes the FlipAuditLogClusteredKey rebuild; the log needs about 2x reserved).
|
|
EXEC sp_spaceused 'dbo.AuditLog';
|
|
SELECT MIN(OccurredAtUtc) AS oldest, MAX(OccurredAtUtc) AS newest FROM dbo.AuditLog;
|
|
|
|
-- 4. Clustered key shape: expect key_ordinal 1 = EventId before the flip, OccurredAtUtc after.
|
|
SELECT ic.key_ordinal, c.name
|
|
FROM sys.index_columns ic
|
|
JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
|
|
WHERE ic.object_id = OBJECT_ID('dbo.AuditLog') AND ic.index_id = 1
|
|
ORDER BY ic.key_ordinal;
|
|
|
|
-- 5. Log space, files and volumes.
|
|
SELECT total_log_size_in_bytes / 1048576 AS log_mb,
|
|
used_log_space_in_bytes / 1048576 AS log_used_mb,
|
|
CAST(used_log_space_in_percent AS decimal(5,1)) AS log_used_pct
|
|
FROM sys.dm_db_log_space_usage;
|
|
SELECT name, type_desc, CAST(size AS bigint) * 8 / 1024 AS size_mb,
|
|
CAST(growth AS bigint) * 8 / 1024 AS growth_mb, is_percent_growth, physical_name
|
|
FROM sys.database_files;
|
|
SELECT DISTINCT vs.volume_mount_point, vs.available_bytes / 1048576 AS free_mb
|
|
FROM sys.database_files f CROSS APPLY sys.dm_os_volume_stats(DB_ID(), f.file_id) vs;
|
|
|
|
-- 6. SourceNode backfill state (run `audit backfill-source-node` before the hash chain is enabled).
|
|
SELECT Kind, COUNT(*) AS n, SUM(CASE WHEN SourceNode IS NULL THEN 1 ELSE 0 END) AS null_sourcenode,
|
|
MAX(CASE WHEN SourceNode IS NULL THEN OccurredAtUtc END) AS newest_null
|
|
FROM dbo.AuditLog GROUP BY Kind ORDER BY null_sourcenode DESC;
|
|
|
|
-- 7. Objects the window creates: expect none of these before, all after.
|
|
SELECT OBJECT_NAME(object_id) AS tbl, name AS col FROM sys.columns
|
|
WHERE name IN ('ChainSeq', 'RowHash', 'RowVersion', 'IsMesReportable') ORDER BY 1, 2;
|
|
SELECT name FROM sys.tables WHERE name IN ('AuditLogChainHead', 'AuditLogChainTombstone');
|
|
SELECT name FROM sys.database_principals WHERE name LIKE 'scadabridge[_]audit[_]%';
|
|
|
|
-- 8. Partition function headroom (the flip rebuilds onto ps_AuditLog_Month).
|
|
SELECT pf.name, COUNT(prv.boundary_id) AS boundaries, MAX(CAST(prv.value AS datetime2)) AS last_boundary
|
|
FROM sys.partition_functions pf
|
|
LEFT JOIN sys.partition_range_values prv ON prv.function_id = pf.function_id
|
|
GROUP BY pf.name;
|
|
|
|
-- 9. Recent backups.
|
|
SELECT TOP 5 type, backup_finish_date, is_copy_only
|
|
FROM msdb.dbo.backupset WHERE database_name = DB_NAME() ORDER BY backup_finish_date DESC;
|