# Start two writable nodes

> Seed the subscriber once, subscribe in reverse and prove that writes arrive in both directions.

---

LLMS index: [llms.txt](/llms.txt)

---

## Prepare the instances {#prepare}

Start with two fresh Mimus 19.0.1 clusters on one host, A on loopback port 5541 and B on 5542. Install the paired Spock extension and output plugin in both prefixes. Configure the following on **both**, merging any existing required preloads. Each cluster needs its own data directory and port. Restart both and create a database named `lab` in each. For separate hosts replace the loopback addresses with peer-reachable addresses.

```ini
shared_preload_libraries = 'spock'
wal_level = logical
track_commit_timestamp = on
output_plugin_libraries = 'pgoutput,spock_output'
max_worker_processes = 24
max_replication_slots = 12
max_wal_senders = 12
spock.conflict_resolution = 'last_update_wins'
spock.save_resolutions = on
spock.enable_ddl_replication = off
```

Configure `pg_hba.conf` and service-account libpq credentials so both servers can connect to both `lab` databases using the named administrative role. The example uses `postgres`. Test each DSN from the database service account, including reconnect after restart. Connect `psql` to `lab` separately on A and B. Install the extension on both, then register each node with its own address.

```sql
-- A and B
CREATE EXTENSION spock;

-- A
SELECT spock.node_create('node_a',
    'host=127.0.0.1 port=5541 dbname=lab user=postgres');
-- B
SELECT spock.node_create('node_b',
    'host=127.0.0.1 port=5542 dbname=lab user=postgres');
```

## Define the tables and copy the seed {#subscribe}

On **both** nodes create the same empty table, column options and replication-set membership:

```sql
CREATE TABLE public.accounts (
    id integer PRIMARY KEY,
    label text,
    balance integer NOT NULL
);
ALTER TABLE public.accounts ALTER COLUMN balance
    SET (log_old_value = true, delta_apply_function = spock.delta_apply);
SELECT spock.repset_add_table('default', 'public.accounts');
```

Seed A only. On B, subscribe to A and confirm the seed arrived. Then subscribe A to B without copying data a second time. The empty origin list limits forwarding to locally originated changes.

```sql
-- A
INSERT INTO public.accounts VALUES (1, 'seed', 100);

-- B
SELECT spock.sub_create('from_a',
    'host=127.0.0.1 port=5541 dbname=lab user=postgres',
    replication_sets := ARRAY['default'], synchronize_structure := false,
    synchronize_data := true, forward_origins := '{}');
SELECT spock.sub_wait_for_sync('from_a');
SELECT * FROM public.accounts WHERE id = 1;

-- A
SELECT spock.sub_create('from_b',
    'host=127.0.0.1 port=5542 dbname=lab user=postgres',
    replication_sets := ARRAY['default'], synchronize_structure := false,
    synchronize_data := false, forward_origins := '{}');
SELECT spock.sub_wait_for_sync('from_b');
```

## Check both writers {#write}

```sql
-- A
INSERT INTO public.accounts VALUES (2, 'from_a', 50);
-- B
SELECT * FROM public.accounts WHERE id = 2;
-- B, after seeing (2, from_a, 50)
UPDATE public.accounts SET label = 'from_b', balance = balance + 2 WHERE id = 2;
-- A
SELECT * FROM public.accounts WHERE id = 2;
```

On each read, poll until the row arrives before moving to the next step. A should finally return `(2,from_b,52)`. Check `SELECT subscription_name, status FROM spock.sub_show_status()` on both nodes. Both should say `replicating`. A local COMMIT may return before the peer sees the row. [Operate the pair](/docs/spock/operations/)

---

Backlinks:

- [pgEdge · Spock](/docs/spock/)
- [Conflicts, monitoring and catch-up](/docs/spock/operations/)
