メインコンテンツへスキップ
メインコンテンツへスキップ

Managed Postgres OpenAPI

Beta

ClickHouse OpenAPI を使用すると、ClickHouse サービスと同様に Managed Postgres サービスもプログラムで制御できます。同じ API では、サービスメトリクスをスクレイピングするための [Prometheus エンドポイント] も公開されています。OpenAPI にすでに慣れている場合は、[API キー] を取得して Managed Postgres API リファレンス に直接進んでください。そうでない場合は、このまま読み進めて概要をすばやく確認してください。

API キー

ClickHouse OpenAPI の使用には認証が必要です。作成方法については [API キー] を参照してください。その後、次のようにBasic認証の認証情報として使用します。

KEY_ID=mykeyid
KEY_SECRET=mykeysecret

curl -s --user "$KEY_ID:$KEY_SECRET" https://api.clickhouse.cloud/v1/organizations | jq

組織 ID

次に、組織 ID を取得します。

  1. コンソールの左下にある組織名を選択します。
  2. Organization details を選択します。
  3. Organization ID の右側にあるコピーアイコンをクリックして、 クリップボードに直接コピーします。

これで、次のようにリクエストで使用できます。

ORG_ID=myorgid

curl -s --user "$KEY_ID:$KEY_SECRET" \
    "https://api.clickhouse.cloud/v1/organizations/$ORG_ID/postgres" | jq

これで、最初の Postgres API リクエストを実行できました。上記の list API では、 組織内のすべての Postgres サーバーが一覧表示されます。出力は次のようになります。

{
  "result": [
    {
      "id": "ee2fef9f-b443-8ad0-8c9b-724390cdb826",
      "name": "oltp",
      "provider": "aws",
      "region": "eu-west-2",
      "postgresVersion": "18",
      "size": "r6gd.medium",
      "storageSize": 59,
      "haType": "none",
      "tags": [],
      "isPrimary": true,
      "state": "running",
      "createdAt": "2026-05-25T16:42:16+00:00"
    }
  ],
  "requestId": "c128d830-5769-4c82-8235-f79aa69d1ebf",
  "status": 200
}

CRUD

それでは、Postgresサービスのライフサイクルを見ていきます。

作成

まず、create API を使用して新しいサービスを作成します。リクエストの JSON ボディには、次のプロパティを含める必要があります。

  • name: 新しい Postgres サービスの名前
  • provider: クラウドプロバイダーの名前
  • region: サービスをデプロイするプロバイダーのネットワーク内の 区域
  • size: VM のサイズ

これらのプロパティに指定可能な値については、create API のドキュメントを参照してください。さらに、 デフォルトの 17 ではなく、Postgres 18 を指定しましょう:

create_data='{
  "name": "my postgres",
  "provider": "aws",
  "region": "us-west-2",
  "postgresVersion": "18",
  "size": "r8gd.large"
}'

では、このデータを使用して新しいインスタンスを作成します。なお、content-type ヘッダーが必要です:

curl -s --user "$KEY_ID:$KEY_SECRET" -H 'Content-Type: application/json' \
    "https://api.clickhouse.cloud/v1/organizations/$ORG_ID/postgres" \
    -d "$create_data" | jq

成功すると、新しいインスタンスが作成され、その情報が返されます。 これには接続データも含まれます:

{
  "result": {
    "id": "67b4bc12-8582-45d0-8806-fe9b2e5a54e6",
    "name": "my postgres",
    "provider": "aws",
    "region": "us-west-2",
    "postgresVersion": "18",
    "size": "r8gd.large",
    "storageSize": 118,
    "haType": "none",
    "tags": [],
    "connectionString": "postgres://postgres:vV6cfEr2p_-TzkCDrZOx@my-postgres-6d8d2e3e.pg7myrd1j06p3gx4zrm2ze8qz6.c0.us-west-2.aws.pg.clickhouse-dev.com:5432/postgres?channel_binding=require",
    "username": "postgres",
    "password": "vV6cfEr2p_-TzkCDrZOx",
    "hostname": "my-postgres-6d8d2e3e.pg7myrd1j06p3gx4zrm2ze8qz6.c0.us-west-2.aws.pg.clickhouse-dev.com",
    "isPrimary": true,
    "state": "creating"
  },
  "requestId": "a5957990-dbe5-46fd-b5ce-a7f8f79e50fe",
  "status": 200
}

取得

レスポンスの id を使用して、サービスを再度取得します。

PG_ID=67b4bc12-8582-45d0-8806-fe9b2e5a54e6
curl -s --user "$KEY_ID:$KEY_SECRET" \
    "https://api.clickhouse.cloud/v1/organizations/$ORG_ID/postgres/$PG_ID" \
    | jq

出力は作成時に返されるJSONとほぼ同じですが、stateを 確認してください。runningに変わったら、サーバーの準備完了です:

curl -s --user "$KEY_ID:$KEY_SECRET" \
    "https://api.clickhouse.cloud/v1/organizations/$ORG_ID/postgres/$PG_ID" \
    | jq .result.state
"running"

これで、connectionString プロパティを使用して、たとえば psql 経由で接続できます。

$ psql "$(
    curl -s --user "$KEY_ID:$KEY_SECRET" \
    "https://api.clickhouse.cloud/v1/organizations/$ORG_ID/postgres/$PG_ID" \
    | jq -r .result.connectionString
)"

psql (18.3)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql)
Type "help" for help.

postgres=#

psql を終了するには、\q を入力します。

更新

Managed Postgres サービスのプロパティの子集は、RFC 7396 JSON Merge Patch を使用する patch API で更新できます。複雑なデプロイでは、タグが特に重要になる場合があります。その場合は、リクエストでタグだけを送信してください。

curl -sX PATCH --user "$KEY_ID:$KEY_SECRET" -H 'Content-Type: application/json' \
    "https://api.clickhouse.cloud/v1/organizations/$ORG_ID/postgres/$PG_ID" \
    -d '{"tags": [{"key": "Environment", "value": "production"}]}' \
    | jq .result

返されるデータには、次の新しいタグが含まれているはずです:

{
  "id": "67b4bc12-8582-45d0-8806-fe9b2e5a54e6",
  "name": "my postgres",
  "provider": "aws",
  "region": "us-west-2",
  "postgresVersion": "18",
  "size": "r8gd.large",
  "storageSize": 118,
  "haType": "none",
  "tags": [
    {
      "key": "Environment",
      "value": "production"
    }
  ],
  "connectionString": "postgres://postgres:vV6cfEr2p_-TzkCDrZOx@my-postgres-6d8d2e3e.$PG_ID.c0.us-west-2.aws.pg.clickhouse-dev.com:5432/postgres?channel_binding=require",
  "username": "postgres",
  "password": "vV6cfEr2p_-TzkCDrZOx",
  "hostname": "my-postgres-6d8d2e3e.$PG_ID.c0.us-west-2.aws.pg.clickhouse-dev.com",
  "isPrimary": true,
  "state": "running"
}

OpenAPI には、patch API でサポートされていないプロパティを更新するための追加エンドポイントが用意されています。たとえば、Postgres configuration を更新するには、config API を使用します。

curl -s --user "$KEY_ID:$KEY_SECRET" -H 'Content-Type: application/json' \
    "https://api.clickhouse.cloud/v1/organizations/$ORG_ID/postgres/$PG_ID/config" \
    -d '{"pgConfig": {"max_connections": "42"}, "pgBouncerConfig": {}}' | jq

出力には、更新後の設定に加えて、変更による影響を説明するメッセージも表示されます:

{
  "result":{
    "pgConfig": {
      "max_connections": "42"
    },
    "pgBouncerConfig": {},
    "message": "The changes in the following parameters require a database restart to take effect: max_connections. You can restart the database by using the restart endpoint."
  },
  "requestId":"fdec06f2-66f7-45b4-9f82-0c051aba20aa",
  "status": 200
}

削除

Postgres サービスを削除するには、delete API を使用します。

注意

Postgres サービスを削除すると、サービス自体とそのすべての データが完全に削除されます。サービスを削除する前に、 必ずバックアップを取得するか、レプリカをプライマリに昇格させてください。

curl -sX DELETE --user "$KEY_ID:$KEY_SECRET" \
    "https://api.clickhouse.cloud/v1/organizations/$ORG_ID/postgres/$PG_ID" \
    | jq

成功すると、レスポンスにはステータスコード 200 が返されます。例:

{
  "requestId": "ac9bbffa-e370-410c-8bdd-bd24bf3d7f82",
  "status": 200
}

監視

Prometheus 互換の 2 つのエンドポイントで、Managed Postgres サービスの CPU、メモリ、I/O、接続、 およびトランザクションのメトリクスを公開します。1 つは組織内のすべてのサービスの メトリクスを返し、もう 1 つは単一のサービスのメトリクスを返します。 設定については Prometheus endpoint ページを、メトリクスの完全な一覧については metrics reference を参照してください。