次の方法で共有


高可用性を管理する

Important

Lakebase 自動スケールは、自動スケール コンピューティング、ゼロへのスケール、分岐、インスタント リストアを備えた最新バージョンの Lakebase です。 サポートされているリージョンについては、「 リージョンの可用性」を参照してください。 Lakebase プロビジョニング済みユーザーの場合は、「 Lakebase Provisioned」を参照してください。

このガイドでは、Lakebase エンドポイントの高可用性の有効化と管理について説明します。 高可用性のしくみとセカンダリ コンピューティング インスタンスとスタンドアロン読み取りレプリカの違いの背景については、「 高可用性」を参照してください。

高可用性を有効にする

高可用性を有効にするには、UI でコンピューティングの種類と HA 構成を設定するか、API を使用してエンドポイントの EndpointGroupSpec を構成します。

前提条件

  • ゼロへのスケールは無効にする必要があります。 UI で、コンピューティング ドロワーの編集で [スケール]を 0[オフ] に設定します。 API を使用して、エンドポイント スペックで no_suspension: true を設定します (更新マスクとして spec.suspension を使用します)。

UI

プロジェクトを作成したら、プロジェクト ダッシュボードからプライマリ コンピューティング リンクをクリックして、コンピューティング ドロワーの編集を開きます。

プロジェクトのダッシュボードには、主要なコンピュートリンクを含む運用ブランチが表示されています

コンピューティングの種類[高可用性] に設定し、[高可用性] で [構成] を選択します。

  • 2 (1 プライマリ、1 セカンダリ)
  • 3 (プライマリ 1、セカンダリ 2)
  • または 4 (1 プライマリ、3 セカンダリ) の合計コンピューティング インスタンス。

コンピューティングの種類の切り替えが [高可用性] に設定され、[構成] ドロップダウンに 2、3、または 4 個のコンピューティング インスタンスのオプションが表示されているコンピューティング ドロワーを編集する

Lakebase は、異なる可用性ゾーンにセカンダリ コンピューティング インスタンスをプロビジョニングします。 すべてのコンピューティング インスタンスがアクティブになると、エンドポイントには自動フェールオーバーがあります。

Python SDK

from databricks.sdk import WorkspaceClient
from databricks.sdk.service.postgres import (
    Endpoint, EndpointSpec, EndpointType, EndpointGroupSpec, FieldMask
)

w = WorkspaceClient()

endpoint_name = "projects/my-project/branches/production/endpoints/my-endpoint"

result = w.postgres.update_endpoint(
    name=endpoint_name,
    endpoint=Endpoint(
        name=endpoint_name,
        spec=EndpointSpec(
            endpoint_type=EndpointType.ENDPOINT_TYPE_READ_WRITE,
            group=EndpointGroupSpec(
                min=2,
                max=2,
                enable_readable_secondaries=True
            )
        )
    ),
    update_mask=FieldMask(field_mask=["spec.group"])
).wait()

print(f"Group size: {result.status.group.max}")
print(f"Host: {result.status.hosts.host}")
print(f"Read-only host: {result.status.hosts.read_only_host}")

CLI

databricks postgres update-endpoint \
  projects/my-project/branches/production/endpoints/my-endpoint \
  "spec.group" \
  --json '{
    "spec": {
      "group": {
        "min": 2,
        "max": 2,
        "enable_readable_secondaries": true
      }
    }
  }'

curl

curl -X PATCH "$DATABRICKS_HOST/api/2.0/postgres/projects/my-project/branches/production/endpoints/my-endpoint?update_mask=spec.group" \
  -H "Authorization: Bearer $DATABRICKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "projects/my-project/branches/production/endpoints/my-endpoint",
    "spec": {
      "group": {
        "min": 2,
        "max": 2,
        "enable_readable_secondaries": true
      }
    }
  }' | jq

セカンダリ コンピューティング インスタンスへの読み取り専用アクセスを構成する

読み取り専用コンピューティング インスタンスへのアクセスの制限は、セカンダリ コンピューティング インスタンスが -ro 接続文字列 経由で読み取りトラフィックを処理するかどうかを制御します。

UI

  1. [コンピューティング] タブ 、プライマリ コンピューティングの [編集 ] をクリックします。
  2. [ 高可用性] で、[ 読み取り専用コンピューティング インスタンスへのアクセスを許可する] チェック ボックスをオンまたはオフにします。
  3. [保存] をクリックします。

Python SDK

from databricks.sdk import WorkspaceClient
from databricks.sdk.service.postgres import (
    Endpoint, EndpointSpec, EndpointType, EndpointGroupSpec, FieldMask
)

w = WorkspaceClient()

endpoint_name = "projects/my-project/branches/production/endpoints/my-endpoint"

# Get current group size first
current = w.postgres.get_endpoint(name=endpoint_name)
current_size = current.status.group.max

w.postgres.update_endpoint(
    name=endpoint_name,
    endpoint=Endpoint(
        name=endpoint_name,
        spec=EndpointSpec(
            endpoint_type=EndpointType.ENDPOINT_TYPE_READ_WRITE,
            group=EndpointGroupSpec(
                min=current_size,
                max=current_size,
                enable_readable_secondaries=True  # set False to disable
            )
        )
    ),
    update_mask=FieldMask(field_mask=["spec.group.enable_readable_secondaries"])
).wait()

CLI

# Replace 2 with your current group size
databricks postgres update-endpoint \
  projects/my-project/branches/production/endpoints/my-endpoint \
  "spec.group.enable_readable_secondaries" \
  --json '{
    "spec": {
      "group": {
        "min": 2,
        "max": 2,
        "enable_readable_secondaries": true
      }
    }
  }'

curl

# Replace 2 with your current group size
curl -X PATCH "$DATABRICKS_HOST/api/2.0/postgres/projects/my-project/branches/production/endpoints/my-endpoint?update_mask=spec.group.enable_readable_secondaries" \
  -H "Authorization: Bearer $DATABRICKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "projects/my-project/branches/production/endpoints/my-endpoint",
    "spec": {
      "group": {
        "min": 2,
        "max": 2,
        "enable_readable_secondaries": true
      }
    }
  }' | jq

Warnung

セカンダリ コンピューティング インスタンス1のみが有効になっており、読み取りアクセスが有効になっている場合、-ro 接続文字列 上のすべての読み取りトラフィックは、置換が追加されるまでフェールオーバー中に中断されます。 回復性のある読み取りアクセスを実現するには、読み取りアクセスが有効になっている 2 つ以上 のセカンダリ コンピューティング インスタンスを構成します。

セカンダリ コンピューティング インスタンスの数を変更する

UI

  1. [コンピューティング] タブ 、プライマリ コンピューティングの [編集 ] をクリックします。
  2. [ 高可用性] で、ドロップダウンから新しい コンピューティング構成 を選択します (合計コンピューティング インスタンス数は 23、または 4 )。
  3. [保存] をクリックします。

高可用性を無効にするには、コンピューティングの 種類[単一コンピューティング] に戻します。 これにより、すべてのセカンダリ コンピューティング インスタンスが削除され、エンドポイントが単一コンピューティング構成に戻ります。

Python SDK

from databricks.sdk import WorkspaceClient
from databricks.sdk.service.postgres import (
    Endpoint, EndpointSpec, EndpointType, EndpointGroupSpec, FieldMask
)

w = WorkspaceClient()

endpoint_name = "projects/my-project/branches/production/endpoints/my-endpoint"

# Scale to 3 compute instances (1 primary + 2 secondaries)
w.postgres.update_endpoint(
    name=endpoint_name,
    endpoint=Endpoint(
        name=endpoint_name,
        spec=EndpointSpec(
            endpoint_type=EndpointType.ENDPOINT_TYPE_READ_WRITE,
            group=EndpointGroupSpec(min=3, max=3)
        )
    ),
    update_mask=FieldMask(field_mask=["spec.group.min", "spec.group.max"])
).wait()

CLI

# Scale to 3 compute instances (1 primary + 2 secondaries)
databricks postgres update-endpoint \
  projects/my-project/branches/production/endpoints/my-endpoint \
  "spec.group.min,spec.group.max" \
  --json '{
    "spec": {
      "group": { "min": 3, "max": 3 }
    }
  }'

curl

curl -X PATCH "$DATABRICKS_HOST/api/2.0/postgres/projects/my-project/branches/production/endpoints/my-endpoint?update_mask=spec.group.min,spec.group.max" \
  -H "Authorization: Bearer $DATABRICKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "projects/my-project/branches/production/endpoints/my-endpoint",
    "spec": {
      "group": { "min": 3, "max": 3 }
    }
  }' | jq

高可用性の状態とロールを表示する

[ コンピューティング ] タブには、現在のロール、状態、アクセス レベルを持つ高可用性構成内のすべてのコンピューティング インスタンスが表示されます。

読み取り/書き込みアクセス権を持つ 1 つのプライマリ コンピューティング インスタンスと、読み取り専用アクセス権を持つ 3 つのセカンダリ コンピューティング インスタンス (すべて ACTIVE) を示す [コンピューティング] タブ

コラム 価値観
役割 プライマリ、セカンダリ
地位 開始状態、アクティブ
Access 読み取り/書き込み (プライマリ)、読み取り専用 (アクセスが有効なセカンダリ コンピューティング インスタンス)、無効 (読み取りアクセス権のないセカンダリ コンピューティング インスタンス)

プライマリ コンピューティング ヘッダーには、エンドポイント ID、自動スケール範囲、セカンダリカウント ( 8 ↔ 16 CU · 3 secondaries など) も表示されます。

接続文字列を取得する

UI

プライマリ コンピューティングで [ 接続 ] をクリックして、接続の詳細ダイアログを開きます。 [ コンピューティング] ドロップダウンには、高可用性エンドポイントの両方の接続オプションが一覧表示されます。

プライマリとセカンダリのROオプションが表示された[計算]ドロップダウンが開き、接続の詳細ダイアログに読み取り専用の接続文字列が表示されます。

コンピューティング オプション 接続文字列 使用対象
Primary (name) ● Active {endpoint-id}.database.{region}.databricks.com すべての書き込みと読み取り/書き込み接続
Secondary (name) ● Active RO {endpoint-id}-ro.database.{region}.databricks.com 第二の計算インスタンスへの負荷分散読み取り

-ro 接続文字列は、読み取り専用コンピューティング インスタンスへのアクセス権が有効になっている場合にのみ使用できます。

Python SDK

from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

endpoint = w.postgres.get_endpoint(
    name="projects/my-project/branches/production/endpoints/my-endpoint"
)

print(f"Read/write host: {endpoint.status.hosts.host}")
print(f"Read-only host:  {endpoint.status.hosts.read_only_host}")

CLI

databricks postgres get-endpoint \
  projects/my-project/branches/production/endpoints/my-endpoint \
  -o json | jq '{rw_host: .status.hosts.host, ro_host: .status.hosts.read_only_host}'

curl

curl -X GET "$DATABRICKS_HOST/api/2.0/postgres/projects/my-project/branches/production/endpoints/my-endpoint" \
  -H "Authorization: Bearer $DATABRICKS_TOKEN" \
  | jq '{rw_host: .status.hosts.host, ro_host: .status.hosts.read_only_host}'

完全な接続文字列リファレンスについては、接続文字列を参照してください。

次のステップ

  • 高可用性 - 概念、フェールオーバー動作、ベスト プラクティス
  • 読み取りレプリカ — スタンドアロンの読み取りレプリカは、高可用性なしで追加の読み取り能力を提供します。
  • 接続文字列