# Change SYNC to ASYNC percona patroni replication with callback or others

**URL:** <https://forums.percona.com/t/change-sync-to-async-percona-patroni-replication-with-callback-or-others/20426>\
**Category:** Percona Distribution for PostgreSQL\
**Tags:** percona\
**Created:** [March 5, 2023, 1:26pm UTC](https://forums.percona.com/t/change-sync-to-async-percona-patroni-replication-with-callback-or-others/20426 "2023-03-05T13:26:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MRizwanShaukat](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@MRizwanShaukat](https://forums.percona.com/u/MRizwanShaukat)\
**Post date:** [March 5, 2023, 1:26pm UTC](https://forums.percona.com/t/change-sync-to-async-percona-patroni-replication-with-callback-or-others/20426/1 "2023-03-05T13:26:06Z")

</div>

hi, we have 2 patroni nodes and 3 etcd nodes, currently, we configured SYNC replication between replication node SYNCHRONOUS\_COMMIT=on and synchornous\_standby\_name=‘node2’, we intended to change replication to ASYNC if replica goes down with callback or some other parameters, need help, how we can achieve this requirement

Percona 14.6  
RHEL 8

---

<div class="post-metadata">

**Author:** ![Charly\_Batista](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/charly_batista/32/1242_2.png) [@Charly\_Batista](https://forums.percona.com/u/Charly_Batista)\
**Post date:** [March 9, 2023, 4:00am UTC](https://forums.percona.com/t/change-sync-to-async-percona-patroni-replication-with-callback-or-others/20426/2 "2023-03-09T04:00:49Z")

</div>

Hello @MRizwanShaukat you can use the parameters “synchronous\_mode”, “synchronous\_commit” “synchronous\_standby\_names”, and patroni will take care of the standby names. For example:

```auto
bootstrap:
    dcs:
        ttl: 30
        maximum_lag_on_failover: 1048576
        synchronous_mode: "on"
        postgresql:
            use_pg_rewind: true
            use_slots: true
            parameters:
                wal_level: replica
                hot_standby: "on"
                synchronous_commit: "on"
                synchronous_standby_names: "*"

```

Note that in the below example I’m using **synchronous\_standby\_names: “\*”** this way Patroni will take care of the standby name. In this example I have a setup with 3 nodes (node1, node2, node3) and node1 is the primary. If I check the param I get:

```auto
test=> show synchronous_standby_names;
-[RECORD 1]-------------+------------
synchronous_standby_names | "node2"
(1 row)

root@lab-node2:~# patronictl -c /percona/config/patroni.yml list
+ Cluster: cluster_1 (7208383656948843317) --------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-----------+-------------+--------------+---------+----+-----------+
| node1 | 10.0.100.13 | Leader | running | 1 | |
| node2 | 10.0.100.11 | Sync Standby | running | 1 | 0 |
| node3 | 10.0.100.6 | Replica | running | 1 | 0 |
+-----------+-------------+--------------+---------+----+-----------+

```

If I cause node2 to crash then I get:

```auto
test=> show synchronous_standby_names;
 synchronous_standby_names 
---------------------------
 "node3"
(1 row)

root@lab-node2:~# patronictl -c /percona/config/patroni.yml list
+ Cluster: cluster_1 (7208383656948843317) --------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-----------+-------------+--------------+---------+----+-----------+
| node1 | 10.0.100.13 | Leader | running | 1 | |
| node3 | 10.0.100.6 | Sync Standby | running | 1 | 0 |
+-----------+-------------+--------------+---------+----+-----------+

```

As we can see, Patroni took care of the Sync Standby.

Now, in the case I lose all my nodes (I’m using more ETCD servers than PG nodes in this example to be able to have only one PG node running as leader) Patroni will empty the config:

```auto
test=> show synchronous_standby_names;
 synchronous_standby_names 
---------------------------
 
(1 row)

test=> select pg_is_in_recovery();
 pg_is_in_recovery 
-------------------
 f
(1 row)

test=> insert into t1 select from generate_series(1,1000);
INSERT 0 1000

root@lab-node2:~# patronictl -c /percona/config/patroni.yml list
+ Cluster: cluster_1 (7208383656948843317) --+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-----------+-------------+--------+---------+----+-----------+
| node1 | 10.0.100.13 | Leader | running | 1 | |
+-----------+-------------+--------+---------+----+-----------+

```

My primary is still running and responsive as if it wasn’t using sync replicas.

Note that **I am NOT using “synchronous\_mode\_strict”** because this parameter prevents Patroni from switching off the synchronous replication on the primary when no synchronous standby candidates are available.

You may find more information in Patroni’s documentation here[1].

Hope this helps.

_Charly_

[1] [Replication modes — Patroni 3.0.1 documentation](https://patroni.readthedocs.io/en/latest/replication_modes.html)

---

<div class="post-metadata">

**Author:** ![MRizwanShaukat](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@MRizwanShaukat](https://forums.percona.com/u/MRizwanShaukat)\
**Post date:** [March 18, 2023, 8:41pm UTC](https://forums.percona.com/t/change-sync-to-async-percona-patroni-replication-with-callback-or-others/20426/3 "2023-03-18T20:41:57Z")

</div>

Thanks for reply, @Charly_Batista it’s working as expected 🙂

---

<div class="post-metadata">

**Author:** ![MRizwanShaukat](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@MRizwanShaukat](https://forums.percona.com/u/MRizwanShaukat)\
**Post date:** [March 20, 2023, 3:55pm UTC](https://forums.percona.com/t/change-sync-to-async-percona-patroni-replication-with-callback-or-others/20426/4 "2023-03-20T15:55:57Z")

</div>

hi, we configured with “\*” it’s not able to get synchronous\_standby\_names automatically, we need to specify standby name in this parameter, then only it showed SYCN Standby … on disaster, it’s not changing standby parameter automatically, any idea pls

---

<div class="post-metadata">

**Author:** ![Charly\_Batista](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/charly_batista/32/1242_2.png) [@Charly\_Batista](https://forums.percona.com/u/Charly_Batista)\
**Post date:** [March 20, 2023, 10:37pm UTC](https://forums.percona.com/t/change-sync-to-async-percona-patroni-replication-with-callback-or-others/20426/5 "2023-03-20T22:37:41Z")

</div>

Hi,

Can you please share your configuration? You can get it using the below command:

`patronictl -c </path/to/patroni.yml> edit-config`

---

<div class="post-metadata">

**Author:** ![MRizwanShaukat](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@MRizwanShaukat](https://forums.percona.com/u/MRizwanShaukat)\
**Post date:** [March 22, 2023, 11:51am UTC](https://forums.percona.com/t/change-sync-to-async-percona-patroni-replication-with-callback-or-others/20426/6 "2023-03-22T11:51:55Z")

</div>

We specify these parameters on all nodes, it’s not changing status to “Sync Standby” automatically, even synchronous\_standby\_names didn’t pick node name automatically e.g. node 2 or node 3, on node 2 failure also, it’s not changing value.

loop\_wait: 10  
master\_start\_timeout: 300  
maximum\_lag\_on\_failover: 1048576  
postgresql:  
parameters:  
hot\_standby: ‘on’  
max\_replication\_slots: 10  
max\_wal\_senders: 10  
synchronous\_commit: ‘on’  
synchronous\_standby\_names: ‘\*’  
wal\_keep\_segments: 8  
wal\_level: replica  
use\_pg\_rewind: true  
use\_slots: true  
retry\_timeout: 10  
slots:  
percona\_3nodes\_replication\_slot:  
type: physical  
synchronous\_mode: ‘on’  
ttl: 30
