在此教學步驟中,您將查詢 HorizonDB 資料庫、檢視 PostgreSQL 中繼資料,並檢閱基本監控、安全性和整合狀態。
Important
Fabric HorizonDB 目前處於公開預覽階段。 功能、限制與行為可能會在正式推出前發生變化。 如需更多資訊,請參閱 Microsoft Fabric 預覽功能。
Prerequisites
- 完成 建立資料表並載入資料。
- 開啟
contoso-orders-db。 - 以資料庫建立者身份登入。 其他使用者與主體無法在目前預覽版中連線至 PostgreSQL。
查詢已開啟與處理中的訂單
針對 PostgreSQL 端點開啟一個新的查詢,然後執行:
SELECT
order_row.order_reference,
customer.customer_name,
customer.segment,
order_row.order_date,
order_row.status,
order_row.total
FROM horizon_sample.orders AS order_row
JOIN horizon_sample.customers AS customer
ON customer.customer_id = order_row.customer_id
WHERE order_row.status IN ('open', 'processing')
ORDER BY order_row.order_date DESC, order_row.order_reference;
結果包含 ORD-1001 和 ORD-1002。
依客戶區隔彙總訂單
跑步:
SELECT
customer.segment,
count(order_row.order_id) AS order_count,
coalesce(sum(order_row.total), 0) AS order_total
FROM horizon_sample.customers AS customer
LEFT JOIN horizon_sample.orders AS order_row
ON order_row.customer_id = customer.customer_id
GROUP BY customer.segment
ORDER BY customer.segment;
預期結果:
| 區段 | 訂單數量 | 訂單總計 |
|---|---|---|
| 商用 | 1 | 425.50 |
| Enterprise | 2 | 2230.25 |
在事務中測試更新
使用明確交易,以確保教學資料保持不變:
BEGIN;
UPDATE horizon_sample.orders
SET status = 'processing'
WHERE order_reference = 'ORD-1001'
AND status = 'open';
SELECT
order_reference,
status
FROM horizon_sample.orders
WHERE order_reference = 'ORD-1001';
ROLLBACK;
交易內部的查詢會報告 processing。 在 ROLLBACK 之後,ORD-1001 仍為 open。
不要讓編輯器裡的交易一直開啟。 閒置交易可以保留鎖。 如果在提交進行中連線中斷連線,請重新連線並驗證業務紀錄,再重播寫入。
檢查物件與擴充功能
重新整理物件總管,展開 horizon_sample,並確認兩個教學表格都已存在。
請以 SQL 列出相同物件:
SELECT
table_schema,
table_name,
table_type
FROM information_schema.tables
WHERE table_schema = 'horizon_sample'
ORDER BY table_name;
檢視已安裝的擴充功能:
SELECT
extension.extname AS extension_name,
extension.extversion AS installed_version,
namespace.nspname AS schema_name
FROM pg_catalog.pg_extension AS extension
JOIN pg_catalog.pg_namespace AS namespace
ON namespace.oid = extension.extnamespace
ORDER BY extension.extname;
該服務會管理其自動建立的擴充功能。 不要建立、刪除、取代或變更它們。
如果您計畫查詢符合資格的 Fabric 來源,請確認聯邦擴充功能:
SELECT
extname,
extversion
FROM pg_catalog.pg_extension
WHERE extname = 'pg_fabric_fdw';
您稍後會在查詢 Fabric HorizonDB 鏡像 Fabric 資料時使用此受管理整合。
檢視基本監控
執行此 PostgreSQL 原生資料庫統計查詢:
SELECT
datname AS database_name,
numbackends AS active_connections,
xact_commit,
xact_rollback,
blks_read,
blks_hit,
temp_files,
temp_bytes,
deadlocks,
stats_reset
FROM pg_catalog.pg_stat_database
WHERE datname = current_database();
查詢會回傳目前資料庫的一列資料。 當資料庫暫停時,計數器可能會重置、延遲或無法使用。 缺少遙測數據並不等於完全沒有活動。
檢視您目前的會話:
SELECT
pid,
usename,
application_name,
state,
xact_start,
query_start,
wait_event_type,
wait_event
FROM pg_catalog.pg_stat_activity
WHERE pid = pg_backend_pid();
其他工作階段的可見性及完整查詢文字取決於 PostgreSQL 權限。 查詢文字可能包含敏感值,請勿將未經審核的輸出貼入截圖或支援請求中。
如需更廣泛的監控指引,請參閱《監控 Fabric HorizonDB》。
檢視驗證與授權
跑步:
SELECT
current_user AS signed_in_user,
session_user,
has_schema_privilege(current_user, 'horizon_sample', 'USAGE')
AS can_use_sample_schema,
has_table_privilege(
current_user,
'horizon_sample.customers',
'SELECT'
) AS can_read_customers,
has_table_privilege(
current_user,
'horizon_sample.orders',
'SELECT'
) AS can_read_orders;
確認該身分代表您的 Microsoft Entra 主體,且所需檢查會回傳 true。
共用資料庫項目不會讓其他使用者或主體連線至 PostgreSQL。 它也不會授予超級使用者或主機層級存取權限。 檢視 驗證、授權與 驗證 PostgreSQL 存取。
作為可選的桌面練習,請在 Fabric 工具列中選擇 Visual Studio Code,開啟連線,選擇 Entra Authentication,並以建立者身份登入。 建立物件後,重新整理 PostgreSQL 連線 樹狀結構。 請參閱使用 Visual Studio Code 連線。
檢視整合狀態
開啟資料庫的整合或鏡像體驗。 在進行下一個步驟之前,請確認它沒有顯示相依性失敗。 在 PostgreSQL 準備就緒後,初始複製仍會繼續進行。
PostgreSQL 健康狀態、鏡像健康狀態、SQL 分析端點健康、聯邦健康狀態與複製工作健康是獨立的。
故障排除查詢
| 徵兆 | Resolution |
|---|---|
| 驗證成功,但查詢被拒絕 | 確認建立者的身份、物件所有權,以及支援的作業。 |
| 找不到關聯 | 驗證資料庫、結構描述限定、拼字及引號識別碼大小寫。 |
| Explorer 不會顯示資料表 | 重新整理並透過 information_schema驗證該物件。 |
| 查詢會等待 | 檢視生命週期狀態、您的交易狀態,以及在您有權限的情況下的封鎖工作階段。 |
| 連線會重置 | 重新開啟查詢並安全地協調先前的任何寫入作業,然後再嘗試。 |