# How to purge binlogs on replica nodes?

**URL:** <https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120>\
**Category:** Percona XtraDB Cluster 8.x\
**Tags:** mysql\
**Created:** [June 26, 2023, 11:17am UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120 "2023-06-26T11:17:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slavisa\_Milojkovic](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/slavisa_milojkovic/32/7097_2.png) [@Slavisa\_Milojkovic](https://forums.percona.com/u/Slavisa_Milojkovic)\
**Post date:** [June 26, 2023, 11:17am UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120/1 "2023-06-26T11:17:04Z")

</div>

Hello, I have purged binlogs from pxc-0 node by querying `PURGE BINARY LOGS TO 'binlog.000180';` since they were getting bigger than 100Gb. It was successful on the first node, but the replicated binlogs remain on the other 2 Kubernetes nodes. It seems they won’t auto-remove from there too. How can I safely purge those also?

---

<div class="post-metadata">

**Author:** ![kedarpercona](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/kedarpercona/32/809_2.png) [@kedarpercona](https://forums.percona.com/u/kedarpercona)\
**Post date:** [June 26, 2023, 11:24am UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120/2 "2023-06-26T11:24:44Z")

</div>

Hello @Slavisa_Milojkovic ,

[PURGE BINARY LOGS](https://dev.mysql.com/doc/refman/8.0/en/purge-binary-logs.html) will not be written to binlogs and hence the effect will not be replicated.  
To automatically purge the binary logs, consider using [BINLOG\_EXPIRE\_LOGS\_SECONDS](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds) or [EXPIRE\_LOGS\_DAYS](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_expire_logs_days) (deprecated) configuration option.

Thanks,  
K

---

<div class="post-metadata">

**Author:** ![Slavisa\_Milojkovic](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/slavisa_milojkovic/32/7097_2.png) [@Slavisa\_Milojkovic](https://forums.percona.com/u/Slavisa_Milojkovic)\
**Post date:** [June 26, 2023, 11:55am UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120/3 "2023-06-26T11:55:06Z")

</div>

Thanks, I’ll test with:

```auto
set global binlog_expire_logs_seconds = 360;

```

---

<div class="post-metadata">

**Author:** ![kedarpercona](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/kedarpercona/32/809_2.png) [@kedarpercona](https://forums.percona.com/u/kedarpercona)\
**Post date:** [June 26, 2023, 12:12pm UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120/4 "2023-06-26T12:12:31Z")

</div>

Becareful with that. 360s is only 5 minutes! If your replicas are not caughtup, or stuck in replication errors, you will end up missing binary logs and thus needing to restore.  
I have usually seen 7 days of retention as a common practice but ofcourse depending on disk size available.  
Also, you can compress your binlogs and save on disk, [refer this](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_transaction_compression).

Thanks,  
K

---

<div class="post-metadata">

**Author:** ![Slavisa\_Milojkovic](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/slavisa_milojkovic/32/7097_2.png) [@Slavisa\_Milojkovic](https://forums.percona.com/u/Slavisa_Milojkovic)\
**Post date:** [June 26, 2023, 12:28pm UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120/5 "2023-06-26T12:28:11Z")

</div>

I meant 3600sec, an hour to test it, but I made a mistake. This is not production setup and we already have backup dumps, but for some reason binlogs are filling up pretty quickly, in couple of days. I will change the period after testing to a week of course. But seems it again cleared only node pxc-0. It is not removing old binlogs. After what time will replicas start purging the logs?

Thanks

---

<div class="post-metadata">

**Author:** ![kedarpercona](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/kedarpercona/32/809_2.png) [@kedarpercona](https://forums.percona.com/u/kedarpercona)\
**Post date:** [June 26, 2023, 12:32pm UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120/6 "2023-06-26T12:32:48Z")

</div>

Hi Slavisa,

This configuration is for that particular mysql instance only. You need to configure on individual PXC node.

Thanks,  
K

---

<div class="post-metadata">

**Author:** ![Slavisa\_Milojkovic](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/slavisa_milojkovic/32/7097_2.png) [@Slavisa\_Milojkovic](https://forums.percona.com/u/Slavisa_Milojkovic)\
**Post date:** [June 26, 2023, 12:45pm UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120/7 "2023-06-26T12:45:27Z")

</div>

Thank you for your answer and clarification.

---

<div class="post-metadata">

**Author:** ![CTutte](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ctutte/32/1341_2.png) [@CTutte](https://forums.percona.com/u/CTutte)\
**Post date:** [June 26, 2023, 2:29pm UTC](https://forums.percona.com/t/how-to-purge-binlogs-on-replica-nodes/23120/8 "2023-06-26T14:29:28Z")

</div>

Hi Slavisa\_Milojkovic,

One last comment.

Binlogs won’t be automatically removed when they reach binlog\_expire\_logs\_seconds but when a binary log is rotated the binary logs older than binlog\_expire\_logs\_seconds will be removed.

Binary logs are flushed (and a new one generated) under 3 conditions:

- a server restart
- “flush logs” statement being executed
- a binary log being full and rotated

Regards
