> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/integrations/resource-integrations/clickhouse/requesting-access.md). Agents can also search and read this documentation through its [MCP server](https://docs.p0.dev/~gitbook/mcp).

# Requesting ClickHouse Cloud access

How to request just-in-time SQL access or a console role on a ClickHouse Cloud service via P0

{% hint style="info" %}
The ClickHouse Cloud integration is in beta. Functionality and configuration may change.
{% endhint %}

You can request access to one service in a ClickHouse Cloud organization: SQL access at a level on an object, or a console role. When your request is approved, P0 gives the access to your own ClickHouse Cloud login. When access ends, P0 takes it away.

{% hint style="info" %}
P0 finds you in the organization by the email you sign in to P0 with, and doesn't add members. Join the organization with that email before you request.
{% endhint %}

## Requesting from the P0 CLI

To request SQL access:

```bash
p0 request clickhouse sql <service> <object> <level>
```

To request a console role:

```bash
p0 request clickhouse console <service> <consoleRole>
```

| Argument        | Description                                                                                                                                                                                  |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<service>`     | The service, by its name or its ID. P0 looks in every ClickHouse Cloud organization your admin installed.                                                                                    |
| `<object>`      | `'*'`, quoted, for the whole service, a database by its name, such as `analytics`, or a table, view, materialized view or dictionary in one, as `database.name`, such as `analytics.events`. |
| `<level>`       | `read`, `write` or `admin`. See [#what-you-can-request](#what-you-can-request "mention").                                                                                                    |
| `<consoleRole>` | `sql-console-readonly`, `sql-console-admin`, `service-reader` or `service-admin`.                                                                                                            |

P0 matches a service's ID ignoring case, and its name as you typed it, then ignoring case. If two services share the name, P0 refuses the request and lists their IDs, so request it by its ID instead. Objects are case-sensitive.

For example, to read the table `analytics.events` in the service `prod`:

```bash
p0 request clickhouse sql prod analytics.events read --reason "Check yesterday's event counts"
```

To get `write` on the whole service, quote the `*` so your shell doesn't expand it:

```bash
p0 request clickhouse sql prod '*' write --reason "Backfill the events table"
```

To get SQL console read-only access:

```bash
p0 request clickhouse console prod sql-console-readonly --reason "Look into a slow query"
```

To list the services you can request, run `p0 ls clickhouse sql service`. To list a service's databases, tables, views and dictionaries, run `p0 ls clickhouse sql object --service prod`.

## Requesting from Slack or the P0 app

In Slack, the same commands work as slash commands, such as `/p0 request clickhouse sql <service> <object> <level>`. For a form, type `/p0 request` in Slack, or click **Request Access** on the **Access Management** page of the P0 app. Select **ClickHouse Cloud**, choose **SQL access** or **Console role**, and fill in its fields. **Service** lists each service with its organization, and **Object** lists `* (the whole service)` first, then the service's databases, tables, views, materialized views and dictionaries, each under its own heading.

For every way to request access, see [Requesting access](https://docs.p0.dev/access-management/access-management/just-in-time-access/requesting-access.md).

## What you can request

| Access                 | What P0 grants on the service                                                       | Services it works on     |
| ---------------------- | ----------------------------------------------------------------------------------- | ------------------------ |
| SQL access, `read`     | `SELECT` and `dictGet` on the object                                                | ClickHouse 26.4 or later |
| SQL access, `write`    | `read`'s, and `INSERT`, `ALTER UPDATE`, `ALTER DELETE` and `TRUNCATE` on the object | ClickHouse 26.4 or later |
| SQL access, `admin`    | `write`'s, and `CREATE`, `DROP`, `ALTER` and `OPTIMIZE` on the object               | ClickHouse 26.4 or later |
| `sql-console-readonly` | SQL console read-only access                                                        | Any                      |
| `sql-console-admin`    | SQL console admin access                                                            | Any                      |
| `service-reader`       | The service permissions of ClickHouse Cloud's **Service Reader** role               | Any                      |
| `service-admin`        | The service permissions of ClickHouse Cloud's **Service Admin** role                | Any                      |

P0 gives you the access through a custom role it creates for your request, whose name starts with `p0_`, with you as its only member. The role also lets you view the organization and the service in the console. Your own roles in the organization don't change. P0 doesn't grant access on BYOC services. On the whole service, P0 grants `write` and `admin` with a revoke of every privilege beyond `read`'s on the `system` database.

A grant on a view or materialized view covers that view only. To read through it, the view must be defined with `SQL SECURITY DEFINER`, or you request its source tables too. For more, see [ClickHouse Cloud](https://docs.p0.dev/integrations/resource-integrations/clickhouse.md#what-p0-can-grant).

## When your request is approved

Once P0 grants the access, its message says what it granted and on which service.

Open the service in the ClickHouse Cloud console, signed in with your own ClickHouse Cloud login, and use SQL console. You need no password. `clickhouse-client --login` works too.

{% hint style="info" %}
**ClickHouse Cloud can take up to 10 minutes to apply the access.** If a query is refused right after approval, wait a few minutes and run it again. If your access still doesn't appear after 10 minutes, ask your ClickHouse Cloud admin to check that the service's JWT authentication has its SQL Console toggle on.
{% endhint %}

When your access ends, P0 deletes the role. ClickHouse Cloud can take up to 10 minutes to remove the access, and a query that's running then may finish.

## When P0 refuses your request

P0 refuses a request as you make it in these cases. It checks your membership and the service again at approval, so you can see those then too.

| Message                                                                                                                                                                                                                                                          | Why                                                                                                                                    | What to do                                                                                                                       |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `<email> isn't a member of the ClickHouse Cloud organization <organization>. P0 doesn't add members: join the ClickHouse Cloud organization first, then request access again.`                                                                                   | No member of the organization has the email you sign in to P0 with.                                                                    | Ask your ClickHouse Cloud admin to invite you with your P0 email. Once you've joined, request again.                             |
| `More than one member of the ClickHouse Cloud organization <organization> has the email <email>, so P0 can't tell which is yours. Ask your ClickHouse Cloud admin to remove the extra member, then request access again.`                                        | Two or more members have your email.                                                                                                   | Ask your ClickHouse Cloud admin to remove the extra member. Then request again.                                                  |
| `P0 can't grant access in the ClickHouse Cloud organization <organization> to <email>: the organization's connector doesn't act for that email's domain. Ask your P0 admin which domains it allows.`                                                             | Your P0 email's domain isn't one that your admin allows for this organization.                                                         | Ask your P0 admin which domains the connector allows. P0 can't grant you access in this organization with an email outside them. |
| `<service> isn't a service in any ClickHouse Cloud organization installed in P0. Check the service's name or ID.`                                                                                                                                                | No installed organization has a service with that name or ID.                                                                          | Check the name with `p0 ls clickhouse sql service`, then request again.                                                          |
| `<service> is a service in the ClickHouse Cloud organization <organization>, which is waiting on "Finish" in P0, so access in it can't be requested right now. Ask your P0 admin to click "Finish" on the organization's page in P0, then request access again.` | Your P0 admin hasn't finished installing the organization.                                                                             | Ask your P0 admin to click **Finish**. Then request again.                                                                       |
| A message that starts `P0 couldn't list the services of the ClickHouse Cloud organization <organization>, so it can't tell which service <service> is. Request the service by its ID instead.`                                                                   | You named the service by its name, and one organization couldn't list its services. The end of the message says what went wrong there. | Request the service by its ID, or ask your P0 admin to fix what the message names.                                               |
| `More than one ClickHouse Cloud service is named <name>: <id> in <organization>, <id> in <organization>. Request access to one of them by its ID.`                                                                                                               | Two or more services share the name.                                                                                                   | Request again with one of the IDs the message lists.                                                                             |
| `<service> in the ClickHouse Cloud organization <organization> is a BYOC (Bring Your Own Cloud) service, and P0 doesn't grant access on BYOC services.`                                                                                                          | P0 doesn't support BYOC services.                                                                                                      | Ask your ClickHouse Cloud admin for access.                                                                                      |
| `<service> in the ClickHouse Cloud organization <organization> runs ClickHouse <version>. SQL access needs ClickHouse 26.4 or later; console roles work on any version.`                                                                                         | The service runs a ClickHouse older than 26.4.                                                                                         | Request a console role instead, or ask your ClickHouse Cloud admin to upgrade the service.                                       |
| A message that starts `ClickHouse Cloud doesn't say which version of ClickHouse <service>`                                                                                                                                                                       | ClickHouse Cloud didn't report the service's version.                                                                                  | Request a console role instead, or request again later.                                                                          |
| `<object> isn't a database, table, view or dictionary in the service <service> (ClickHouse Cloud organization <organization>). Name the whole service as '*' (quoted in the CLI), a database by its name, or anything in one as database.name.`                  | The service has no such object. Names are case-sensitive.                                                                              | Check the object with `p0 ls clickhouse sql object --service <service>`, then request again.                                     |
| `The level must be one of read, write, admin.`                                                                                                                                                                                                                   | The level isn't one of the three.                                                                                                      | Request again with `read`, `write` or `admin`.                                                                                   |
| `The console role must be one of sql-console-readonly, sql-console-admin, service-reader, service-admin.`                                                                                                                                                        | The console role isn't one of the four.                                                                                                | Request again with one of them.                                                                                                  |
| `The service <name> (<id>) isn't in the ClickHouse Cloud organization <organization> any more.`                                                                                                                                                                  | The service was deleted after you requested.                                                                                           | Make a new request on another service.                                                                                           |

## Troubleshooting

| Message                                                                                                                                                                                                                                                                                                                                                                                              | What to do                                                                                                                                                                                     |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `P0 doesn't know which email domains the connector of the ClickHouse Cloud organization <organization> acts for, so it can't grant access there. Ask your P0 admin to remove the organization in P0 and add it again.`                                                                                                                                                                               | An admin removes the organization and adds it again, as in [ClickHouse Cloud](https://docs.p0.dev/integrations/resource-integrations/clickhouse.md#on-requests). Then request again.           |
| `This ClickHouse Cloud service has more than 50,000 databases, tables, views and dictionaries, so P0 can't list them. Request the whole service as '*' instead: that doesn't need the list.`, or `This ClickHouse Cloud service has too many databases, tables, views and dictionaries to fit in 4 MB, so P0 can't list them. Request the whole service as '*' instead: that doesn't need the list.` | P0 can't check SQL access requests on objects in a service this large. Request access to the whole service, `'*'`, or a console role instead.                                                  |
| `The ClickHouse Cloud organization <organization> isn't finished installing in P0, so access in it can't be requested right now. Ask your P0 admin to click "Finish" on the organization's page in P0, then request access again.`                                                                                                                                                                   | An admin clicks **Finish** on the organization's page in P0. Then request again. Access you already have there still ends on time.                                                             |
| `P0 couldn't reach the ClickHouse Cloud connector. Ask your P0 admin to check its deployment.`                                                                                                                                                                                                                                                                                                       | An admin checks that the connector is deployed, and that P0 can invoke it.                                                                                                                     |
| `P0's ClickHouse Cloud connector couldn't read the API key of the ClickHouse Cloud organization <organization>. Ask your P0 admin to check the key's secret, and the connector's read grant on it.`                                                                                                                                                                                                  | An admin checks the API key's secret, as in [ClickHouse Cloud](https://docs.p0.dev/integrations/resource-integrations/clickhouse.md#on-requests).                                              |
| `The ClickHouse Cloud organization <organization-id> isn't installed in P0. Access in it can't be requested, changed or revoked until it's installed again.`                                                                                                                                                                                                                                         | An admin adds the organization again, as in [ClickHouse Cloud](https://docs.p0.dev/integrations/resource-integrations/clickhouse.md#on-requests).                                              |
| `The connector <id> of the ClickHouse Cloud organization <organization> isn't installed, so P0 can't act in the organization. Ask your P0 admin to install it again. Access that P0 already granted in <organization> may need to be removed by hand.`                                                                                                                                               | An admin installs the organization's connector, as in [ClickHouse Cloud](https://docs.p0.dev/integrations/resource-integrations/clickhouse.md#on-requests).                                    |
| A message that ends `Ask your P0 admin to fix the API key of the ClickHouse Cloud organization <organization>.`                                                                                                                                                                                                                                                                                      | ClickHouse Cloud refused P0's API key. An admin fixes the key, as in [ClickHouse Cloud](https://docs.p0.dev/integrations/resource-integrations/clickhouse.md#on-requests). Then request again. |
| `ClickHouse Cloud rate-limited the API key P0 uses for the organization <organization>. Try again in a few minutes. If it keeps happening, the organization's ClickHouse Cloud admin can ask ClickHouse support to raise the key's rate limit.`                                                                                                                                                      | Request again in a few minutes. If it keeps happening, tell your ClickHouse Cloud admin.                                                                                                       |
| `ClickHouse Cloud is temporarily unavailable. Try again in a few minutes.`                                                                                                                                                                                                                                                                                                                           | Request again in a few minutes.                                                                                                                                                                |
