I have two PostgreSQL servers running, one publishing all tables and the other subscribing to all via logical replication. I'm currently testing a failover solution, and it seems if I remove the subscribers on the secondary and redirect the application to it, insertions fail as the primary key for each table is trying to start at one.
For example, I see a lot of stuff like this:
Oct 25 15:48:10 icinga-master1 icinga2[29819]: Error "ERROR: duplicate key value violates unique constraint "pk_customvariable_id"
DETAIL: Key (customvariable_id)=(1) already exists.
" when executing query "INSERT INTO icinga_customvariables (config_type, instance_id, is_json, object_id, varname, varvalue) VALUES (E'1', 1, E'0', 2677, E'gfl_bmname', E'tomcat1_filenotfound')"
When trying to manually insert that, I get the same error in postgres. I can, however, import the pg_dump from the secondary and everything is fine. Is there a setting I'm missing here? I've also tried throwing in a recovery.conf and using pg_ctl to promote, but that seems to stop the subscriber from working and resulted in the same issue. Maybe I'm not subscribing to a system table I should be?
I have these wal settings in my postgresql.conf in each:
wal_level = logical
hot_standby = on
hot_standby_feedback = on
max_logical_replication_workers = 8
max_sync_workers_per_subscription = 8
On primary:
List of publications
Name | Owner | All tables | Inserts | Updates | Deletes
------------+----------+------------+---------+---------+---------
icinga_pub | postgres | t | t | t | t
On secondary (I do set that disabled when testing this):
List of subscriptions
Name | Owner | Enabled | Publication
------------+----------+---------+--------------
icinga_sub | postgres | t | {icinga_pub}
I've dropped the databases and started over on the secondary while troubleshooting to keep things clean. Any help is appreciated.