DBAtlas · Database operations atlas

Enable Query Store, apply recommended settings and check its state

SQL ServerQuery Store

Command

ALTER DATABASE [Musteri] SET QUERY_STORE = ON;
ALTER DATABASE [Musteri] SET QUERY_STORE (
    OPERATION_MODE = READ_WRITE,
    QUERY_CAPTURE_MODE = AUTO,
    MAX_STORAGE_SIZE_MB = 2048,
    INTERVAL_LENGTH_MINUTES = 15,
    DATA_FLUSH_INTERVAL_SECONDS = 900,
    CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 30),
    SIZE_BASED_CLEANUP_MODE = AUTO,
    MAX_PLANS_PER_QUERY = 200,
    WAIT_STATS_CAPTURE_MODE = ON);

-- State: if actual_state dropped to READ_ONLY, check readonly_reason
USE [Musteri];
SELECT actual_state_desc, desired_state_desc, readonly_reason,
       current_storage_size_mb, max_storage_size_mb,
       query_capture_mode_desc, size_based_cleanup_mode_desc, wait_stats_capture_mode_desc
FROM   sys.database_query_store_options;

What it does

Enables Query Store in the database; starts persisting query texts, plans, runtime and wait statistics in time intervals. The options define the storage limit, cleanup and capture mode.

When to use it

When a new database goes live, before a version/compatibility level upgrade (for a baseline), or when a plan regression is suspected.

Caution

When MAX_STORAGE_SIZE_MB is reached, Query Store silently switches to READ_ONLY (readonly_reason = 65536) and stops collecting; monitor current_storage_size_mb. QUERY_CAPTURE_MODE = ALL fills storage quickly and adds overhead under heavy ad-hoc workloads. Very busy OLTP systems may show QDS_* waits. Turning it OFF keeps the collected data; CLEAR deletes it.

Open in DBAtlas →

Related