'postgres database logical replication: ERROR: duplicate key value violates unique constraint "users_unique_key"

i am trying to set up master/slave postgres replication. i have 2 servers, master with populated data ,i did complete backup of the database i want to replicate and restored it in slave, then i configured the replication with (copy_data=false) . when insert a new row in any table, it works fine, but when i do update an existing row, i get the error:

022-03-16 22:29:08.708 UTC [625449] ERROR:  duplicate key value violates unique constraint "users_unique_key"
2022-03-16 22:29:08.708 UTC [625449] DETAIL:  Key (userid, classid)=(4556, 4507) already exists.
2022-03-16 22:29:08.711 UTC [625285] LOG:  background worker "logical replication worker" (PID 625449) exited with exit code 1

The table has primary key and set to "not null". My question is , how do i setup logical replication, with UPDATE statement possible ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source