Duplicated records when row is updated between transactions
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start in src/postgres_scanner.cpp around lines 92-93 and inspect why pg_export_snapshot and SET TRANSACTION SNAPSHOT are not appearing in the logged queries. Reproduce with pg_debug_show_queries=true, pg_connection_limit=4, and concurrent PostgreSQL transactions if possible. Done means the snapshot setup occurs as expected and concurrent row updates no longer produce duplicated rows.
Written by the indexing model from the issue text.
Description
What happens?
We started seeing duplicated rows when extracting data from PostgresDB and noticed that it happens when the row is updated/created when different transaction starts, which seems to be similar to what was reported back in https://github.com/duckdb/duckdb-postgres/issues/163.
I checked our logs with the flag pg_debug_show_queries=true after I saw this change and validated all connections are using BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY as expected.
However, I noticed SET TRANSACTION SNAPSHOT 'some-snapshot-id' is never called and neither the expected query before that: SELECT pg_is_in_recovery(), pg_export_snapshot(), (select count(*) from pg_stat_wal_receiver).
This query works when executed directly in our database and provides the following result:
SELECT pg_is_in_recovery(), pg_export_snapshot(), (select count(*) from pg_stat_wal_receiver);
pg_is_in_recovery | pg_export_snapshot | count
-------------------+---------------------+-------
f | 0000102C-00400680-1 | 0
I suspect the code is not reaching the part where it gets pg_export_snapshot for some reason and therefore affecting the results of the reading operation even when the isolation level is correct. Our workflow has pg_connection_limit=4.
To Reproduce
A bit hard to reproduce since the update operation of a row needs to happen between the start of concurrent transactions (we see this issue happening a couple of times per week), but we're happy to test some code in our workflows.
OS:
Linux
PostgreSQL Version:
17.5
DuckDB Version:
1.4.1
DuckDB Client:
Python
Full Name:
Rina Sakurai
Affiliation:
Mentimeter
Have you tried this on the latest main branch?
- I agree
Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?
- I agree
- Dominant language
- C++
- Stars
- 375
- Forks
- 113
- Avg merge
- 6h 42m
- Merged PRs (30d)
- 30
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from duckdb/duckdb-postgres
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
duckdb/duckdb-postgres#623 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
duckdb/duckdb-postgres#618 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
duckdb/duckdb-postgres#594 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
duckdb/duckdb-postgres#575 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
duckdb/duckdb-postgres#564 · 1 comment ·
Maintainers usually reply within 1 day
All issues in duckdb/duckdb-postgres
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
area: ui bug good first issue P2: medium value: medium
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
patrick-hudson/put.gd-desktop#366 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Niko1221/Strata#3673 · 2 comments ·
Maintainers usually reply within 3 days