Andy Carter
08/15/2024, 8:12 AM(duplicate key value violates unique constraint)
, even though the key it was reporting did not actually exist in the db.
I discovered this possibly related issue with psycopg2. https://github.com/psycopg/psycopg2/issues/1036 In summary, if there are parallel statements executing CREATE TABLE IF NOT EXISTS
then it can raise this error.
I don't know the internals too well but is it possible to cause the db to execute`create table if not exists` messages in parallel when running meltano (from within dagster if that's relevant)? That might explain my issue.
Edit: prior thread: https://meltano.slack.com/archives/C069CQNHDNF/p1722527619910199 Going to give meltanolabs
variant a go...Charles Feduke
08/15/2024, 4:02 PMcreate table if not exists
are ran in parallel - I assume you mean target-postgres, since that is where create table if not exists
are executing. This would be an extremely common problem for anyone using target-postgres if the issue was with parallelism when creating tables [of different names]. But in your original thread your unique key violation is coming from a table you’ve defined, not any of the PGSQL internal structure tables used for user-defined tables.Edgar RamĂrez (Arch.dev)
08/15/2024, 5:44 PMAndy Carter
08/16/2024, 8:10 AMmedia_insights
which does already exist. I only have a surface understanding of postgres, afraid I don't really understand your last sentence and the implicationsCharles Feduke
08/16/2024, 1:14 PMcreate table if not exists
and the table in question doesn’t technically exist in the PostgreSQL system tables because its still being created, so it also tries to create the table and its associated objects and thus the result is a unique key violation because some of the objects do exist (but in this scenario its from the PostgreSQL system tables which store the definitions for all of the other tables in the database).
It looks like Edgar has successfully identified your problem though which is good.Andy Carter
08/16/2024, 1:29 PMAndy Carter
08/20/2024, 12:20 PMmetadata:
, overriding the key definition in the tap repo. I wonder if that was affecting it too. I've just decided to edit my fork to include those keys and add the missing fields via post_process
. That with a full delete of the target schema in postgres got me back up and running.