sqldw-operations-cli

作者: microsoft

更新檢查 — 每次工作階段一次(強制) 此技能在工作階段中首次使用時,請先執行檢查更新技能再繼續。

npx skills add https://github.com/microsoft/skills-for-fabric --skill sqldw-operations-cli

Update Check — ONCE PER SESSION (mandatory) The first time this skill is used in a session, run the check-updates skill before proceeding.

  • GitHub Copilot CLI / VS Code: invoke the check-updates skill.
  • Claude Code / Cowork / Cursor / Windsurf / Codex: compare local vs remote package.json version.
  • Skip if the check was already performed earlier in this session.

CRITICAL NOTES

  1. To find the workspace details (including its ID) from workspace name: list all workspaces and, then, use JMESPath filtering
  2. To find the item details (including its ID) from workspace ID, item type, and item name: list all items of that type in that workspace and, then, use JMESPath filtering

SQL DW Performance & Diagnostics — CLI Skill

This skill provides performance analysis, deep diagnostics, and optimization guidance for Microsoft Fabric Data Warehouse via sqlcmd and the built-in queryinsights views. All queries are read-only.

Prerequisites

For tool installation and authentication setup, see COMMON-CLI.md § Authentication Recipes and COMMON-CLI.md § SQL / TDS Data-Plane Access.

Monitoring-specific requirements:

  • Workspace role: Admin or Member on the target workspace (required for queryinsights views)
  • Warehouse must exist with recent query activity (queryinsights views retain 30 days; data appears with up to 15 min delay)

Table of Contents

TaskReferenceNotes
Finding Workspaces and Items in FabricCOMMON-CLI.md § Finding Workspaces and Items in FabricMandatoryREAD link first [needed for finding workspace id by its name or item id by its name, item type, and workspace id]
Fabric Topology & Key ConceptsCOMMON-CORE.md § Fabric Topology & Key Concepts
Environment URLsCOMMON-CORE.md § Environment URLs
Authentication & Token AcquisitionCOMMON-CORE.md § Authentication & Token AcquisitionWrong audience = 401; read before any auth issue
Core Control-Plane REST APIsCOMMON-CORE.md § Core Control-Plane REST APIsIncludes pagination, LRO polling, and rate-limiting patterns
Capacity ManagementCOMMON-CORE.md § Capacity Management
Gotchas, Best Practices & Troubleshooting (Platform)COMMON-CORE.md § Gotchas, Best Practices & Troubleshooting
Tool Selection RationaleCOMMON-CLI.md § Tool Selection Rationale
Authentication RecipesCOMMON-CLI.md § Authentication Recipesaz login flows and token acquisition
Fabric Control-Plane API via az restCOMMON-CLI.md § Fabric Control-Plane API via az restAlways pass --resource; includes pagination and LRO helpers
SQL / TDS Data-Plane AccessCOMMON-CLI.md § SQL / TDS Data-Plane Accesssqlcmd (Go) connect, query, CSV export
Gotchas & Troubleshooting (CLI-Specific)COMMON-CLI.md § Gotchas & Troubleshooting (CLI-Specific)az rest audience, shell escaping, token expiry
Quick ReferenceCOMMON-CLI.md § Quick Referenceaz rest template + token audience/tool matrix
Connection FundamentalsSQLDW-CONSUMPTION-CORE.md § Connection FundamentalsTDS, port 1433, Entra-only, no MARS
Monitoring and DiagnosticsSQLDW-CONSUMPTION-CORE.md § Monitoring and DiagnosticsQuery labels; DMVs (live) + queryinsights.* (30-day history)
Performance: Best Practices and TroubleshootingSQLDW-CONSUMPTION-CORE.md § Performance: Best Practices and TroubleshootingStatistics, caching, clustering, query tips
Gotchas and Troubleshooting (Consumption)SQLDW-CONSUMPTION-CORE.md § Gotchas and Troubleshooting Reference18 numbered issues with cause + resolution
Data Ingestion (DW Only)SQLDW-AUTHORING-CORE.md § Data Ingestion (DW Only)COPY INTO, OPENROWSET, method comparison
Query Referencequery-reference.mdT-SQL queries, parameters, and example output for all analyses
Composite RecipesCOMMON-CLI.md § Composite Recipes
Item-Type Capability MatrixSQLDW-CONSUMPTION-CORE.md § Item-Type Capability MatrixWarehouses only — queryinsights not available on SQLEP
PrerequisitesSKILL.md § PrerequisitesTools, auth, workspace role
Tool StackSKILL.md § Tool Stack
ConnectionSKILL.md § Connection
Performance AnalysisSKILL.md § Performance AnalysisLong-running queries, resource consumers, user insights, baselines
Deep DiagnosticsSKILL.md § Deep DiagnosticsPressure windows, cache warmth, cluster keys
Fabric DW ConstraintsSKILL.md § Fabric DW ConstraintsNEVER recommend unsupported features
Best PracticesSKILL.md § Best PracticesMonitoring-specific guidance
Agentic WorkflowsSKILL.md § Agentic WorkflowsCommon investigation patterns
Gotchas, Rules, TroubleshootingSKILL.md § Gotchas, Rules, TroubleshootingMUST DO / AVOID / PREFER checklists
ExamplesSKILL.md § ExamplesPrompt/response pairs

Tool Stack

For installation and setup, see Prerequisites.

ToolRole
sqlcmd (Go)Execute monitoring T-SQL queries via Entra ID auth (-G)
az CLIToken acquisition, Fabric REST for endpoint discovery
jqParse JSON from az rest

Connection

For authentication recipes (interactive, service principal, CI/CD), see COMMON-CLI.md § Authentication Recipes.

Discover the SQL Endpoint FQDN

Per COMMON-CLI.md Discovering Connection Parameters via REST:

WS_ID="<workspaceId>"
ITEM_ID="<warehouseId>"

# Warehouse
az rest --method get \
  --resource "https://api.fabric.microsoft.com" \
  --url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/warehouses/$ITEM_ID" \
  --query "properties.connectionString" --output tsv

Result: <uniqueId>.datawarehouse.fabric.microsoft.com

Connect with sqlcmd (Go)

sqlcmd -S "<endpoint>.datawarehouse.fabric.microsoft.com" -d "<DatabaseName>" -G \
  -Q "SELECT TOP 5 * FROM queryinsights.exec_requests_history ORDER BY total_elapsed_time_ms DESC"

Reusable Connection Variables

FABRIC_SERVER="<endpoint>.datawarehouse.fabric.microsoft.com"
FABRIC_DB="<DatabaseName>"
SQLCMD="sqlcmd -S $FABRIC_SERVER -d $FABRIC_DB -G"
$SQLCMD -Q "SELECT TOP 5 * FROM queryinsights.long_running_queries ORDER BY last_run_total_elapsed_time_ms DESC"
# PowerShell
$s = "<endpoint>.datawarehouse.fabric.microsoft.com"; $db = "<DatabaseName>"
sqlcmd -S $s -d $db -G -Q "SELECT TOP 5 * FROM queryinsights.exec_requests_history ORDER BY total_elapsed_time_ms DESC"

Performance Analysis

All SQL queries, parameters, return fields, and response formatting are in query-reference.md.

Long-Running Queries Summary

Find the slowest queries from queryinsights.long_running_queries. See query-reference.md § Long-Running Queries Summary for SQL and formatting.

Top Resource Consumers

Find CPU- and storage-heavy queries from queryinsights.exec_requests_history. See query-reference.md § Top Resource Consumers for SQL, thresholds, and formatting.

Recommendation thresholds:

  • Remote scans > 1,000 MB → review data layout, consider clustering
  • CPU > 5,000,000 ms → review query logic
  • Elapsed > 300,000 ms → check joins, filters, statistics
  • Reference: Performance guidelines

Top Users Insights

Analyze user activity and query patterns. See query-reference.md § Top Users Insights for SQL and classification logic.

Compare Recent vs Baseline

Detect performance regressions by comparing recent window against historical baseline. See query-reference.md § Compare Recent vs Baseline for SQL and formatting.

Recent Queries

Retrieve the most recently executed queries. See query-reference.md § Recent Queries for SQL.

Search Query Patterns

Search historical query patterns by table name, column, or keyword. See query-reference.md § Search Query Patterns for SQL.


Deep Diagnostics

All SQL queries for diagnostics are in query-reference.md.

Analyze Long-Running Query Plans

See query-reference.md § Long-Running Query Analysis for SQL.

Analysis guidance — when reviewing slow queries, check:

  • High data_scanned_remote_storage_mb → data layout issues (run OPTIMIZE, consider clustering)
  • High allocated_cpu_time_ms relative to elapsed → CPU-bound (simplify joins, reduce columns)
  • High elapsed but low CPU → waiting on resources (check for pressure windows)

Analyze Pressure Window Queries

Identify SQL pool pressure events using queryinsights.sql_pool_insights and correlate with the heaviest queries running during those windows. See query-reference.md § Pressure Window Analysis for the two-step SQL.

Usage: Step 1 returns pressure windows with window_start and window_end timestamps. Substitute those actual timestamp values into Step 2's WHERE clause to find overlapping queries.

Global recommendations — based on aggregate pressure analysis:

  • If SELECT pool has more pressure → read-heavy workload, suggest caching and column pruning
  • If NONSELECT pool has more pressure → write-heavy, suggest batching and COPY INTO
  • If total pressure > 60 min → suggest scaling capacity or staggering workloads

Analyze Query Cache Warmth

See query-reference.md § Cache Warmth Analysis for SQL.

Classification logic — for each execution, compute total_mb = remote + memory + disk:

  • result_cache_hit = 1cached
  • remote_mb / total_mb > 0.8cold (>80% from remote storage)
  • (memory_mb + disk_mb) / total_mb > 0.8warm (>80% from cache)

Recommendations:

  • Over 50% cold runs → Enable result set caching: ALTER DATABASE SET RESULT_SET_CACHING ON;
  • Always-cold patterns → Check for GETDATE()/GETUTCDATE() or volatile functions that bust the cache key

Recommend Cluster Keys

See query-reference.md § Cluster Key Recommendations for SQL.

Key rules:

  • Only WHERE predicates benefit from clustering — equality JOIN ON conditions do not
  • Prefer mid-to-high cardinality columns (many distinct values)
  • Maximum 4 clustering columns
  • Use CTAS with WITH (CLUSTER BY (...))ALTER TABLE is not supported

To apply clustering — see query-reference.md § Cluster Key Recommendations for CTAS creation, sp_rename table swap, and verification SQL.

Note: Fabric does not support ALTER TABLE SET DATA_CLUSTERING_KEY or RENAME OBJECT. Always use CTAS with WITH (CLUSTER BY (...)) and sp_rename for table swaps.


Fabric DW Constraints

NEVER recommend features not supported in Fabric Data Warehouse. Always consult this list before making optimization suggestions.

Do NOT RecommendWhyRecommend Instead
Nonclustered indexesNot supportedV-Order, column pruning, predicate pushdown
Materialized viewsNot supportedStandard views or result set caching
Index hints (FORCESEEK/FORCESCAN)Not supportedSimplify query structure
Multi-column statisticsNot supportedSingle-column statistics on key columns
ALTER TABLE SET DATA_CLUSTERING_KEYNot supportedCTAS with WITH (CLUSTER BY (...))
RENAME OBJECTNot supportedEXEC sp_rename 'schema.old', 'new'
Change isolation levelSnapshot onlyFabric uses snapshot isolation exclusively
CREATE USERNot supportedManage users via Fabric workspace
TriggersNot supportedApplication logic or Fabric pipelines
Recursive CTEsNot supportedIterative approach
"Enable Query Insights" settingQuery Insights is always on — there is no settingIf access is denied, the user needs Admin or Member workspace role

Agentic Workflows

Workflow 1: "Why is my warehouse slow?"

  1. Check for pressure events → Run the pressure window analysis query (last 24h)
  2. Find the heaviest queries → Run top resource consumers query (last 1h)
  3. Analyze slow queries → Run long-running queries analysis
  4. Check cache behavior → Run cache warmth analysis (last 24h)
  5. Recommend clustering → Run cluster key recommendation queries

Workflow 2: "Has performance degraded?"

  1. Compare against baseline → Run recent vs baseline comparison (1h vs 7-day)
  2. Identify new slow queries → Run long-running queries summary (top 5)
  3. Check user patterns → Run top users insights (last 24h)

Workflow 3: "Optimize my warehouse"

  1. Review best practices → See SQLDW-CONSUMPTION-CORE.md § Performance: Best Practices and Troubleshooting
  2. Find optimization targets → Run top resource consumers (last 24h)
  3. Recommend clustering → Run cluster key recommendation queries
  4. Analyze cold-start queries → Run cache warmth analysis

Workflow 4: "What are people running?"

  1. Recent activity → Run recent queries (top 10)
  2. User patterns → Run top users insights (last 24h)
  3. Search for specific patterns → Run query pattern search with search term

Best Practices

For comprehensive Fabric DW best practices, see SQLDW-CONSUMPTION-CORE.md § Performance: Best Practices and Troubleshooting and the Fabric guidelines.

Monitoring-specific best practices:

  • Start broad, then drill down — begin with long-running queries summary and baseline comparison before deep diagnostics
  • Use pressure window analysis for root-cause analysis rather than guessing at bottlenecks
  • Label all agent queries with OPTION (LABEL = 'AGENTCLI_MONITOR_...') for tracing in Query Insights
  • Prefer mid-to-high cardinality columns for clustering keys — low cardinality columns offer limited file-skipping benefit
  • Use WHERE predicates to identify cluster key candidates — equality JOIN ON conditions do not benefit from clustering
  • Always verify clustering after CTAS by querying sys.index_columns.data_clustering_ordinal
  • Check cold vs warm cache before concluding a query is inherently slow — first execution may be a cold start
  • Adjust time windows (DATEADD parameters) to match user's investigation scope — don't default to arbitrary windows

Gotchas, Rules, Troubleshooting

For generic CLI gotchas (connection, auth, shell escaping): see COMMON-CLI.md § Gotchas & Troubleshooting. For T-SQL/platform gotchas: see SQLDW-CONSUMPTION-CORE.md § Gotchas and Troubleshooting Reference.

MUST DO

  • Always check Fabric DW Constraints before recommending optimizations
  • When recommending clustering, instruct users to use CTAS with WITH (CLUSTER BY (...)) — not ALTER TABLE
  • Report actual query output — do not fabricate or assume results
  • Label queries with OPTION (LABEL = 'AGENTCLI_MONITOR_...') for Query Insights tracing

PREFER

  • Start with high-level queries (long-running summary, baseline comparison) before drilling into diagnostics
  • Use the pressure window analysis for root-cause analysis rather than guessing at bottlenecks
  • Combine multiple queries in the Agentic Workflows for comprehensive investigations
  • Adjust time windows (DATEADD parameters) based on what the user asks for

AVOID

  • Recommending Fabric-unsupported features (nonclustered indexes, materialized views, index hints, triggers)
  • Suggesting that Query Insights needs to be "enabled" or "turned on" — queryinsights views are always available; permission errors indicate insufficient workspace role (Admin or Member required)
  • Running monitoring queries without confirming connection parameters (server, database)
  • Guessing at performance root causes without running the diagnostic queries
  • Using SELECT * in monitoring queries — always select specific columns

TROUBLESHOOTING (Monitoring-Specific)

For generic connection/auth troubleshooting, see COMMON-CLI.md § Gotchas & Troubleshooting.

SymptomCauseFix
Invalid object name 'queryinsights...'New warehouse < 2 min oldWait ~2 minutes
Permission errors on queryinsights.*Insufficient workspace roleRequires Admin or Member role
No data in queryinsights viewsNo recent query activity or < 15 min delayWait 15 min after query completion
No rows but data existsRLS filteringCheck USER_NAME(), verify RLS policies

Examples

Find Slow Queries

User: "What are the slowest queries in my warehouse?"

Agent: Runs the long-running queries summary via sqlcmd:

sqlcmd -S "myserver.datawarehouse.fabric.microsoft.com" -d "MyWarehouse" -G -Q "
SELECT TOP 5
    left(last_run_command, 80) AS query_preview,
    number_of_runs,
    last_run_total_elapsed_time_ms,
    median_total_elapsed_time_ms
FROM queryinsights.long_running_queries
ORDER BY median_total_elapsed_time_ms DESC
"

The top 5 slowest queries are:

  1. SELECT * FROM FactSales JOIN DimCustomer... — ran 12 times, last took 45,200 ms (median 38,500 ms)
  2. SELECT region, SUM(amount)... — ran 8 times, last took 32,100 ms (median 29,000 ms) ...

Diagnose Performance Degradation

User: "Is my warehouse slower than last week?"

Agent: Runs the baseline comparison query and presents:

Performance Comparison (last 1h vs 7-day baseline):

  • Elapsed time: 2,450 ms avg → 4,100 ms avg (+67.3%)
  • CPU consumption: 1,200 ms → 2,800 ms (+133.3%)
  • Data scanned: 450 MB → 480 MB (+6.7%)

Significant regression detected. Let me check for pressure events and analyze the heaviest queries...

Then follows up with pressure window and resource consumer queries.

Get Clustering Recommendations

User: "Which tables should I cluster and on what columns?"

Agent: Runs the cluster key recommendation queries and presents:

Recommended Clustering Keys:

TableRecommended ColumnsRow CountTotal Scanned MB
dbo.FactSalesSaleDate, Region50M12,500 MB
dbo.FactInventoryProductID, WarehouseID12M3,200 MB

To apply clustering, use CTAS:

CREATE TABLE dbo.FactSales_clustered
WITH (CLUSTER BY (SaleDate, Region))
AS SELECT * FROM dbo.FactSales;

來自 microsoft 的更多技能

oss-growth
microsoft
開源增長駭客角色
official
microsoft-foundry
microsoft
端到端部署、評估與管理 Foundry 代理:Docker 建置、ACR 推送、託管/提示代理建立、容器啟動、批次評估、持續評估、提示最佳化工作流程、agent.yaml、從追蹤資料集整理。用途:將代理部署至 Foundry、託管代理、建立代理、調用代理、評估代理、執行批次評估、持續評估、持續監控、持續評估狀態、最佳化提示、改善提示、提示最佳化器、最佳化代理指令、改善代理...
officialdevelopmentdevops
azure-ai
microsoft
用於 Azure AI:搜尋、語音、OpenAI、文件智慧。協助搜尋、向量/混合搜尋、語音轉文字、文字轉語音、轉錄、OCR。適用情境:AI 搜尋、查詢搜尋、向量搜尋、混合搜尋、語意搜尋、語音轉文字、文字轉語音、轉錄、OCR、將文字轉換為語音。
officialdevelopmentapi
azure-deploy
microsoft
對已準備好的應用程式執行 Azure 部署,這些應用程式需具備現有的 .azure/deployment-plan.md 與基礎架構檔案。當使用者要求建立新應用程式時,請勿使用此技能——應改用 azure-prepare。此技能會執行 azd up、azd deploy、terraform apply 及 az deployment 命令,並內建錯誤復原機制。需具備來自 azure-prepare 的 .azure/deployment-plan.md,以及來自 azure-validate 的驗證狀態。適用時機:「執行 azd up」、「執行 azd deploy」、「執行部署」……
officialdevopsaws
azure-storage
microsoft
Azure Storage Services 包括 Blob 儲存體、檔案共用、佇列儲存體、表格儲存體和 Data Lake。回答關於儲存存取層(熱、冷、凍結、封存)、各層使用時機及層級比較的問題。提供物件儲存、SMB 檔案共用、非同步訊息、NoSQL 鍵值及大數據分析。包含生命週期管理。用於:blob 儲存體、檔案共用、佇列儲存體、表格儲存體、data lake、上傳檔案、下載 blob、儲存帳戶、存取層...
officialdevelopmentdatabase
azure-diagnostics
microsoft
在 Azure 上使用 AppLens、Azure Monitor、資源健康狀態和安全分類來偵錯 Azure 生產問題。適用時機:偵錯生產問題、疑難排解應用程式服務、應用程式服務高 CPU、應用程式服務部署失敗、疑難排解容器應用程式、疑難排解函數、疑難排解 AKS、kubectl 無法連線、kube-system/CoreDNS 失敗、Pod 擱置、CrashLoop、節點未就緒、升級失敗、分析記錄、KQL、深入解析、映像提取失敗、冷啟動問題、健康狀態探查失敗...
officialdevopsdevelopment
azure-prepare
microsoft
準備 Azure 應用程式以進行部署(基礎架構 Bicep/Terraform、azure.yaml、Dockerfile)。用於建立/現代化或建立+部署;不適用於跨雲端遷移(請使用 azure-cloud-migrate)。請勿用於:copilot-sdk 應用程式(請使用 azure-hosted-copilot-sdk)。適用時機:「建立應用程式」、「建置 Web 應用程式」、「建立 API」、「建立無伺服器 HTTP API」、「建立前端」、「建立後端」、「建置服務」、「現代化應用程式」、「更新應用程式」、「新增驗證」、「新增快取」、「託管於 Azure」、「建立並...」
officialdevelopmentdevops
azure-validate
microsoft
部署前驗證 Azure 就緒狀態。對設定、基礎架構(Bicep 或 Terraform)、RBAC 角色指派、受控身分權限及先決條件進行深度檢查,再進行部署。適用時機:驗證我的應用程式、檢查部署就緒狀態、執行預檢檢查、驗證設定、確認是否可部署、驗證 azure.yaml、驗證 Bicep、部署前測試、疑難排解部署錯誤、驗證 Azure Functions、驗證函式應用程式、驗證無伺服器...
officialdevopstesting