Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of inital snapshot events in Debezium

In our application we need to publish events from the certain postgresql table into Kafka, so we decided to use Debezium but ran into the following problem: during initial snapshot messages show up in Kafka in an unexpected (from our point of view) order. Order of events is crucial to our application, in fact they must be orderd by the integer primary key of the table. AFAIK inital snapshot is just a SELECT from the table without an ORDER BY. So is there a way or workaround to make Debezuim postgresql connector extract events in a certain order?

Thanks in advance!

like image 270
mitix Avatar asked Nov 02 '25 15:11

mitix


2 Answers

Check out the snapshot.select.statement.overrides property in the connector docs. It lets you customize the SELECT statement used for specific tables, so you can append the required ORDER BY clause.

like image 198
Gunnar Avatar answered Nov 05 '25 15:11

Gunnar


There is no guarantee that the order of the inserts in the transaction log is in the same order as the automatically generated primary keys. With high concurrency, a different order would be quite normal.

If the transactions are short, the order should not be too mixed up.

Anyway, there is nothing you can do about this on the PostgreSQL side.

like image 45
Laurenz Albe Avatar answered Nov 05 '25 15:11

Laurenz Albe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!