How to fix Error 6389 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 6389 – Selective XML Index Maxlength Exceeded

Why This Error Happens

This error occurs when a value being inserted into an XML column exceeds the maximum length constraint defined for a specific path in a Selective XML Index (SXI). SQL Server 2025 enforces strict maxlength boundaries on promoted nodes within the index schema, and any XML data exceeding this byte or character limit at the specified path will be rejected during the insert or update operation. This typically happens after a source system change increases the size of XML payloads without a corresponding update to the index’s path specification, or when the index was created with an undersized maxlength for a promoted property.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Path and Index

  • Capture the full error message, noting the %.*ls values for both the path and the selective XML index name.
  • Query sys.selective_xml_index_paths joined with sys.xml_indexes to locate the current max_length setting for the reported path.
  • Run: SELECT sxip.path, sxip.max_length, xi.name AS index_name FROM sys.selective_xml_index_paths sxip JOIN sys.xml_indexes xi ON sxip.xml_index_id = xi.index_id;

Step 2: Inspect the Source Data Causing the Overflow

  • Isolate the specific XML document or batch being inserted that triggered the error.
  • Use DATALENGTH() or LEN() against the XQuery .value() extraction of the same path to confirm the actual size of the incoming data.
  • Compare this value against the max_length returned in Step 1 to confirm the overflow margin.

Step 3: Drop and Recreate the Selective XML Index with Updated Maxlength

  • Since ALTER INDEX does not support modifying path-level max_length for SXI directly, you must drop and recreate the index.
  • Run: DROP INDEX [YourSXIName] ON [YourSchema].[YourTable];
  • Recreate using: CREATE SELECTIVE XML INDEX [YourSXIName] ON [YourSchema].[YourTable]([XmlColumn]) FOR ([YourPathName] = 'YourXPath' AS SQL VARCHAR(MAX));
  • Alternatively, increase the specific value from a fixed length (e.g., VARCHAR(100)) to a larger explicit size or VARCHAR(MAX) if path cardinality supports it.

Step 4: Rebuild Dependent Secondary XML Indexes

  • If secondary indexes (VALUE, PATH, or PROPERTY) reference the same XML column, rebuild them after the SXI recreation to ensure schema consistency.
  • Run: ALTER INDEX ALL ON [YourSchema].[YourTable] REBUILD;
  • Check sys.dm_db_index_physical_stats to confirm the rebuild completed without fragmentation warnings.

Alternative or Verification Steps

  • Re-run the original INSERT/UPDATE statement that failed; if it completes without Error 6389, the maxlength adjustment was successful.
  • If recreating the index is not immediately feasible, implement a staging table with VARCHAR(MAX) validation logic to truncate or flag oversized XML nodes before they reach the indexed production table.