How-to guide

Turn off state-machine change notices

Source 080_snapshot_draft_change_notify_switch.sql, ChangeFeedStartupValidator.cs

On Postgres every write to trax.snapshot_draft sends a change notice, and every transaction that sends one takes a lock shared by the whole cluster through its commit, so concurrent instance writes commit one at a time. Migration 080 lets the database stop sending them; hosts then hear changes by polling. Why the switch exists and what each host checks at startup is in Schema migrations.

The order matters. A host still listening never hears a write the database no longer announces, and a host on Notify refuses to start once the database turns the notices off.

1. Move every host to polling

Set ChangeFeed to Poll in each host's AddStateMachines options, and deploy every host that serves state machines from this database:

using Trax.Effect.Data.Postgres.Extensions;
using Trax.Effect.Extensions;
using Trax.StateMachine.Persistence;
using Trax.Mediator.Extensions;
 
services.AddTrax(trax =>
    trax.AddEffects(effects => effects.UsePostgres(connectionString))
        .AddStateMachines(options => options.ChangeFeed = StateMachineChangeFeed.Poll, assemblies)
        .AddMediator(assemblies)
);

A polling host whose database still sends notices starts and logs a warning saying so. That is expected until step 2.

2. Turn the notices off for the database

Once no host is on Notify, run:

ALTER DATABASE <name> SET trax.snapshot_notify = 'off';

It applies to new sessions, so connections already open keep sending notices until the pool replaces them. Use only this database-level setting: a role setting, a connection string's Options=-c trax.snapshot_notify=off or SET LOCAL silences some writers only, and is not supported while any host listens.

3. Check the warning is gone

Restart one host. It no longer logs that the database still sends a change notice for every write.

Turning the notices back on

Reset the setting first, then move hosts back to Notify:

ALTER DATABASE <name> RESET trax.snapshot_notify;

Also RESET it for any role or connection string that sets it. A Notify host started while the notices are off refuses to start, and one that was already running when they were turned off stays silent until it restarts.