排解 AlloyDB Omni Kubernetes 運算子問題

選取說明文件版本:

本頁面說明如何解決 AlloyDB Omni Kubernetes 運算子的問題。

收集偵錯資訊

這些章節說明如何收集記錄和設定以進行偵錯。

從運算子 Pod 擷取記錄

如要從運算子 Pod 擷取記錄,請執行下列指令:

kubectl logs deployments/fleet-controller-manager -c manager -n alloydb-omni-system
kubectl logs deployments/local-controller-manager -c manager -n alloydb-omni-system

擷取資料庫 Pod 記錄

如要擷取資料庫 Pod 記錄,請執行下列指令:

kubectl logs al-<id-instance-name>-0 -n db
kubectl logs -l alloydbomni.internal.dbadmin.goog/dbcluster=dbcluster-name -c database -n db

以下記錄是資料庫健康狀態檢查成功的範例:

I1106 16:17:28.826188      30 gateway.go:166] "DatabaseHealthCheck: handling request" log_name="agent" project_ns="dbc-bugbash" dbcluster="dbcluster-sample"
I1106 16:17:28.826295      30 gateway.go:184] "DatabaseHealthCheck: request handled successfully" log_name="agent" project_ns="dbc-bugbash" dbcluster="dbcluster-s
ample"
I1106 16:17:34.810447      30 gateway.go:166] "DatabaseHealthCheck: handling request" log_name="agent" project_ns="dbc-bugbash" dbcluster="dbcluster-sample"
I1106 16:17:34.834844      30 gateway.go:184] "DatabaseHealthCheck: request handled successfully" log_name="agent" project_ns="dbc-bugbash" dbcluster="dbcluster-s
ample"
I1106 16:17:38.825843      30 gateway.go:166] "DatabaseHealthCheck: handling request" log_name="agent" project_ns="dbc-bugbash" dbcluster="dbcluster-sample"
I1106 16:17:38.825959      30 gateway.go:184] "DatabaseHealthCheck: request handled successfully" log_name="agent" project_ns="dbc-bugbash" dbcluster="dbcluster-s
ample"

擷取 postgresql.log

如要擷取 postgresql.log,請執行下列指令:

kubectl exec -it al-id-instance-name-0 -n db -c database -- cat /obs/diagnostic/postgresql.log

擷取 DBInstance YAML 檔案

如要擷取 DBInstance YAML 檔案,請執行下列指令:

kubectl get dbclusters.a <dbcluster-name> -n db -o yaml

擷取高可用性情境的設定和記錄

如要擷取高可用性 (HA) 情境專屬的設定和記錄,請執行下列指令:

kubectl get replicationconfig -n <namespace>
kubectl get deletestandbyjobs.alloydbomni.internal -n <namespace> -o yaml
kubectl get createstandbyjobs.alloydbomni.internal -n <namespace> -o yaml
kubectl get failovers.alloydbomni.dbadmin.goog -n <namespace> -o yaml

擷取 Pod 和 STS 狀態

如要擷取 Pod 和 StatefulSet (STS) 狀態,請執行下列指令:

kubectl describe pod -n <namespace> <pod-name>
kubectl describe statefulset -n <namespace> al-<id-instance-name>

找出錯誤

這些章節說明如何找出錯誤。

尋找錯誤狀態和錯誤代碼

如要找出錯誤代碼,請檢查狀態下的 DBCluster YAML 檔案。 詳情請參閱錯誤代碼說明文件。

如要擷取 DBCluster YAML 檔案,請執行下列指令:

kubectl get dbclusters.a <dbcluster-name> -n <dbcluster-namespace> -o yaml

尋找 criticalIncidents。這個部分包含錯誤碼和堆疊追蹤。

以下是 criticalIncidents 的範例:

status:
    certificateReference:
      certificateKey: ca.crt
      secretRef:
        name: dbs-al-cert-dr-mce
        namespace: dr
    conditions:
    -   lastTransitionTime: "2024-10-07T22:46:03Z"
    ...
    criticalIncidents:
    -   code: DBSE0304
      createTime: "2024-10-03T11:50:54Z"
      message: 'Healthcheck: Health check invalid result.'
      resource:
        component: healthcheck
        location:
          group: alloydbomni.internal.dbadmin.goog
          kind: Instance
          name: bc0f-dr-mce
          namespace: dr
          version: v1
      stackTrace:
      -   component: healthcheck
        message: 'DBSE0304: Healthcheck: Health check invalid result. rpc error: code
          = Code(10304) desc = DBSE0304: Healthcheck: Health check invalid result.
          dbdaemon/healthCheck: invalid timestamp read back from the healthcheck table.
          Lag is 384837.296269 seconds, wanted 35 seconds'

您也可以擷取 JSON 格式的特定欄位,藉此取得狀態:

kubectl get dbcluster.${DBTYPE:?} -n "${PROJECT:?}" "${DBCLUSTER:?}" -o json -o jsonpath='{.status.criticalIncidents}' | jq

輸出結果會與下列內容相似:

[
  {
    "code": "DBSE0085",
    "createTime": "2024-03-14T05:41:37Z",
    "message": "Platform: Pod is unschedulable.",
    "resource": {
      "component": "provisioning",
      "location": {
        "group": "alloydb.internal.dbadmin.goog",
        "kind": "Instance",
        "name": "b55f-testdbcluster",
        "namespace": "dbs-system",
        "version": "v1"
      }
    },
    "stackTrace": [
      {
        "component": "provisioning",
        "message": "DBSE0085: Platform: Pod is unschedulable. 0/16 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: 0/16 nodes are available: 16 No preemption victims found for incoming pod..: Pod is unschedulable"
      }
    ]
  }
]

如果錯誤訊息是指資料庫 Pod,請檢查相同命名空間中的執行個體和 Pod 資源:

kubectl get instances.a dbcluster_name -n dbcluster_namespace -o yaml
kubectl get pods -l alloydbomni.internal.dbadmin.goog/dbcluster=dbcluster_name -l alloydbomni.internal.dbadmin.goog/task-type=database -n dbcluster_namespace

偵錯記憶體問題

這些章節說明如何偵錯記憶體問題。

執行並擷取記憶體快照資料

請只在需要排解問題時開啟這項功能。記得在完成後關閉。

如要擷取堆積傾印,請完成下列步驟:

  1. alloydb-omni-system 命名空間下修改運算子部署作業,名稱為 fleet-controller-managerlocal-controller-manager
  2. 將下列引數新增至 Pod --pprof-address=:8642 或任何其他可用通訊埠。
  3. 等待控制器 Pod 重新啟動。
  4. 轉送上述連接埠。例如:

    kubectl port-forward -n alloydb-omni-system fleet-controller-manager-pod-name 8642:8642
    
  5. 在另一個終端機中執行 go tool pprof http://localhost:8642/debug/pprof/heap。 如未使用 8642,請變更通訊埠,使其與前述通訊埠一致。

  6. 連線至該地址並執行疑難排解指令。例如 top

  7. 完成疑難排解後,請移除引數並等待 Pod 重新啟動,藉此還原步驟 1。

判斷運算子監控的資源數量

如要瞭解使用的資源,請執行下列指令:

kubectl get backuprepositories -A  | wc -l
kubectl get failovers -A  | wc -l
kubectl get instancebackupplans -A  | wc -l
kubectl get instancebackups -A  | wc -l
kubectl get instancerestores -A  | wc -l
kubectl get instances -A  | wc -l
kubectl get instanceswitchovers -A  | wc -l
kubectl get lrojobs -A  | wc -l
kubectl get replicationconfigs -A  | wc -l
kubectl get sidecars -A  | wc -l
kubectl get deployments -A  | wc -l
kubectl get statefulsets -A  | wc -l
kubectl get certificates.cert-manager.io -A  | wc -l
kubectl get issuers.cert-manager.io -A  | wc -l
kubectl get configmaps -A  | wc -l
kubectl get persistentvolumeclaims -A  | wc -l
kubectl get persistentvolumes -A  | wc -l
kubectl get pods -A  | wc -l
kubectl get secrets -A  | wc -l
kubectl get services -A  | wc -l
kubectl get storageclasses.storage.k8s.io -A  | wc -l

舉例來說,如果密鑰數量過多,可能會導致記憶體不足 (OOM) 錯誤。

kubectl get secrets -A | wc -l

進階 HA 偵錯

本節參照內部實作的資源。這些功能隨時可能變更,且不保證具有回溯相容性。請只對非正式環境資料庫的問題套用手動修正。這些步驟可能會導致資料庫無法復原。

AlloyDB Omni HA 設定包含三個階段:

  1. 設定主要伺服器,以便接收待機伺服器的連線。
  2. 初始化待命節點,並連線至主要節點。
  3. 設定主要設定,讓連線同步。

步驟 2 通常最慢。視資料庫大小而定,這項作業可能需要數小時才能完成。

每個複製執行個體都應附加 replicationconfig。例如:bash ❯ k get replicationconfigs.alloydbomni.internal.dbadmin.goog NAME PARENT TYPE ROLE READY HEALTHY 9f47-dbcluster-sample--7576-dbcluster-sample 9f47-dbcluster-sample Physical Upstream True True ds-7576-dbcluster-sample 7576-dbcluster-sample Physical Downstream True True

在這個例子中:

  • 執行個體 9f47-dbcluster-sample 已設為實體上游。
  • 執行個體 7576-dbcluster-sample 已設為實體下游。

複製設定的規格會指出預期設定,而狀態則會反映從資料庫讀取的實際狀態。如果規格與狀態不符,控制器仍會嘗試套用變更,或是發生錯誤導致變更無法套用。狀態欄位會反映這項異動。

待命工作

應該會有兩組內部工作追蹤待命工作流程:

  • createstandbyjobs.alloydbomni.internal.dbadmin.goog
  • deletestandbyjobs.alloydbomni.internal.dbadmin.goog

如果設定程序似乎停滯不前,請查看與資料庫叢集 (DBC) 相關的工作。作業可能會有錯誤訊息,說明設定目前處於哪種狀態。工作完成後一段時間,系統就會自動清除,因此如果沒有進行中的工作,您可能不會看到任何工作。

k get createstandbyjob

輸出結果會與下列內容相似:

apiVersion: alloydbomni.dbadmin.gdc.goog/v1
  kind: CreateStandbyJob
  metadata:
    creationTimestamp: "2024-11-05T03:34:26Z"
    finalizers:
    -   createstandbyjob.dbadmin.goog/finalizer
    generation: 1804
    labels:
      dbs.internal.dbadmin.goog/dbc: foo-ha-alloydb1-clone1
    name: foo-ha-alloydb1-clone1--ac00-foo-ha-alloydb1-clone1--6036-foo-ha-alloydb1-clone1-1730777666
    namespace: db
    resourceVersion: "11819071"
    uid: 1f24cedf-b326-422f-9405-c96c8720cd90
  spec:
    attempt: 3
    cleanup: false
    currentStep: SetupSynchronous
    currentStepTime: "2024-11-05T03:45:31Z"
    metadata:
      dbc: foo-ha-alloydb1-clone1
      primaryInstance: ac00-foo-ha-alloydb1-clone1
      retryError: 'etcdserver: leader changed'
      standbyInstance: 6036-foo-ha-alloydb1-clone1
    requeueTime: "2024-11-05T18:33:03Z"
    startTime: "2024-11-05T03:36:56Z"

主要驗證

首先,請確認主要設定正確無誤。每個待命資料庫都應有對應的複製設定檔。如果規格和狀態的 isSynchronous 為 true,則設定應已完成。如果規格和狀態中的 isSynchronous 為 false,表示尚未完成步驟 3。查看待命工作,確認是否有任何正在執行的工作,以及是否有任何錯誤訊息。

  replication:
    profiles:
    -   isActive: true
      isSynchronous: true
      name: ha:4c82-dbcluster-sample::d85d-dbcluster-sample
      password:
        name: ha-rep-pw-dbcluster-sample
        namespace: default
      passwordResourceVersion: "896080"
      role: Upstream
      type: Physical
      username: alloydbreplica

確認 disableHealthcheck 註解為 false。只有在容錯移轉或切換期間,才應停用這項功能。

apiVersion: alloydbomni.internal.dbadmin.goog/v1
kind: Instance
metadata:
  annotations:
    dbs.internal.dbadmin.goog/consecutiveHealthcheckFailures: "0"
    dbs.internal.dbadmin.goog/disableHealthcheck: "false"
    dr-secondary: "false"
    forceReconcile: "1730414498"

查詢

如要確認 DB Pod 上的資源設定正確無誤,請以管理員使用者 alloydbadmin 身分登入資料庫。然後發出下列查詢:

複製運算單元

alloydbadmin=# select * from pg_replication_slots;
-[ RECORD 1 ]-------+---------------------------------------------
slot_name           | d85d_dbcluster_sample
plugin              |
slot_type           | physical
datoid              |
database            |
temporary           | f
active              | t
active_pid          | 250
xmin                | 16318
catalog_xmin        |
restart_lsn         | 0/CA657F0
confirmed_flush_lsn |
wal_status          | reserved
safe_wal_size       |
two_phase           | f

如果複寫位置與待命執行個體同名,即為良好狀態。如果沒有複寫時段,表示第一個設定步驟尚未順利完成。

如果 active == t 為 false,表示待機裝置因某種原因 (網路、待機裝置未完成設定等) 無法連線,可能需要繼續在待機裝置端進行偵錯。

複製統計資料

alloydbadmin=# select * from pg_stat_replication;
-[ RECORD 1 ]----+----------------------------------------------------------------
pid              | 250
usesysid         | 16385
usename          | alloydbreplica
application_name | d85d_dbcluster_sample
client_addr      | 10.54.79.196
client_hostname  | gke-samwise-default-pool-afaf152d-8197.us-central1-a.c.foo
client_port      | 24914
backend_start    | 2024-10-30 21:44:26.408261+00
backend_xmin     |
state            | streaming
sent_lsn         | 0/CA64DA8
write_lsn        | 0/CA64DA8
flush_lsn        | 0/CA64DA8
replay_lsn       | 0/CA64DA8
write_lag        |
flush_lag        |
replay_lag       |
sync_priority    | 2
sync_state       | sync
reply_time       | 2024-11-04 22:08:04.370838+00

如果沒有,表示沒有連線。sync_state 應為 sync。如果不是 sync,表示設定的最後一個步驟未完成。查看記錄 / 工作應可瞭解詳情。

待命驗證

待命資料庫的複製設定檔應與主要資料庫的設定檔相符:

  replication:
    profiles:
    -   host: 10.54.79.210
      isActive: true
      isSynchronous: true
      name: ha:4c82-dbcluster-sample::d85d-dbcluster-sample
      passwordResourceVersion: "896080"
      port: 5432
      role: Downstream
      type: Physical
      username: alloydbreplica

如果待機伺服器無法連線至主要伺服器,可能有兩種常見原因:

  1. 備援裝置仍在設定中。
  2. 設定或嘗試連線時,備用裝置發生錯誤。

如要檢查是否發生選項 1 的情況,請取得資料庫 Pod 記錄,並尋找名為 dbdaemon/setupPhysicalReplicationDownstream 的記錄陳述式。以下是設定成功的記錄範例:

I1104 22:42:42.604871     103 replication.go:107] "dbdaemon/setupPhysicalReplicationDownstream: begin setup" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
2024-11-04 22:42:42,605 INFO waiting for postgres to stop
2024-11-04 22:42:43,566 INFO stopped: postgres (exit status 0)
I1104 22:42:43.567590     103 replication.go:131] "dbdaemon/setupPhysicalReplicationDownstream: about to call pg_basebackup" log_name="agent" project_ns="default" dbcluster="dbcluster-sample" cmd=["-h","10.54.79.210","-D","/mnt/disks/pgsql/pg_basebackup_data","-U","alloydbreplica","-v","-P","-p","5432","-w","-c","fast"]
I1104 22:42:44.206403     103 replication.go:139] "dbdaemon/setupPhysicalReplicationDownstream: pg_basebackup finished" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
I1104 22:42:44.206440     103 replication.go:141] "dbdaemon/setupPhysicalReplicationDownstream: replacing data directory with pg_basebackup data directory" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
I1104 22:42:44.244749     103 replication.go:148] "dbdaemon/setupPhysicalReplicationDownstream: replaced data directory with pg_basebackup data directory" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
I1104 22:42:44.244783     103 replication.go:150] "dbdaemon/setupPhysicalReplicationDownstream: Creating config files" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
I1104 22:42:44.251565     103 replication.go:155] "dbdaemon/setupPhysicalReplicationDownstream: removing postgresql config file for log archiving" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
I1104 22:42:44.251621     103 replication.go:160] "dbdaemon/setupPhysicalReplicationDownstream: removing postgresql auto config file" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
I1104 22:42:44.251689     103 replication.go:165] "dbdaemon/setupPhysicalReplicationDownstream: Successfully wrote to config file" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
2024-11-04 22:42:44,256 INFO spawned: 'postgres' with pid 271
2024-11-04 22:42:45,469 INFO success: postgres entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
I1104 22:42:45.469838     103 replication.go:174] "dbdaemon/setupPhysicalReplicationDownstream: backup replication configuration after changing replication config" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"
I1104 22:42:45.476732     103 replication.go:179] "dbdaemon/setupPhysicalReplicationDownstream: finished standby setup" log_name="agent" project_ns="default" dbcluster="dbcluster-sample"

如果發生連線錯誤,請檢查資料庫 Pod 記錄,以及 /obs/diagnostic/postgresql.log 的資料庫記錄檔,瞭解嘗試連線時發生了什麼錯誤。常見錯誤是待機和主要裝置之間沒有網路連線。

手動修正

如要修正 HA 問題,最簡單的方法是先將 numberOfStandbys 設為 0,然後重設為所需數字,藉此停用再重新啟用 HA。如果備用裝置無法停用,請按照下列步驟手動重設 HA 設定,使其為空白:

  1. 手動刪除待命執行個體。
  2. 連線至主要資料庫。查詢目前的複寫位置,然後刪除要刪除的待命複寫位置:

    select pg_drop_replication_slot('<replication_slot_name_here>');
    
  3. 從要刪除的主要執行個體中,刪除所有複製設定檔。

如果執行個體最近未完成對帳,您可以編輯 forceReconcile 註解值。請將該值設為任何數值,也就是上次更新註解的時間戳記。該註解的唯一用途是提供可更新的欄位,以強制執行新的對帳作業。

apiVersion: alloydbomni.internal.dbadmin.goog/v1
kind: Instance
metadata:
  annotations:
    dbs.internal.dbadmin.goog/consecutiveHealthcheckFailures: "0"
    dbs.internal.dbadmin.goog/disableHealthcheck: "false"
    dr-secondary: "false"
    forceReconcile: "1730414498"

收集資料庫引擎和稽核記錄

資料庫引擎記錄和稽核記錄會以檔案形式儲存在資料庫 Pod 中 (需要根存取權):

  • obs/diagnostic/postgresql.log
  • obs/diagnostic/postgresql.audit
export NAMESPACE=dbcluster-namespace
export DBCLUSTER=dbcluster-sample

export DBPOD=`kubectl get pod -n ${NAMESPACE} -l alloydbomni.internal.dbadmin.goog/dbcluster=${DBCLUSTER} -l alloydbomni.internal.dbadmin.goog/task-type=database -o jsonpath='{.items[0].metadata.name}'`
kubectl exec -n ${NAMESPACE} ${DBPOD} -it -- /bin/bash

$ ls -la /obs/diagnostic/
-rw------- 1 postgres postgres    98438 Sep 25 20:15 postgresql.audit
-rw------- 1 postgres postgres 21405058 Sep 25 20:24 postgresql.log

收集資料庫和資料庫 Pod 指標

AlloyDB Omni 運算子提供 AlloyDB Omni 引擎和代管該引擎的 Pod 的一組基本指標。這些指標會以 Prometheus 端點的形式提供,通訊埠為 9187。如要存取端點,您需要使用 DBCluster 和工作類型標籤,找出資料庫 Pod 和資料庫監控 Pod 的名稱,如下所示。

export NAMESPACE=default
export DBCLUSTER=dbcluster-sample

export DBPOD=`kubectl get pod -n ${NAMESPACE} -l alloydbomni.internal.dbadmin.goog/dbcluster=${DBCLUSTER},alloydbomni.internal.dbadmin.gdc.goog/task-type=database -o jsonpath='{.items[0].metadata.name}'`

export MONITORINGPOD=`kubectl get pod -n ${NAMESPACE} -l alloydbomni.internal.dbadmin.goog/dbcluster=${DBCLUSTER},alloydbomni.internal.dbadmin.gdc.goog/task-type=monitoring -o jsonpath='{.items[0].metadata.name}'`

存取 AlloyDB Omni 資料庫指標

kubectl port-forward -n ${NAMESPACE} ${MONITORINGPOD} 9187:9187
curl http://localhost:9187/metrics | grep HELP

存取資料庫 Pod 指標

kubectl port-forward -n ${NAMESPACE} ${DBPOD} 9187:9187
curl http://localhost:9187/metrics | grep HELP

您也可以設定 Prometheus,從 Kubernetes 叢集抓取指標。詳情請參閱 Prometheus Kubernetes 服務探索設定