Skip to main content
Every INSERT that goes through the asynchronous insert queue is recorded in system.asynchronous_insert_log with a status and, if it failed, the exception. This matters most with wait_for_async_insert = 0: the client receives a successful response as soon as the data is buffered, before it is parsed and written, so this table and the server log are the only places where the failure is reported.

Check whether asynchronous inserts fail

Two counters in system.events show the number of asynchronous INSERT queries and the number of failed ones since the server started. A counter that is still zero is not listed.
For the details, group the log by table and status:
Each row of the log is one INSERT query sent by a client. The status column has three values: Log entries are written with a delay of a few seconds. SYSTEM FLUSH LOGS writes them immediately.

Read the error of a failed insert

  • exception is the full error message.
  • query_id is the ID of the INSERT query that the client sent, which you can match with the logs of the client.
  • flush_query_id is the ID of the background query that wrote the batch. Use it to find the flush in system.query_log (WHERE query_id = '...'), which has the duration, the number of written rows and the profile events of the flush.
ClickHouse collects the inserts that have the same query text, settings and user into one batch and writes the batch as a whole. When the write fails, every insert of the batch gets the status FlushError with the same exception. Before you send the data again, check the target table: a write that fails in a materialized view has already stored its rows in the table itself. The following query shows how many inserts each failed flush took with it:

Typical causes

ParsingError: the data does not match the format named in the query or the types of the columns, for example a string in a numeric field or invalid JSON. Fix the producer; the rejected data is not kept anywhere on the server. FlushError: any error that is raised while the batch is written. Common ones:
  • TOO_MANY_PARTS: the table has too many active parts and rejects new inserts. See Resolving the “Too many parts” exception.
  • ACCESS_DENIED, with the message Not enough privileges. To execute this query, it's necessary to have the grant .... The INSERT grant on the target table is checked when the insert is received, so a client that lacks it gets the error immediately. Access is checked again when the batch is written, and that check also covers the materialized views attached to the table: if the definer of a materialized view lacks a grant on the table that the view reads from or writes to, the insert into the source table fails at flush time. The message names the user and the missing grant. Compare it with the output of SHOW GRANTS for that user and add the grant with GRANT. The same happens if a grant is revoked between the moment the insert is received and the flush.

Make the client see the error

With wait_for_async_insert = 1, which is the default, the INSERT query returns only after its batch is written, and a parsing or flush error is returned to the client, which can then retry or report it. If your clients use wait_for_async_insert = 0, they cannot detect these failures, and you have to monitor system.asynchronous_insert_log instead. The trade-offs of the two modes are described in the “Error handling” section of Asynchronous inserts.

Where the log is available

  • On a self-managed server the table exists if the server configuration has the asynchronous_insert_log section. The default config.xml includes it.
  • The log is local to each server. On a cluster, read it from all replicas with the clusterAllReplicas table function. In ClickHouse Cloud the cluster is named default: FROM clusterAllReplicas(default, system.asynchronous_insert_log). See System tables in ClickHouse Cloud.
  • Inserts that are still waiting in the queue are not in the log yet. They are listed in system.asynchronous_inserts.