Share via


刪除已啟用 Azure Arc 的 PostgreSQL 伺服器

本文件說明從 Azure Arc 設定中刪除伺服器的步驟。

注意

作為預覽功能,本文所述的技術受限於 Microsoft Azure 預覽版增補使用規定

版本資訊中提供的最新更新。

刪除伺服器

例如,假設我們想要從下列設定中刪除 postgres01 執行個體:

az postgres server-arc list --k8s-namespace <namespace> --use-k8s
Name        State  
----------  -------
postgres01  Ready  

刪除命令的一般格式為:

az postgres server-arc delete -n <server name> --k8s-namespace <namespace> --use-k8s

執行此命令時,系統會要求您確認對伺服器的刪除。 如果您使用指令碼自動執行刪除,則必須使用 --force 參數略過確認要求。 例如,您執行如下的命令:

az postgres server-arc delete -n <server name> --force --k8s-namespace <namespace> --use-k8s

如需關於刪除命令的詳細資訊,請執行:

az postgres server-arc delete --help 

刪除此範例中使用的伺服器

az postgres server-arc delete -n postgres01 --k8s-namespace <namespace> --use-k8s

回收 Kubernetes 永續性磁碟區宣告 (PVC)

PersistentVolumeClaim (PVC) 是 Kubernetes 叢集的使用者在建立儲存體並將其新增至 PostgreSQL 伺服器時提出的儲存體要求。 刪除伺服器群組並不會移除其相關聯的 PVC。 這是原廠設定。 其目的是要在意外刪除執行個體時,協助使用者存取資料庫檔案。 刪除 PVC 並不是必要的。 但是建議您這麼做。 如果您未回收這些 PVC,最終將會發生錯誤,因為 Kubernetes 叢集會認為其磁碟空間不足,或者,在建立新的 PVC 時使用相同的 PostgreSQL 伺服器名稱,可能會導致不一致的狀況。 若要回收 PVC,請採取下列步驟:

1.列出您已刪除之伺服器群組的 PVC

若要列出 PVC,請執行此命令:

kubectl get pvc [-n <namespace name>]

這會傳回 PVC 的清單,特別是您已刪除之伺服器群組的 PVC。 例如:

kubectl get pvc
NAME                                         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
data-few7hh0k4npx9phsiobdc3hq-postgres01-0   Bound    pvc-72ccc225-dad0-4dee-8eae-ed352be847aa   5Gi        RWO            default        2d18h
data-few7hh0k4npx9phsiobdc3hq-postgres01-1   Bound    pvc-ce6f0c51-faed-45ae-9472-8cdf390deb0d   5Gi        RWO            default        2d18h
data-few7hh0k4npx9phsiobdc3hq-postgres01-2   Bound    pvc-5a863ab9-522a-45f3-889b-8084c48c32f8   5Gi        RWO            default        2d18h
data-few7hh0k4npx9phsiobdc3hq-postgres01-3   Bound    pvc-00e1ace3-1452-434f-8445-767ec39c23f2   5Gi        RWO            default        2d15h
logs-few7hh0k4npx9phsiobdc3hq-postgres01-0   Bound    pvc-8b810f4c-d72a-474a-a5d7-64ec26fa32de   5Gi        RWO            default        2d18h
logs-few7hh0k4npx9phsiobdc3hq-postgres01-1   Bound    pvc-51d1e91b-08a9-4b6b-858d-38e8e06e60f9   5Gi        RWO            default        2d18h
logs-few7hh0k4npx9phsiobdc3hq-postgres01-2   Bound    pvc-8e5ad55e-300d-4353-92d8-2e383b3fe96e   5Gi        RWO            default        2d18h
logs-few7hh0k4npx9phsiobdc3hq-postgres01-3   Bound    pvc-f9e4cb98-c943-45b0-aa07-dd5cff7ea585   5Gi        RWO            default        2d15h

此伺服器群組有 8 個 PVC。

2.刪除每個 PVC

對已刪除的 PostgreSQL 伺服器刪除資料和記錄 PVC。

此命令的一般格式為:

kubectl delete pvc <name of pvc>  [-n <namespace name>]

例如:

kubectl delete pvc data-few7hh0k4npx9phsiobdc3hq-postgres01-0
kubectl delete pvc data-few7hh0k4npx9phsiobdc3hq-postgres01-1
kubectl delete pvc data-few7hh0k4npx9phsiobdc3hq-postgres01-2
kubectl delete pvc data-few7hh0k4npx9phsiobdc3hq-postgres01-3
kubectl delete pvc logs-few7hh0k4npx9phsiobdc3hq-postgres01-0
kubectl delete pvc logs-few7hh0k4npx9phsiobdc3hq-postgres01-1
kubectl delete pvc logs-few7hh0k4npx9phsiobdc3hq-postgres01-2
kubectl delete pvc logs-few7hh0k4npx9phsiobdc3hq-postgres01-3

每個 kubectl 命令都會確認已成功刪除 PVC。 例如:

persistentvolumeclaim "data-postgres01-0" deleted

注意

如前所述,若未刪除 PVC,最終可能導致您的 Kubernetes 叢集擲回錯誤。 其中一些錯誤可能包括,無法從 Kubernetes API 建立、讀取、更新、刪除資源,或無法執行 az arcdata dc export 之類的命令,因為控制器 Pod 可能會因為此儲存體問題 (正常 Kubernetes 行為) 而從 Kubernetes 節點被收回。

例如,您可能會在記錄中看到如下的訊息:

Annotations:    microsoft.com/ignore-pod-health: true  
Status:         Failed  
Reason:         Evicted  
Message:        The node was low on resource: ephemeral-storage. Container controller was using 16372Ki, which exceeds its request of 0.

後續步驟

建立已啟用 Azure Arc 的 PostgreSQL 伺服器