Hello everyone! :wave::skin-tone-2: We're getting ...
# troubleshooting
f
Hello everyone! πŸ‘‹πŸ» We're getting deadlock error a couple of times every day on one of our PostgreSQL sinks and we're worried that we are losing events this way. Any advices are welcomed πŸ™
Stacktrace:
Copy code
05/09/2023 04:31:33.166 ERROR [jdbc-upsert-output-format-thread-1] [none] [lc.datahub.flink] [none] org.apache.flink.connector.jdbc.internal.JdbcOutputFormat [JdbcOutputFormat:223] JDBC executeBatch error, retry times = 0 
java.sql.BatchUpdateException: Batch entry 10 INSERT INTO ... was aborted: ERROR: deadlock detected
  Detail: Process 26315 waits for ShareLock on transaction 1783678; blocked by process 26325.
Process 26325 waits for ShareLock on transaction 1783677; blocked by process 26315.
  Hint: See server log for query details.
  Where: while inserting index tuple (185399,38) in relation "fact_file_translation_status"  Call getNextException to see other errors in the batch.
	at org.postgresql.jdbc.BatchResultHandler.handleCompletion(BatchResultHandler.java:186) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:570) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.postgresql.jdbc.PgStatement.internalExecuteBatch(PgStatement.java:887) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:910) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1649) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.apache.flink.connector.jdbc.internal.executor.SimpleBatchStatementExecutor.executeBatch(SimpleBatchStatementExecutor.java:73) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.apache.flink.connector.jdbc.internal.JdbcOutputFormat.attemptFlush(JdbcOutputFormat.java:249) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.apache.flink.connector.jdbc.internal.TableJdbcUpsertOutputFormat.attemptFlush(TableJdbcUpsertOutputFormat.java:131) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.apache.flink.connector.jdbc.internal.JdbcOutputFormat.flush(JdbcOutputFormat.java:219) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.apache.flink.connector.jdbc.internal.JdbcOutputFormat.lambda$open$0(JdbcOutputFormat.java:158) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: org.postgresql.util.PSQLException: ERROR: deadlock detected
  Detail: Process 26315 waits for ShareLock on transaction 1783678; blocked by process 26325.
Process 26325 waits for ShareLock on transaction 1783677; blocked by process 26315.
  Hint: See server log for query details.
  Where: while inserting index tuple (185399,38) in relation "fact_file_translation_status"
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:559) ~[blob_p-a7e6b16e05b4154b9650955f39734cc3b65f9b01-8762d38095b25c39321ed0bfae4dbffb:?]
	... 14 more
We fixed it by lowering the parallelism