Private preview in ClickHouse Cloud
ClickHouse OpenAPI를 사용하면 ClickHouse 서비스와 마찬가지로 Managed Postgres 서비스도 프로그래밍 방식으로 제어할 수 있습니다. 이미 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가 필요합니다.
- 콘솔 왼쪽 하단에서 조직 이름을 선택합니다.
- Organization details를 선택합니다.
- Organization ID 오른쪽에 있는 복사 아이콘을 클릭하여
클립보드로 직접 복사합니다.
CRUD
Postgres 서비스의 생명주기를 살펴보겠습니다.
먼저 create API를 사용하여 새 항목을 생성합니다. 요청의 JSON 본문에는
다음 속성이 필요합니다:
name: 새 Postgres 서비스의 이름
provider: 클라우드 제공자의 이름
region: 서비스를 배포할 클라우드 제공자 네트워크 내의 영역
size: VM 크기
storageSize: VM의 스토리지 크기
이러한 속성에 사용할 수 있는 값은 create API 문서를 참조하십시오. 또한
기본값인 17 대신 Postgres 18을 지정하겠습니다:
create_data='{
"name": "my postgres",
"provider": "aws",
"region": "us-west-2",
"postgresVersion": "18",
"size": "r8gd.large",
"storageSize": 118
}'
이제 이 데이터를 사용해 새 인스턴스를 생성합니다. 이때 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": "pg7myrd1j06p3gx4zrm2ze8qz6",
"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=pg7myrd1j06p3gx4zrm2ze8qz6
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
이제 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를 입력하세요.
업데이트
patch API는 RFC 7396 JSON Merge Patch를 사용해 Managed
Postgres 서비스의 속성 일부만 업데이트할 수 있습니다. 복잡한
배포에서는 태그가 특히 유용할 수 있으며, 요청에 태그만 보내면 됩니다:
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": "$PG_ID",
"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"
}
Postgres 서비스를 삭제하려면 delete API를 사용합니다.
참고
Postgres 서비스를 삭제하면 서비스와 그 안의 모든 데이터가 완전히
삭제됩니다. 서비스를 삭제하기 전에 반드시 백업이 있거나 레플리카를
primary로 승격해 두었는지 확인하십시오.
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
}