2

I'm having issues replicating data between 2 Postgres servers using SymmetricDS (open source version). Here's the relevant informations to understand my problem:

I have deployed 3 servers with Vagrant:

  • symmetricds.local [192.168.44.9]
  • postgres01.local [192.168.44.10]
  • postgres02.local [192.168.44.11]

In the symmetricds.local server I install SymmetricDS as a service. Int the postgres##.local servers I install postgres 11 and load Sakila data (sample data).

I then create the following configuration files in the symmetricds.local server:

cat <<EOF >>/opt/symmetric-server-3.12.10/engines/postgres01.properties
engine.name=postgres01
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://192.168.44.10:5432/postgres?stringtype=unspecified
db.user=postgres
db.password=postgres
registration.url=
sync.url=http://192.168.44.9:31415/sync/postgres01
group.id=primary
external.id=postgres01
auto.registration=true
initial.load.create.first=true
EOF

cat <<EOF >>/opt/symmetric-server-3.12.10/engines/postgres02.properties
engine.name=postgres02
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://192.168.44.11:5432/postgres?stringtype=unspecified
db.user=postgres
db.password=postgres
registration.url=http://192.168.44.9:31415/sync/postgres01
sync.url=http://192.168.44.9:31415/sync/postgres02
group.id=primary
external.id=postgres02
EOF

After that I start the SymmetricDS service:

sudo /opt/symmetric-server-3.12.10/bin/sym_service start

At that point all sym_ tables are created in both Postgres servers.

I add some data in postgres01.local server for replication between the two Postgres servers to work:

INSERT INTO sym_node_group_link (source_node_group_id,target_node_group_id,data_event_action)
VALUES ('primary','primary','P');

INSERT INTO sym_trigger (trigger_id, source_schema_name, source_table_name, channel_id, sync_on_update, sync_on_insert, sync_on_delete, sync_on_update_condition, sync_on_insert_condition, sync_on_delete_condition, last_update_time, create_time)
VALUES ('public.all', 'public', '*', 'default', 1, 1, 1, '1=1', '1=1', '1=1', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

INSERT INTO sym_router (router_id,source_node_group_id,target_node_group_id,router_type,router_expression,sync_on_update,sync_on_insert,sync_on_delete,use_source_catalog_schema,create_time,last_update_by,last_update_time)
VALUES ('primary_2_primary', 'primary', 'primary', 'default', NULL, 1, 1, 1, 0, CURRENT_TIMESTAMP, 'console', CURRENT_TIMESTAMP);

INSERT INTO sym_trigger_router (trigger_id, router_id, enabled, initial_load_order, create_time, last_update_time)
VALUES ('public.all', 'primary_2_primary', 1, 10, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

Finally, I run this in the symmetricds.local server to allow registration:

sudo /opt/symmetric-server-3.12.10/bin/symadmin -e postgres01 open-registration primary postgres02

After a few minutes, triggers are created and data is shared between sym_ tables. But user data (Sakila tables) are not replicated.

I try to force table reload with:

INSERT INTO sym_table_reload_request (source_node_id, target_node_id, trigger_id, router_id, create_time, last_update_time) VALUES ('postgres01', 'postgres02', 'ALL', 'ALL', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

But then I get this error in SymmetricDS logs:

2021-07-01 15:03:19,097 ERROR [postgres01] [InitialLoadService] [postgres01-job-11] Error while queuing initial loads StackTraceKey.init [SymmetricException:46596748] org.jumpmind.symmetric.SymmetricException: Unable to issue an update for sym_node_security.  Check the sym_trigger_hist for sym_node_security.
    at org.jumpmind.symmetric.service.impl.DataService.insertNodeSecurityUpdate(DataService.java:2230)
    at org.jumpmind.symmetric.service.impl.DataService.insertSqlEventsPriorToReload(DataService.java:1227)
    at org.jumpmind.symmetric.service.impl.DataService.insertReloadEvents(DataService.java:1006)
    at org.jumpmind.symmetric.service.impl.InitialLoadService.processTableRequestLoads(InitialLoadService.java:282)
    at org.jumpmind.symmetric.service.impl.InitialLoadService.queueLoads(InitialLoadService.java:98)
    at org.jumpmind.symmetric.job.InitialLoadJob.doJob(InitialLoadJob.java:43)
    at org.jumpmind.symmetric.job.AbstractJob.invoke(AbstractJob.java:227)
    at org.jumpmind.symmetric.job.AbstractJob.run(AbstractJob.java:298)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

2021-07-01 15:03:29,118 INFO [postgres01] [InitialLoadService] [postgres01-job-14] Found 1 table reload requests to process.
2021-07-01 15:03:29,131 INFO [postgres01] [InitialLoadService] [postgres01-job-14] Cancelling load 2 for node postgres02
2021-07-01 15:03:29,134 INFO [postgres01] [InitialLoadService] [postgres01-job-14] Marked 1 load requests as OK for node postgres02
2021-07-01 15:03:29,136 INFO [postgres01] [InitialLoadService] [postgres01-job-14] Marked 0 extract requests as OK for node postgres02
2021-07-01 15:03:29,137 INFO [postgres01] [InitialLoadService] [postgres01-job-14] Marked 0 batches as OK for node postgres02
2021-07-01 15:03:29,147 INFO [postgres01] [DataService] [postgres01-job-14] Queueing up an initial load to node postgres02
2021-07-01 15:03:29,175 ERROR [postgres01] [InitialLoadService] [postgres01-job-14] Error while queuing initial loads StackTraceKey [SymmetricException:46596748]

Still nothing gets replicated and the sym_trigger_hist table is empty on postgres01 but full with all tables on postgres02.

Cloud you help me understanding the problem with my configuration?

blakelead
  • 1,780
  • 2
  • 17
  • 28
  • If all tables an on postgresql02 then maybe it should be passed as source? Besides that here - https://sourceforge.net/p/symmetricds/discussion/739236/thread/70a6e351a5/ - are two more configuration parameters mentioned... Sorry - I have just basic knowledge about Symmetric DS – Michał Zaborowski Jul 07 '21 at 13:50

2 Answers2

4

You should run the symadmin sync-triggers command on postgres01 to build the triggers. Check the logs to see if there are any errors. The sym_trigger_hist table should be populated in postgres01 if the triggers are successfully created.

The command to execute to build the triggers is:

symadmin sync-triggers -e postgres01
buddemat
  • 4,552
  • 14
  • 29
  • 49
  • This command does work, but defeat the purpose of automating replication process. I'll try again without it but if I still cannot make it work I'll accept your answer. – blakelead Jul 09 '21 at 07:39
  • To be sure, do you think this is the best way to do it even if symmetricds is run as a systemd service? – blakelead Jul 09 '21 at 14:50
3

The "sync triggers" process should run automatically right after registration, and it puts an entry in sym_trigger_hist for each SYM table that is replicated. Those entries are needed for operations like initial loads. If sym_trigger_hist is empty, then something went wrong running "sync triggers". When successful, the logging will look like this:

2021-07-07 13:21:42,799 INFO [postgres01] [RegistrationService] [qtp2060037930-34] Completed registration of node primary:postgres02
2021-07-07 13:21:46,598 INFO [postgres02] [TriggerRouterService] [postgres02-job-2] Synchronizing triggers
2021-07-07 13:21:48,668 INFO [postgres02] [PostgreSqlSymmetricDialect] [postgres02-sync-triggers-1] Creating SYM_ON_I_FOR_SYM_ND_SCRTY_CLNT trigger for SYM_NODE_SECURITY
2021-07-07 13:21:48,679 INFO [postgres02] [PostgreSqlSymmetricDialect] [postgres02-sync-triggers-1] Creating SYM_ON_U_FOR_SYM_ND_SCRTY_CLNT trigger for SYM_NODE_SECURITY
2021-07-07 13:21:48,690 INFO [postgres02] [PostgreSqlSymmetricDialect] [postgres02-sync-triggers-1] Creating SYM_ON_D_FOR_SYM_ND_SCRTY_CLNT trigger for SYM_NODE_SECURITY
...
2021-07-07 13:21:48,701 INFO [postgres02] [TriggerRouterService] [postgres02-job-2] Done synchronizing triggers
2021-07-07 13:21:49,439 INFO [postgres02] [RegistrationService] [postgres02-job-2] Successfully registered node [id=postgres02]

You should be able to go back in the logs and see what error it encountered during registration. You might be able to fix it by restarting SymmetricDS, which causes it to run "sync triggers" again.

Eric Long
  • 926
  • 4
  • 3
  • I agree sync trigger shoud be automatic, but unfortunately restarting symmetricds doesn't resolve my issue – blakelead Jul 09 '21 at 07:35