Skip to main content

Enable query store

Since SQL Server 2016, there has been an option to enable a query store. The query store stores details about unique queries: their execution plans, the time they took, the logical reads they required, etc. This would help greatly in identifying performance issues.

ALTER DATABASE [MXSuite] SET QUERY_STORE = ON
(
    OPERATION_MODE = READ_WRITE,
    CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 30), -- keeps 30 days of info, up to limit of storage though
    DATA_FLUSH_INTERVAL_SECONDS = 900, -- how often the data for the query store gets moved from ram to disk, recommended is900 seconds. higher means more memory usage and less disk i/o, lower means the opposite, although it shouldn't have any significant performance impact. 
    MAX_STORAGE_SIZE_MB = 1024, -- occupies max 1gb, i'd suggest 2gb on bigger databases but I don't know how much 1gb can handle
    INTERVAL_LENGTH_MINUTES = 60,
    SIZE_BASED_CLEANUP_MODE = AUTO,
    QUERY_CAPTURE_MODE = AUTO, --filters out insignificant queries, which there are a lot of
    MAX_PLANS_PER_QUERY = 200
);