SQL Flow Field Guide

sys.sp_mergemetadataretentioncleanup

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

Performs a manual cleanup of metadata in the MSmerge system tables.

What changes

Input
Not stated in the Microsoft summary.
Output or change
Not stated in the Microsoft summary.

Syntax at a glance

sys.sp_mergemetadataretentioncleanup
    [ [ @num_genhistory_rows = ] num_genhistory_rows OUTPUT ]
    [ , [ @num_contents_rows = ] num_contents_rows OUTPUT ]
    [ , [ @num_tombstone_rows = ] num_tombstone_rows OUTPUT ]
    [ , [ @aggressive_cleanup_only = ] aggressive_cleanup_only ]
[ ; ]

Work example

Performs a manual cleanup of metadata in the MSmerge system tables.

Write a proposed call on paper. Name the target, required permission, expected change, and recovery step before any lab use.

Check your work What can this procedure change or start, and what permission does it need?

Open Microsoft Learn for full syntax, permissions, and details for your version.