Skip to main content
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, 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:
Find it in the server log file, or in system.text_log if this table is enabled:
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 option places them in the request body, and the C# client can put the statement of an insert into the URL with InsertQueryPlacement.Url.
A single URL parameter has its own limit as well: a value longer than 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:
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, 262144 bytes by default, which you can raise for a request with a URL parameter.
  • Send the list as external data: 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:
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.