> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP 400 "HTTP request URI invalid or too long": why the query is not in system.query_log and how to fix it

> The HTTP interface rejects a request whose URL exceeds http_max_uri_size (1 MiB) before a query exists, so system.query_log has no record of it. Move large values from the URL to the request body.

ClickHouse answers `400 Bad Request` with the plain-text body `HTTP request URI invalid or too long` when the URL of an HTTP request is longer than [`http_max_uri_size`](https://clickhouse.com/docs/reference/settings/session-settings/http-max#http_max_uri_size), which is 1048576 bytes (1 MiB) by default. The server rejects the request while it reads the request line, before it authenticates the user or creates a query. Nothing was executed, and that is why you cannot find the request in `system.query_log`. To fix it, send the large values in the request body instead of the URL.

## Why there is no record of the query

The URL is the first thing the server reads. The `query_id`, the user name and the settings of an HTTP request are URL parameters or headers, so a request that is rejected at this point has no user, no `query_id` and no query:

* There is no row in `system.query_log` and nothing in `system.processes`.
* No data was read or written.
* The server sends the response and closes the connection without reading the rest of the request. A client that is still sending a large request can report a reset or broken connection instead of the `400` response.

The only trace on the server is a message of the `HTTPServerConnection` logger at the `Debug` level:

```text theme={null}
HTTP request failed: Bad Request: Malformed message: HTTP request URI invalid or too long
```

Find it in the server log file, or in [`system.text_log`](https://clickhouse.com/docs/reference/system-tables/text_log) if this table is enabled:

```sql theme={null}
SELECT event_time, level, message
FROM system.text_log
WHERE logger_name = 'HTTPServerConnection'
    AND message LIKE '%URI invalid or too long%'
ORDER BY event_time DESC
LIMIT 10;
```

The message is written only if the server logs at the `debug` or `trace` level. It is not linked to a query, so search by logger and text, not by `query_id`. The server writes this message at most once in 10 seconds. If more requests were rejected in between, the next message ends with `(skipped N similar messages)`.

## How a URL gets that long

* The SQL text is sent in the `query` URL parameter instead of the request body.
* Query parameters are sent as `param_name=value` in the URL, and one of them is a long string or an array with thousands of elements.
* A client library puts these parts into the URL for you. For example, the Python client sends server-side bound parameters as HTTP parameters unless its [`form_encode_query_params`](https://clickhouse.com/docs/integrations/language-clients/python/driver-api) option places them in the request body, and the C# client can put the statement of an insert into the URL with [`InsertQueryPlacement.Url`](https://clickhouse.com/docs/integrations/language-clients/csharp/http).

A single URL parameter has its own limit as well: a value longer than [`http_max_field_value_size`](https://clickhouse.com/docs/reference/settings/session-settings/http-max#http_max_field_value_size) (131072 bytes by default) makes the request fail with `Field value too long`, even if the whole URL is shorter than 1 MiB.

## Move the data out of the URL

Send the SQL text in the body of a `POST` request and keep only short settings in the URL. Query parameters can travel in the body too, as fields of a multipart form:

```bash theme={null}
curl -X POST 'http://localhost:8123/' \
    -F 'query=SELECT count() FROM numbers(10) WHERE number IN {ids:Array(UInt64)}' \
    -F 'param_ids=[1,2,3]'
```

```text theme={null}
3
```

Form fields are still limited by `http_max_field_value_size`. For a long list of values, use one of these instead:

* Write the values into the SQL text that you send in the body. The text of a query is limited by [`max_query_size`](https://clickhouse.com/docs/reference/settings/session-settings/max#max_query_size), 262144 bytes by default, which you can raise for a request with a URL parameter.
* Send the list as [external data](https://clickhouse.com/docs/reference/engines/table-engines/special/external-data.md): a file in the same request that the server loads into a temporary table, which the query uses with `IN`.
* Load the values into a table first, or split the work into several smaller requests.

## Raise the limit on a self-managed server

`http_max_uri_size` is listed among the query settings, but the server applies it before it knows the user and the settings of the request. It always uses the value from the `default` settings profile that it loaded at startup. `SET http_max_uri_size = ...`, a value in another profile, and `http_max_uri_size` passed as a URL parameter are accepted and have no effect on this check.

To change the limit, set it in the `default` profile, for example in a file under `/etc/clickhouse-server/users.d/`, and restart the server:

```xml theme={null}
<clickhouse>
    <profiles>
        <default>
            <http_max_uri_size>4194304</http_max_uri_size>
        </default>
    </profiles>
</clickhouse>
```

Proxies and load balancers between the client and the server can have their own, lower limits for the length of a URL, so moving the data into the request body is the more reliable fix.

## Related pages

* [HTTP interface](https://clickhouse.com/docs/concepts/features/connect-to-clickhouse/protocols/http.md)
* [Queries with parameters over HTTP](https://clickhouse.com/docs/concepts/features/connect-to-clickhouse/protocols/http.md#cli-queries-with-parameters)
* [External data for query processing](https://clickhouse.com/docs/reference/engines/table-engines/special/external-data.md)
