sql_insert output batching #2096
-
Hi all, I'm curious on how the sql_insert output processor works behind the curtain when batching the messages. My current output is: sql_insert:
driver: postgres
dsn: "${DSN}"
table: production
columns:
[
foo,
bar,
]
args_mapping: |
root = [
this.foo,
this.bar
]
batching:
count: 100
byte_size: 0
period: 1m When flushing the batch, what's the generated query? Will it be n INSERT queries, or one single I'm asking this because I'm trying to debug some issue with the size of the batches I'm having. Basically I'm stressloading my service and benthos (or the underlying pg engine) breaks with the following error:
My original insert statement doesn't even have 8 arguments (it actually has 10) and nothing gets processed beyond this error, that will be continuously printed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @antipopp 👋
It will be the latter unless the driver supports transactions (only Here's a working demo:
Now create this yaml file and run Benthos with it: input:
generate:
count: 10000
interval: 0s
mapping: |
root.foo = 1
root.bar = 2
output:
sql_insert:
driver: postgres
dsn: postgres://testuser:testpass@localhost:5432/testdb?sslmode=disable
table: production
columns:
- foo
- bar
args_mapping: |
root = [
this.foo,
this.bar
]
batching:
count: 10000
period: 10s
shutdown_timeout: 3s You should get the following:
Note: You can end up bumping into a message like "pq: got parameters but PostgreSQL only supports 65535 parameters" if your batches end up too big. More details about it here: https://klotzandrew.com/blog/postgres-passing-65535-parameter-limit and I guess it's enforced on the server side as well here. |
Beta Was this translation helpful? Give feedback.
Hey @antipopp 👋
It will be the latter unless the driver supports transactions (only
clickhouse
andoracle
for now). In the case ofpostgres
, it should send a singleINSERT
query along with a list of rows of values, each row having the same length as thecolumns
list in the config.Here's a working demo:
Now create…