Hi @Francois ,
This is still under discussion. There is some overlap between a notification feature such as this, and our future materialised views feature.
I’m hoping we can unblock you by making polling a little easier, essentially giving you a naive CDC. Thanks to @javier for the following workflow.
We have an undocumented function, wal_transactions('table_name')
. This function provides a breakdown of the latest database transactions. This includes some key fields that may be useful to you.
- sequencerTxn
- timestamp
- walId
- segmentId
- segmentTxn
- structureVersion
- minTimestamp
- maxTimestamp
- rowCount
- alterCommandType
By default, the minTimestamp
, maxTimestamp
, and rowCount
fields may be null. To correct this, you can set the following config:
cairo.default.sequencer.part.txn.count=10000
This sets how many transactions are retained in that table, before it rolls over. When the number exceeds 10k, the table will be truncated. You can adjust this number as needed.
Your application can then read this table, and use the metadata to pull new rows of interest from the database.
Since only minTimestamp
, maxTimestamp
and rowCount
are provided, it may not be clear which rows are near or updated. This is especially true for O3 commits.
One workaround for this is to ad an auditing timestamp i.e created_at
or similar to your table. This can be set on the application side by sending the current timestamp, or using now()
as part of a Postgres INSERT statement.
When pulling new rows, you can then pull the range defined by the min and max timestamps, and then filter them by this audit timestamp.
If you are willing to try this as a workaround, please let us know how you get on and if there’s friction that we could improve, prior to a proper notification system.
If this is unworkable, then there are third-party options to handle notification of clients on new database inserts.
Thanks!