SQL Server Azure SQL Solutions


  1. 說明
  2. IaaS
  3. PaaS
  4. Cloud Solutions
    1. High Availability
    2. Automation
    3. Performance Optimizer
    4. Security
  5. Steps
  6. 相關連結

整理 Azure SQL Server 相關的解決方案,包含 IaaS 的 Virtual Machine 以及 PaaS 的 Azure SQL Database 以及 Azure SQL Managed Instance。並從實務應用著眼採用雲端的資料庫解決方案需要考量的項目。

SQL Server Logo

說明

Azure SQL 所提供的資料庫不限於 SQL Server,另外也包括 MySQL 以及 PostgreSQL,但本次的討論主要以地端的 SQL Server 以及雲端的 Azure SQL 進行比較。

  • IaaS
    • Virtual Machines
      • vCores
    • IaaS Agent extension
  • PaaS
    • Azure SQL Database
      • Single Database vs Elastic Pool
      • DTU
        • Basic
        • Standard
        • Premium
      • vCores
        • General Purpose
        • Critical Business
        • HyperScale
      • Serverless
    • Azure SQL Managed Instance
      • vCores
        • General Purpose
        • Critical Business
        • HyperScale

IaaS

IaaS Virtual Machine 提供了 Lift and Shift 的遷移方式,讓地端虛擬機的使用者能夠快速地將資料庫作業遷移。但原本伺服器管理的工作,仍可以藉由安裝 IaaS Agent extension 來簡化管理工作,並從 Azure Portal 就能夠進行多數的管理。

PaaS

無論是 Azure SQL Database 以及 Azure SQL Managed Instance,所支援的資料庫還原 (Restore),都是還原成新的資料庫名稱,需要手動移除原本的資料庫並重新命名 😶

PaaS 的資料庫服務都沒有「停機」的選項,不像 IaaS 的 Virtual Machine 可以將虛擬機進行停止,暫停收費 (儲存空間仍要計費),如果是為達到節省費用效果,只能改將 Service Tier 改為 Serverless,並藉由應用程式斷開連結使用 (或資料庫防火牆設定),來達到無使用無產生費用的效果。

Azure SQL Database 可以是單一資料庫服務 (Single Database) 或者彈性集區 (Elastic Pool),但無論兩者任一種,仍需要一個虛擬機器單位作為其管理容器。

而在效能等級 (Service Tier) 的設定上,如果是單一資料庫是設定在 Azure SQL Database 本身;如果是彈性集區則是設定在彈性集區上。

建立彈性集區的方式

💡 Azure SQL Database 因為沒有 Instance,有替代 Instance 管理需求的專門角色 dbmanager 以及 loginmanager。

dbmanager 可以用於建立與刪除資料庫;loginmanager 可以用於建立與刪除 virtual master 的 logins

💡 Azure AD Server Principal default 權限包含 database backup & restore operations 以及 Set up service broker & DB mail。

💡 評估 Managed Instance 支援使用 Alert 的 metrics: IO Bytes read, Average % CPU utilizatoin over time & Storage space used by instances and databases。

💡 評估使用 DTU 的資源量,可以藉由:

  • total storage space for all databases
  • total number of databases × average DTU utilization per database
  • number of concurrently peaking database × peak DTU utilization per database

Cloud Solutions

說明 Cloud 所能帶來的優勢以及具體技術的特色比較。

💡 Azure SQL Database Replication 僅支援 Standard Transactional 以及 Snapshot。

High Availability

項目 Auto-Failover Groups Active-Geo Replicas
Paas Azure SQL Database & Managed Instance Azure SQL Database
Failover 自動容錯移轉 手動容錯移轉
設定方式 在資料庫容器機器設定 在資料庫設定
運作原理 可用性群組 在不同地點的虛擬機器

💡 Invoke-AzSqlInstanceFailover with "Resource Group Name" & "Managed Instance for fail over"

Automation

除了 IaaS 仍可以使用 Windows scheduler (工程排程器) 來進行自動化維護工作外,PaaS 類型的 SQL Server Service 可以藉由 Azure Automation Accounts 來作業。

使用的邏輯為先建立 Automation Accounts,接著再建立 Runbook (可以使用 PowerSheel 或 Python),發行 Runbook 後再設定排程作業。

根據 Runbook 的腳本,可能是 PowerShell 或者是 Python,可以安裝相關的模組依賴。

為連動受管理的資源,可能會需要帳戶身分,可以儲存在 Automation Accounts 的 Credential 當中。

💡 SQL Server Agetn Jobs 使用 SSMS 來進行管理,無法透過 Azure Portal, ARM Template。

💡 Set-AzVMSqlServerExtension for PowerShell cmdlet

Performance Optimizer

sys.dm_os_waiting_tasks
sys.dm_exec_requests

sys.query_store_query_text
sys.query_store_query

sys.dm_db_session_space_usage
sys.dm_db_task_space_usage

sys.dm_db_index_physical_stats

sys.dm_db_column_store_row_group_physical_stats

sys.dm_db_tuning_recommendations
sys.database_automatic_tuning_options

💡 Automatic tuning CREATE_INDEX & DROP_INDEX 只有在 Azure SQL Database 支援,不支援 Azure SQL Managed Instance。

💡 可以藉由使用ㄒsys.database_files 來觀察資料庫 data & log files 的可用容量。

Security

Data in rest

Transparent Database Encryption

🔑 Service Master key (exists in SQL Server setup)
encrypt 🔑 Database Master key
encrypt 📑 Certificate
encrypt 🔑 Database Encryption key


Azure SQL Database & Azure SQL Managed Instance Default Enable. 在 Azure VM 磁碟額外受到 Azure Disk Encryption 保護,可以與 TDE 形成多層次保護。

Data in transit

Azure 的連線存取會優先以 Database Level 的防火牆規則判斷,其次才以 Server Level 的防火牆規則。

藉由設定 TLS,並由伺服器 Instance 啟用 ForceEncryption,使用端必須使用 Encrypt connection 如果伺服器端的憑證是自簽憑證,使用者必須搭配 Trust server certificate。

Data in use

在記憶體當中的資料庫資料,可以透過 Always Encrypted 技術進行加密保護,讓儲存在資料庫中的資料無法被 DBA 直接檢視

Microsoft Defender for SQL

  • Vulnerability to SQL injection
    偵測脆弱的 TSQL,例如不會檢測輸入資料的 Stored Procedures。
  • Potential SQL injection
    偵測惡意進行中的 Injection 攻擊行為。
  • Access from unusual location & Access from unusual Azure data center
    警示來自異常的地區登入行為。
  • Access from unfamiliar principal
    警示異常使用的 principal、user & login。
  • Access from a potentially harmful application
    警示使用的工具為惡意行為使用的工具。

💡 Change Data Capture

  1. sys.sp_cdc_enable_db
  2. sys.sp_cdc_enable_table

💡 Azure Key Vault to store encryption keys with SQL Server PowerShell cmdlets

Steps

💡 Striped Virtual Disk

  1. Attach disks to vm
  2. Create storage pool
  3. Striped virtual disk
  4. Create a volume

💡 Database Mail

  1. Enable database mail
  2. Create mail account
  3. Create profile
  4. Set profile as default

💡 Failver Configuration

  1. Disable application
  2. Configuration to secondary
  3. Initial failover from secondary
  4. Configure database after recovery
  5. Verify application integrity

💡 Alaways Encrypted

  1. Create a column master key
  2. Create a column encryption key
  3. Encrypt column using randomized encryption

💡 Azure AD Authentication

  1. Create an Azure AD Administrator for instance
  2. Create a contained database user to mapped to Azure AD identity
  3. Connect to database using Azure AD identity

💡 ARM Template

  1. Export Resources template from Azure Portal
  2. Revise configuration parameters in the template
  3. Deploy the template from Azure Portal

💡 Restore Database

  1. Restore the most recent full backup
  2. Restore the diff backup from specific Date
  3. Restore the log backups after diff backup

💡 Move Secondary Server to another region

  1. Active-Geo replication to create secondaries of Server A to C
  2. Delete Failover Group
  3. Create new Failover Group, same name between A and C
  4. Add all primary databases on Server A to the new Failover Group
  5. Drop Server B

💡 Resource Governor

  1. Create Resource Pool
  2. Create Workload Group
  3. Create User Defined classification function
  4. Modify Resource Governor

相關連結

SQL Server Integrated Service 初探

SQL Server 閃電般快速查詢指南⚡

SQL Server 周邊工具彙整筆記

SQL Server 學習資源筆記