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 insystem.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.
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
exceptionis the full error message.query_idis the ID of theINSERTquery that the client sent, which you can match with the logs of the client.flush_query_idis the ID of the background query that wrote the batch. Use it to find the flush insystem.query_log(WHERE query_id = '...'), which has the duration, the number of written rows and the profile events of the flush.
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 messageNot enough privileges. To execute this query, it's necessary to have the grant .... TheINSERTgrant 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 ofSHOW GRANTSfor that user and add the grant withGRANT. The same happens if a grant is revoked between the moment the insert is received and the flush.
Make the client see the error
Withwait_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_logsection. The defaultconfig.xmlincludes it. - The log is local to each server. On a cluster, read it from all replicas with the
clusterAllReplicastable function. In ClickHouse Cloud the cluster is nameddefault: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.