Clickhouse Exception : Memory limit (total) exceeded: 28.13 GiB (attempt to allocate chunk of 4543835 bytes)

I have created a table in with following query in clickhouse databse:

CREATE TABLE events (name String, track_date Date, id UInt64, con_type String, network String) ENGINE = MergeTree() PRIMARY KEY id ORDER BY id;
  1. I am getting data from kafka consumer and parse the JSON Array to build a query
  2. Trying to execute insert query from java application in every 2 seconds given below:
    INSERT INTO events(name, track_date , id, con_type , network ) values 
    (ABC,'2021-05-05',111,'android','wxy') , (DEF,'2021-05-05',112,'ios','ewr') , (HJK,'2021-05-05',111,'android','xyz');
    
  • Data size might be change as per json array length, may be bigger insert query.

After running 4 days of application am getting Exception Like:

ru.yandex.clickhouse.except.ClickHouseException: ClickHouse exception, code: 241, host: localhost, port: 8123; Code: 241, e.displayText() = DB::Exception: Memory limit (total) exceeded: would use 28.13 GiB (attempt to allocate chunk of 4543835 bytes), maximum: 28.13 GiB (version 20.8.3.18)

at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:58) at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:28) at ru.yandex.clickhouse.ClickHouseStatementImpl.checkForErrorAndThrow(ClickHouseStatementImpl.java:875) at ru.yandex.clickhouse.ClickHouseStatementImpl.getInputStream(ClickHouseStatementImpl.java:616) at ru.yandex.clickhouse.ClickHouseStatementImpl.executeUpdate(ClickHouseStatementImpl.java:215) at ru.yandex.clickhouse.ClickHousePreparedStatementImpl.executeUpdate(ClickHousePreparedStatementImpl.java:130) at com.way2news.util.DataAppender.pushClickHouse(DataAppender.java:82) at com.way2news.util.KConsumer.run(KConsumer.java:44) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

Caused by: java.lang.Throwable: Code: 241, e.displayText() = DB::Exception: Memory limit (total) exceeded: would use 28.13 GiB (attempt to allocate chunk of 4543835 bytes), maximum: 28.13 GiB (version 20.8.3.18)

at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:53) ... 14 more

How to resolve this issue.

Thanks,
Bimal.