{"id":3565,"date":"2025-12-28T13:08:34","date_gmt":"2025-12-28T10:08:34","guid":{"rendered":"https:\/\/www.dchost.com\/blog\/mysql-and-postgresql-replication-on-vps-high-availability-and-automatic-failover\/"},"modified":"2026-11-04T19:30:27","modified_gmt":"2026-11-04T16:30:27","slug":"mysql-postgresql-replication","status":"publish","type":"post","link":"https:\/\/www.dchost.com\/blog\/en\/mysql-postgresql-replication\/","title":{"rendered":"VPS Database HA: MySQL and PostgreSQL Replication"},"content":{"rendered":"<div class=\"dchost-blog-content-wrapper\"><p>Running MySQL or PostgreSQL on a single <a href=\"https:\/\/www.dchost.com\/vps\">VPS<\/a> works fine until the first serious incident: a kernel panic, disk failure, data center network issue, or even a bad OS update. At that moment you do not care about benchmark numbers; you only care about how fast you can recover and how much data you might lose. That is exactly what database replication, high availability (HA) and automatic failover are designed to protect you from. In this guide, we will walk through how to design and implement MySQL and PostgreSQL replication on VPS servers in a way that is realistic, maintainable and testable. We will cover core concepts, practical topologies, MySQL and PostgreSQL specific settings, connection routing (proxies, VIP and DNS), and the operational side: backups, monitoring and disaster recovery. The goal is simple: after reading this, you should be able to sketch a concrete HA plan for your own VPS databases and know which tools and patterns to adopt first.<\/p>\n<p>This guide uses <strong>MySQL 8.4 LTS<\/strong> and <strong>PostgreSQL 17<\/strong>, with supported minor releases and compatible clients. The MySQL commands are not MariaDB instructions. Validate backups, versions, certificate trust and administrative recovery before rollout. Standalone replication and a Patroni-managed cluster have different process owners and bootstrap procedures.<\/p>\n<div id=\"toc_container\" role=\"navigation\" aria-label=\"Table of Contents\" data-nosnippet class=\"toc_transparent no_bullets toc_numbered toc_title_center\"><p class=\"toc_title\">\u0130\u00e7indekiler<\/p><ul class=\"toc_list\"><li><a href=\"#Why_Database_Replication_and_HA_Matter_on_a_VPS\"><span class=\"toc_number toc_depth_1\">1.<\/span> Why Database Replication and HA Matter on a VPS<\/a><\/li><li><a href=\"#Core_Concepts_Replication_Failover_and_Topologies\"><span class=\"toc_number toc_depth_1\">2.<\/span> Core Concepts: Replication, Failover and Topologies<\/a><ul><li><a href=\"#Primary_Replica_Master_Slave_Basics\"><span class=\"toc_number toc_depth_2\">2.1.<\/span> Primary \/ Replica (Master \/ Slave) Basics<\/a><\/li><li><a href=\"#Synchronous_vs_Asynchronous_Replication\"><span class=\"toc_number toc_depth_2\">2.2.<\/span> Synchronous vs Asynchronous Replication<\/a><\/li><li><a href=\"#Typical_HA_Topologies_on_VPS\"><span class=\"toc_number toc_depth_2\">2.3.<\/span> Typical HA Topologies on VPS<\/a><\/li><\/ul><\/li><li><a href=\"#Choosing_the_Right_VPS_Architecture_for_HA\"><span class=\"toc_number toc_depth_1\">3.<\/span> Choosing the Right VPS Architecture for HA<\/a><ul><li><a href=\"#How_Many_VPS_Servers_Do_You_Really_Need\"><span class=\"toc_number toc_depth_2\">3.1.<\/span> How Many VPS Servers Do You Really Need?<\/a><\/li><li><a href=\"#Single_Region_vs_Multi-Region_Replication\"><span class=\"toc_number toc_depth_2\">3.2.<\/span> Single Region vs Multi-Region Replication<\/a><\/li><li><a href=\"#Network_and_Storage_Considerations\"><span class=\"toc_number toc_depth_2\">3.3.<\/span> Network and Storage Considerations<\/a><\/li><\/ul><\/li><li><a href=\"#MySQL_Replication_on_VPS_Practical_Setup_and_HA_Patterns\"><span class=\"toc_number toc_depth_1\">4.<\/span> MySQL Replication on VPS: Practical Setup and HA Patterns<\/a><ul><li><a href=\"#1_Preparing_MySQL_for_Replication\"><span class=\"toc_number toc_depth_2\">4.1.<\/span> 1. Preparing MySQL for Replication<\/a><\/li><li><a href=\"#FilePosition_and_manual_read-lock_alternative\"><span class=\"toc_number toc_depth_2\">4.2.<\/span> File\/Position and manual read-lock alternative<\/a><\/li><li><a href=\"#2_Semi-Synchronous_Replication_Optional\"><span class=\"toc_number toc_depth_2\">4.3.<\/span> 2. Semi-Synchronous Replication (Optional)<\/a><\/li><li><a href=\"#3_Handling_Failover_for_MySQL\"><span class=\"toc_number toc_depth_2\">4.4.<\/span> 3. Handling Failover for MySQL<\/a><\/li><\/ul><\/li><li><a href=\"#PostgreSQL_Streaming_Replication_on_VPS\"><span class=\"toc_number toc_depth_1\">5.<\/span> PostgreSQL Streaming Replication on VPS<\/a><ul><li><a href=\"#1_Preparing_PostgreSQL_for_Streaming_Replication\"><span class=\"toc_number toc_depth_2\">5.1.<\/span> 1. Preparing PostgreSQL for Streaming Replication<\/a><\/li><li><a href=\"#2_Base_Backup_and_Standby_Configuration\"><span class=\"toc_number toc_depth_2\">5.2.<\/span> 2. Base Backup and Standby Configuration<\/a><\/li><li><a href=\"#3_Synchronous_Replication_Optional\"><span class=\"toc_number toc_depth_2\">5.3.<\/span> 3. Synchronous Replication (Optional)<\/a><\/li><li><a href=\"#4_Automatic_Failover_with_Patroni_or_repmgr\"><span class=\"toc_number toc_depth_2\">5.4.<\/span> 4. Automatic Failover with Patroni or repmgr<\/a><\/li><li><a href=\"#Patroni_architecture_fragment\"><span class=\"toc_number toc_depth_2\">5.5.<\/span> Patroni architecture fragment<\/a><\/li><\/ul><\/li><li><a href=\"#Automatic_Failover_Patterns_Proxy_VIP_and_DNS\"><span class=\"toc_number toc_depth_1\">6.<\/span> Automatic Failover Patterns: Proxy, VIP and DNS<\/a><ul><li><a href=\"#1_Proxy-Led_HA_HAProxy_ProxySQL_PgBouncer\"><span class=\"toc_number toc_depth_2\">6.1.<\/span> 1. Proxy-Led HA (HAProxy, ProxySQL, PgBouncer)<\/a><\/li><li><a href=\"#2_Floating_IP_VRRP_with_keepalived\"><span class=\"toc_number toc_depth_2\">6.2.<\/span> 2. Floating IP \/ VRRP with keepalived<\/a><\/li><li><a href=\"#3_DNS-Based_Failover\"><span class=\"toc_number toc_depth_2\">6.3.<\/span> 3. DNS-Based Failover<\/a><\/li><li><a href=\"#4_Avoiding_Split-Brain\"><span class=\"toc_number toc_depth_2\">6.4.<\/span> 4. Avoiding Split-Brain<\/a><\/li><\/ul><\/li><li><a href=\"#Operational_Best_Practices_Backups_Monitoring_and_DR\"><span class=\"toc_number toc_depth_1\">7.<\/span> Operational Best Practices: Backups, Monitoring and DR<\/a><ul><li><a href=\"#Replication_Is_Not_a_Backup\"><span class=\"toc_number toc_depth_2\">7.1.<\/span> Replication Is Not a Backup<\/a><\/li><li><a href=\"#Monitoring_Replication_Lag_and_Health\"><span class=\"toc_number toc_depth_2\">7.2.<\/span> Monitoring Replication Lag and Health<\/a><\/li><li><a href=\"#Disaster_Recovery_and_Failover_Drills\"><span class=\"toc_number toc_depth_2\">7.3.<\/span> Disaster Recovery and Failover Drills<\/a><\/li><\/ul><\/li><li><a href=\"#When_Replication_on_a_VPS_Is_and_Is_Not_the_Right_Choice\"><span class=\"toc_number toc_depth_1\">8.<\/span> When Replication on a VPS Is (and Is Not) the Right Choice<\/a><ul><li><a href=\"#When_HA_Replication_Makes_Sense\"><span class=\"toc_number toc_depth_2\">8.1.<\/span> When HA Replication Makes Sense<\/a><\/li><li><a href=\"#When_a_Single_VPS_Strong_Backups_Is_Enough\"><span class=\"toc_number toc_depth_2\">8.2.<\/span> When a Single VPS + Strong Backups Is Enough<\/a><\/li><\/ul><\/li><li><a href=\"#Wrapping_Up_A_Practical_Path_to_HA_MySQLPostgreSQL_on_VPS\"><span class=\"toc_number toc_depth_1\">9.<\/span> Wrapping Up: A Practical Path to HA MySQL\/PostgreSQL on VPS<\/a><\/li><li><a href=\"#Primary_Technical_Sources\"><span class=\"toc_number toc_depth_1\">10.<\/span> Primary Technical Sources<\/a><\/li><\/ul><\/div>\n<h2><span id=\"Why_Database_Replication_and_HA_Matter_on_a_VPS\">Why Database Replication and HA Matter on a VPS<\/span><\/h2>\n<p>CPU, RAM and storage capacity are only part of the design. Set an acceptable recovery time (RTO) and data-loss target (RPO), then evaluate replication, backups and failover against those needs.<\/p>\n<p><strong>Replication<\/strong> is the process of continuously copying data changes from one database instance (primary) to one or more others (replicas). <strong>High availability<\/strong> adds orchestration around that replication: health checks, automatic promotion, and a way for applications to reconnect to the appropriate node after failover.<\/p>\n<p>Backups are essential, but restoring a database can take longer than promoting a ready replica. Data loss depends on which backups and transaction logs survive and can be recovered; it is not inevitable. Replication combined with off-site backups can help meet tighter RPO\/RTO targets. For WooCommerce, SaaS dashboards and internal ERP systems, the choice between a single VPS and HA should follow the application&#8217;s recovery targets and operating budget.<\/p>\n<p>If you are still deciding whether to scale vertically or build HA, it is worth reading our article <a href=\"https:\/\/www.dchost.com\/blog\/en\/high-availability-vs-one-big-server-for-e-commerce-and-saas\/\">High Availability vs one big server for e\u2011commerce and SaaS<\/a>. A small HA setup on multiple VPSs can reduce downtime from individual node failures, but its cost-effectiveness depends on downtime costs, redundancy and operational overhead.<\/p>\n<h2><span id=\"Core_Concepts_Replication_Failover_and_Topologies\">Core Concepts: Replication, Failover and Topologies<\/span><\/h2>\n<h3><span id=\"Primary_Replica_Master_Slave_Basics\">Primary \/ Replica (Master \/ Slave) Basics<\/span><\/h3>\n<p>Both MySQL and PostgreSQL follow the same high-level model:<\/p>\n<ul>\n<li><strong>Primary<\/strong>: accepts all writes (INSERT\/UPDATE\/DELETE, DDL). Clients may also read from it.<\/li>\n<li><strong>Replica<\/strong>: receives changes from the primary and replays them. Usually read-only, serving analytics or read-heavy traffic.<\/li>\n<\/ul>\n<p>In MySQL, classic replication is <strong>statement-based<\/strong> or <strong>row-based<\/strong> using <strong>binary logs (binlog)<\/strong>. Modern deployments typically use row-based binary logging with GTID (Global Transaction ID) for easier recovery and failover.<\/p>\n<p>In PostgreSQL, HA commonly uses <strong>physical streaming replication<\/strong>: the primary writes WAL (Write-Ahead Log) segments, and replicas stream and replay them. You can also use <strong>logical replication<\/strong> for more advanced use cases (partial tables, cross-version migrations), but physical replication is the standard for HA.<\/p>\n<h3><span id=\"Synchronous_vs_Asynchronous_Replication\">Synchronous vs Asynchronous Replication<\/span><\/h3>\n<p>Replication timing directly affects your RPO:<\/p>\n<ul>\n<li><strong>Asynchronous:<\/strong> the primary returns a local commit without waiting for a replica. Unreceived writes may be lost on failover; without a lag bound the loss is not limited to a few seconds.<\/li>\n<li><strong>MySQL semisynchronous:<\/strong> the configured number of replicas acknowledges writing and flushing events to its relay log, not applying them. A timeout can revert the source to asynchronous replication.<\/li>\n<li><strong>PostgreSQL synchronous:<\/strong> synchronous_commit=on waits for durable remote WAL flush, remote_write waits for the remote operating-system write, and remote_apply waits for durable flush and replay. Configure synchronous_standby_names and select an eligible failover target as well.<\/li>\n<\/ul>\n<p>MySQL offers semi-synchronous replication plugins and group replication. PostgreSQL supports synchronous replication with <code>synchronous_commit<\/code> and <code>synchronous_standby_names<\/code>. Starting with asynchronous replication is reasonable only if its potential data loss fits your RPO. Evaluate synchronous options for stricter recovery targets, including their effects on latency and write availability.<\/p>\n<h3><span id=\"Typical_HA_Topologies_on_VPS\">Typical HA Topologies on VPS<\/span><\/h3>\n<p>On 2\u20134 VPS servers, these topologies are common:<\/p>\n<ul>\n<li><strong>Single primary + one replica<\/strong>: basic database redundancy. A ready replica can shorten recovery through promotion (often manual), offload reads and move backup work off the primary.<\/li>\n<li><strong>Single primary + two replicas<\/strong>: better survivability (one replica can remain available while another is down), room for analytics, and flexibility to do rolling OS\/database upgrades where version compatibility permits.<\/li>\n<li><strong>Primary\/replica with quorum and fencing<\/strong>: usually with a coordination layer (etcd\/Consul for PostgreSQL Patroni, or orchestrator-style tools for MySQL) to select a new primary, with fencing to prevent the old primary from continuing to accept writes.<\/li>\n<\/ul>\n<p>MySQL Group Replication and InnoDB Cluster are separate cluster designs. InnoDB Cluster defaults to <strong>single-primary<\/strong>; multi-primary is optional. PostgreSQL can use Patroni or a separately evaluated repmgr design. Each approach still needs supported versions, membership, safe promotion and client routing; a proxy does not turn ordinary replication into a complete cluster.<\/p>\n<p>Related guide: <a href=\"https:\/\/www.dchost.com\/blog\/en\/beyond-backups-what-ive-learned-choosing-between-mariadb-galera-cluster-and-mysql-group-replication-for-real-high-availability\/\">Beyond backups: choosing between MariaDB Galera Cluster and MySQL Group Replication for real HA<\/a>.<\/p>\n<h2><span id=\"Choosing_the_Right_VPS_Architecture_for_HA\">Choosing the Right VPS Architecture for HA<\/span><\/h2>\n<h3><span id=\"How_Many_VPS_Servers_Do_You_Really_Need\">How Many VPS Servers Do You Really Need?<\/span><\/h3>\n<p>Plan capacity and redundancy around three roles:<\/p>\n<ul>\n<li>Database nodes: two or more independently placed VPSs with measured disk\/network capacity. Two data nodes leave only one copy after a node failure.<\/li>\n<li>Controller quorum: for the Patroni example, three actual etcd members, one each on DB1, DB2 and a helper, with Patroni on both database nodes.<\/li>\n<li>Routing and application: redundant proxies and application instances where end-to-end availability requires them. PgBouncer provides pooling, not leader election.<\/li>\n<\/ul>\n<p>If budgets are tight, you can start with <strong>2 database VPSs + 1 app\/proxy VPS<\/strong>, then grow towards fully separated roles as traffic increases. The shared app\/proxy VPS remains a single point of failure, so this provides database redundancy rather than end-to-end HA. Our article <a href=\"https:\/\/www.dchost.com\/blog\/en\/when-to-separate-database-and-application-servers-for-mysql-and-postgresql\/\">When to separate database and application servers for MySQL and PostgreSQL<\/a> goes deeper into this decision.<\/p>\n<p>The etcd quorum is two of three voting members, not two PostgreSQL servers plus an informal witness. Installing etcd only on the helper leaves a single DCS member. Colocation is a capacity tradeoff: test DB I\/O pressure against etcd latency, and verify independent underlying failure domains. Requiring every write on two durable database copies blocks new writes when only one data node remains.<\/p>\n<h3><span id=\"Single_Region_vs_Multi-Region_Replication\">Single Region vs Multi-Region Replication<\/span><\/h3>\n<p>Most HA setups start inside a single data center or region: lower latency, simpler networking and fewer moving parts. Once your RTO\/RPO requirements include regional disasters or long outages, you can extend replication across regions.<\/p>\n<p>For that, we like patterns similar to those described in <a href=\"https:\/\/www.dchost.com\/blog\/en\/when-one-region-goes-dark-a-friendly-guide-to-multi-region-architectures-with-dns-geo-routing-and-database-replication\/\">multi\u2011region architectures with DNS geo\u2011routing and database replication<\/a>: keep a primary cluster in one region, stream replication to another region, and use DNS or traffic manager logic to fail over clients. This design requires VPS placement in separate regions, alongside a backup and DR plan.<\/p>\n<h3><span id=\"Network_and_Storage_Considerations\">Network and Storage Considerations<\/span><\/h3>\n<p>Replication streams WAL\/binlog data over the network; under heavy write load, that traffic can be significant. On a VPS, ensure:<\/p>\n<ul>\n<li>For local HA, your nodes share a <strong>low-latency network<\/strong> while occupying independent failure domains, avoiding a shared physical host or storage dependency where possible. Cross-region replicas trade higher latency for protection against regional outages.<\/li>\n<li>Measure storage latency, write endurance and sustained I\/O under the combined database, replication and backup workload. NVMe may help, but the interface alone does not guarantee performance. Our <a href=\"https:\/\/www.dchost.com\/blog\/en\/nvme-ssd-vs-sata-ssd-vs-hdd\/\">NVMe SSD vs SATA SSD vs HDD comparison<\/a> compares the storage options and their tradeoffs.<\/li>\n<\/ul>\n<h2><span id=\"MySQL_Replication_on_VPS_Practical_Setup_and_HA_Patterns\">MySQL Replication on VPS: Practical Setup and HA Patterns<\/span><\/h2>\n<h3><span id=\"1_Preparing_MySQL_for_Replication\">1. Preparing MySQL for Replication<\/span><\/h3>\n<p>Assume MySQL 8.4 LTS on both hosts, with GTID already enabled on the source. Converting a running non-GTID topology needs a separate migration plan. db1.internal.example.com resolves to 10.0.0.1, and db2.internal.example.com to 10.0.0.2; CA-issued server certificates must match those names. Validate the package source, effective configuration, administrative access and unique server_id\/server_uuid on each host.<\/p>\n<ol>\n<li><strong>Configure unique server IDs<\/strong> in <code>my.cnf<\/code> on each node:<\/li>\n<\/ol>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[mysqld]\nserver_id = 1\nlog_bin = mysql-bin\nbinlog_format = ROW\ngtid_mode = ON\nenforce_gtid_consistency = ON\nlog_replica_updates = ON\nsync_binlog = 1\ninnodb_flush_log_at_trx_commit = 1\nread_only = OFF\nsuper_read_only = OFF\n<\/code><\/pre>\n<p>The future source uses these replica settings:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[mysqld]\nserver_id = 2\nlog_bin = mysql-bin\nbinlog_format = ROW\ngtid_mode = ON\nenforce_gtid_consistency = ON\nlog_replica_updates = ON\nsync_binlog = 1\ninnodb_flush_log_at_trx_commit = 1\nread_only = ON\nsuper_read_only = ON\nrelay_log = relay-bin\nevent_scheduler = OFF\n<\/code><\/pre>\n<p>Binary logging and log_replica_updates are enabled so the replica can later serve downstream replicas; GTID itself does not require binary logging on every replica. Apply startup changes through the distribution\u2019s actual service\/configuration path in a maintenance window and verify the effective values.<\/p>\n<p>Create a dedicated replication account for the replica\u2019s exact source IP as observed by MySQL, accounting for NAT. Use a separate account for monitoring. Keep MySQL port 3306 off the public Internet and restrict internal firewall access to authorized application, replication and administration hosts. Replace the secret in a protected SQL session; do not put actual passwords into shell arguments, shared command histories or logs.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">CREATE USER &#039;repl&#039;@&#039;10.0.0.2&#039;\n  IDENTIFIED WITH caching_sha2_password BY &#039;REPLACE_WITH_UNIQUE_SECRET&#039;\n  REQUIRE SSL;\nGRANT REPLICATION SLAVE ON *.* TO &#039;repl&#039;@&#039;10.0.0.2&#039;;\n<\/code><\/pre>\n<p>REPLICATION SLAVE is sufficient for this account; REPLICATION CLIENT belongs to monitoring\/backup needs when required. CREATE USER\/GRANT does not require FLUSH PRIVILEGES. The default caching_sha2_password mechanism works over the verified TLS channel below. Replication credentials are stored in the replica connection metadata, so protect the data directory and backups.<\/p>\n<p>Seed a new isolated replica from one consistent snapshot. The example has one application schema, appdb; list every application schema together if there are more. A partial dump records the source\u2019s complete GTID set, so omitting a schema can mark missing data as already applied. Inventory and provision users, roles, grants and routine DEFINER accounts separately, with their intended privileges; do not blindly restore mysql system tables as part of a GTID seed.<\/p>\n<p>During the dump, application tables must use InnoDB; suspend DDL, schema deployments and account\/grant changes. Nontransactional tables need a different consistency plan. The pre-created \/secure directory must be restricted to the authorized backup operator. Verify option-specific backup privileges, including SELECT, SHOW VIEW, TRIGGER and the relevant RELOAD, REPLICATION CLIENT, EVENT\/routine permissions.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">umask 077\nmysqldump --host=db1.internal.example.com --user=backup --password \\\n  --ssl-mode=VERIFY_IDENTITY --ssl-ca=\/etc\/mysql\/ca.pem \\\n  --single-transaction --quick --source-data=2 --set-gtid-purged=ON \\\n  --routines --triggers --events --hex-blob --no-tablespaces \\\n  --databases appdb &gt; \/secure\/replica-seed.sql\n<\/code><\/pre>\n<p>&#8211;source-data=2 briefly takes a global read lock at the start and writes the matching File\/Position as a comment. &#8211;set-gtid-purged=ON records the source GTIDs and disables session binary logging during import. &#8211;no-tablespaces omits tablespace definitions; general tablespaces need a separate restore plan. Check the exit status\/stderr, hash the completed dump, transfer it over an encrypted channel and test its restoration. A raw LVM snapshot requires database-consistent coordination; it is not automatically a valid seed.<\/p>\n<p>Use only a fresh, application-fenced target with reviewed GTID state. Existing data or overlapping GTIDs require a separate migration plan; do not clear data or reset GTID history. Temporarily opening read_only\/super_read_only for the authorized import must not expose the target to application writers. The seed_admin account needs privileges for every statement in the reviewed dump, including its GTID\/session settings.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">mysql --host=db2.internal.example.com --user=seed_admin --password \\\n  --ssl-mode=VERIFY_IDENTITY --ssl-ca=\/etc\/mysql\/ca.pem \\\n  &lt; \/secure\/replica-seed.sql\n<\/code><\/pre>\n<p>Stop on any import error. Validate schema\/data, grants and DEFINER accounts, then restore read_only=ON and super_read_only=ON and verify both. This is an application-schema seed, not an unreviewed &#8211;all-databases system-table import. Retain a documented account\/configuration inventory for promotion.<\/p>\n<h3><span id=\"FilePosition_and_manual_read-lock_alternative\">File\/Position and manual read-lock alternative<\/span><\/h3>\n<p>A separate file-position channel must use coordinates from the same snapshot. MySQL 8.4 uses SHOW BINARY LOG STATUS. If taking a manual global read lock, keep the issuing SQL client open while a second session reads coordinates and takes the coordinated backup:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">FLUSH TABLES WITH READ LOCK;\n<\/code><\/pre>\n<p>In the second SQL session while the lock is held:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">SHOW BINARY LOG STATUS\\G\n<\/code><\/pre>\n<p>After the backup completes or is safely abandoned, release the lock in the original lock-owning session:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">UNLOCK TABLES;\n<\/code><\/pre>\n<p>A mysql -e client that exits releases its lock before a later dump. File\/position mode uses SOURCE_AUTO_POSITION=0 and the matching SOURCE_LOG_FILE\/SOURCE_LOG_POS; do not combine it with the GTID path below. Retain the full dataset, account inventory and source history required by the chosen method.<\/p>\n<p>Related guide: <a href=\"https:\/\/www.dchost.com\/blog\/en\/mysql-backup-strategies-mysqldump-percona-xtrabackup-or-snapshots\/\">MySQL backup strategies: mysqldump, XtraBackup and snapshots<\/a>.<\/p>\n<p>Separately preparing accounts and DEFINERs on the isolated target must not introduce unintended local GTIDs; the authorized operator must review that provisioning session\u2019s sql_log_bin policy and the final GTID set. If roles later reverse, provision the replication account for the new replica\u2019s exact observed IP rather than widening it to a wildcard.<\/p>\n<p>Before seeding, verify event_scheduler=OFF on the replica and disable local scheduled jobs. Fencing application connections does not stop local event execution. Enable imported event definitions only through the promotion runbook after proving that the new primary is the sole job owner.<\/p>\n<p>On the replica, both receiver and applier threads must be stopped before changing to auto-position if a channel is already running. The CA file must be readable by MySQL, and SOURCE_HOST must match the certificate identity. In a protected SQL session configure:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">CHANGE REPLICATION SOURCE TO\n  SOURCE_HOST = &#039;db1.internal.example.com&#039;,\n  SOURCE_USER = &#039;repl&#039;,\n  SOURCE_PASSWORD = &#039;REPLACE_WITH_UNIQUE_SECRET&#039;,\n  SOURCE_AUTO_POSITION = 1,\n  SOURCE_SSL = 1,\n  SOURCE_SSL_CA = &#039;\/etc\/mysql\/ca.pem&#039;,\n  SOURCE_SSL_VERIFY_SERVER_CERT = 1;\nSTART REPLICA;\nSHOW REPLICA STATUS\\G\n<\/code><\/pre>\n<p>Check Replica_IO_Running\/Replica_SQL_Running, Last_IO_Error, Last_SQL_Error and all Performance Schema applier worker errors. Verify Auto_Position=1 and the effective TLS\/CA\/identity settings. Seconds_Behind_Source=0 is not proof of catch-up or zero possible data loss; the receiver can be behind on a slow network. Compare GTID history and application invariants. If required GTIDs have been purged, recover the missing trusted history or take a new seed; disabling auto-position does not recover missing data.<\/p>\n<h3><span id=\"2_Semi-Synchronous_Replication_Optional\">2. Semi-Synchronous Replication (Optional)<\/span><\/h3>\n<p>Semisynchronous replication requires compatible plugins on the participating source and replicas. Load only the libraries shipped for the installed MySQL version; verify that the plugin is installed before enabling its variable.<\/p>\n<ul>\n<li>Source: rpl_semi_sync_source plugin; rpl_semi_sync_source_enabled=ON.<\/li>\n<li>Replica: rpl_semi_sync_replica plugin; rpl_semi_sync_replica_enabled=ON.<\/li>\n<li>When enabling a running replica, reconnect its receiver with STOP REPLICA IO_THREAD and START REPLICA IO_THREAD so it registers its semisynchronous capability.<\/li>\n<li>Verify plugin status, acknowledgement count, timeout\/fallback and configured wait point under failure and load; persist intended settings through the appropriate option files.<\/li>\n<\/ul>\n<p>An acknowledgement means the events reached a replica relay log and were flushed to disk, not that SQL replay completed. Timeout can return the source to asynchronous operation. Wait point, durable local settings and promotion of a replica holding the required acknowledged transactions matter; this is not an unconditional RPO=0 guarantee. A failed old source may contain divergent\/unacknowledged work and must be reconciled or rebuilt before reuse.<\/p>\n<h3><span id=\"3_Handling_Failover_for_MySQL\">3. Handling Failover for MySQL<\/span><\/h3>\n<p>Replication alone does not give you HA. You need a way to:<\/p>\n<ul>\n<li>Confirm failure and suspend application writes; fence the old primary so it cannot accept writes, including direct clients and scheduled jobs. read_only\/super_read_only alone is not infrastructure fencing.<\/li>\n<li>Select an eligible replica using GTID history, apply state, errors and the accepted data-loss budget; apply the available required relay-log work before promotion.<\/li>\n<li>Record replication metadata and recovery evidence. Do not use a generic RESET REPLICA ALL recipe that discards channel information before diagnosis.<\/li>\n<li>Complete promotion through the chosen runbook\/controller, prove that exactly one writer is reachable, then update routing and validate application recovery.<\/li>\n<\/ul>\n<p>Common patterns on VPS setups:<\/p>\n<ul>\n<li>Application-aware failover requires supported driver behavior, role checks, reconnects and transaction recovery. Trying a read-only replica is not promotion.<\/li>\n<li>HAProxy or ProxySQL can route traffic according to a tested role policy; they do not independently fence an old writer.<\/li>\n<li>Orchestrator\/Raft quorum belongs to the Orchestrator controllers, for example two of three controllers, not the database replicas. A single helper\/controller is still a controller failure point.<\/li>\n<li>A provider-supported floating IP or redundant proxy endpoint can stabilize addressing, but existing sessions still need recovery.<\/li>\n<\/ul>\n<p>For MySQL, <strong>ProxySQL<\/strong> is particularly powerful: it can route writes to the primary and reads to replicas, handle connection pooling, and integrate with MySQL monitoring. A lagging replica can return stale data immediately after a successful write. Route reads that require read-after-write consistency to the primary or to a replica verified to have applied the required transaction. For a related configuration guide, see <a href=\"https:\/\/www.dchost.com\/blog\/en\/proxysql-mysql-read-write-splitting-pooling\/\">ProxySQL read\/write split and pooling for WooCommerce and Laravel<\/a>. The same patterns apply on a VPS-based HA setup.<\/p>\n<p>The openark\/orchestrator repository is archived; its README directs maintenance collaboration to the Percona fork. Check the selected distribution\u2019s maintenance, support and MySQL 8.4 compatibility before adoption. InnoDB Cluster\/MySQL Router uses its own membership and routing design; do not apply a classic replication runbook to it unchanged.<\/p>\n<h2><span id=\"PostgreSQL_Streaming_Replication_on_VPS\">PostgreSQL Streaming Replication on VPS<\/span><\/h2>\n<h3><span id=\"1_Preparing_PostgreSQL_for_Streaming_Replication\">1. Preparing PostgreSQL for Streaming Replication<\/span><\/h3>\n<p>Use compatible supported PostgreSQL 17 minor releases on both nodes. Physical streaming is not a cross-major upgrade mechanism. pg1.internal.example.com \/ 10.0.0.1 is the primary; pg2.internal.example.com \/ 10.0.0.2 is the standby. Prepare CA-issued server certificates, correct key ownership, private DNS and the client CA file first.<\/p>\n<ol>\n<li><strong>Configure WAL and replication settings<\/strong> on the primary&#8217;s <code>postgresql.conf<\/code>:<\/li>\n<\/ol>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">listen_addresses = &#039;10.0.0.1&#039;\nwal_level = replica\nmax_wal_senders = 10\nmax_replication_slots = 10\nmax_slot_wal_keep_size = &#039;10GB&#039;\nhot_standby = on\npassword_encryption = &#039;scram-sha-256&#039;\nssl = on\nssl_cert_file = &#039;\/etc\/postgresql\/tls\/server.crt&#039;\nssl_key_file = &#039;\/etc\/postgresql\/tls\/server.key&#039;\n<\/code><\/pre>\n<p>Change the standby listen address and node certificate to its own identity; preserve required standby-compatible resource settings. 10GB is an illustrative slot-retention budget to size from write rate and tolerated outages. A slot can fill the disk if retention is unlimited; a limited slot can lose required WAL and require a new seed. Apply startup-only settings in a planned window.<\/p>\n<p>WAL archiving is separate from streaming replication. For PITR, after configuring a tested pgBackRest repository and app stanza, an archive configuration can use:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">archive_mode = on\narchive_command = &#039;pgbackrest --stanza=app archive-push %p&#039;\n<\/code><\/pre>\n<p>Provision the off-host repository, credentials\/ownership and retention first; run stanza-create, check, a complete backup and a restore drill. The check command can trigger a WAL switch. A bare cp or success merely because the destination exists is not a complete reliable archive policy: retries, identical-file verification, conflicting files and full disks need defined handling. Archived WAL is not a base backup.<\/p>\n<ol start=\"2\">\n<li><strong>Allow replication connections<\/strong> in <code>pg_hba.conf<\/code> on the primary:<\/li>\n<\/ol>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">hostssl replication repl 10.0.0.2\/32 scram-sha-256\n<\/code><\/pre>\n<p>pg_hba.conf uses the first matching record; earlier broad rules must not bypass hostssl\/SCRAM. Verify ssl=on, readable certificate\/key files and the effective rule. Permit port 5432 only from the required internal sources.<\/p>\n<p>In an authorized psql session create the role and use the password prompt. If the role already exists, inspect it and plan any password rotation rather than recreating it.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">SET password_encryption = &#039;scram-sha-256&#039;;\nCREATE ROLE repl WITH LOGIN REPLICATION;\n\\password repl\n<\/code><\/pre>\n<h3><span id=\"2_Base_Backup_and_Standby_Configuration\">2. Base Backup and Standby Configuration<\/span><\/h3>\n<p>On the standby:<\/p>\n<ul>\n<li>Stop the standalone PostgreSQL process that would use the target directory. Use a new empty target; never blindly clear an existing data directory. Preserve existing data and configuration first.<\/li>\n<li>Run pg_basebackup as the postgres operating-system account. The example data directory is owned by postgres with mode 0700.<\/li>\n<li>Prepare \/var\/lib\/postgresql\/.pgpass, owned by that account with mode 0600, containing a protected pg1.internal.example.com:5432:replication:repl:REAL_SECRET entry; escape colons\/backslashes as needed.<\/li>\n<li>replica1 must not already exist when using &#8211;create-slot. Allow two walsender connections for the backup plus streamed WAL, sufficient slot capacity, and correctly mapped paths for additional tablespaces.<\/li>\n<\/ul>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">pg_basebackup \\\n  --dbname=&quot;host=pg1.internal.example.com port=5432 user=repl application_name=standby1 sslmode=verify-full sslrootcert=\/etc\/postgresql\/tls\/ca.crt passfile=\/var\/lib\/postgresql\/.pgpass&quot; \\\n  --pgdata=\/var\/lib\/postgresql\/17\/replica \\\n  --format=plain --wal-method=stream --write-recovery-conf \\\n  --create-slot --slot=replica1 --progress\n<\/code><\/pre>\n<p>&#8211;write-recovery-conf creates standby.signal and writes connection and slot settings to postgresql.auto.conf. PostgreSQL 17 does not use recovery.conf. Inspect leftover slots and retained WAL after an interrupted backup; do not delete an active consumer\u2019s slot. Review copied settings plus distribution configuration outside the data directory, including listen address, certificate, hot_standby and the actual service data path before starting.<\/p>\n<p>Start the correct standalone instance and inspect pg_stat_replication on the primary; on the standby verify pg_is_in_recovery(), pg_stat_wal_receiver and receive\/replay LSNs. Test a TLS\/SCRAM replication connection and application-level data invariants. Reaching streaming state alone is not a complete failover test.<\/p>\n<h3><span id=\"3_Synchronous_Replication_Optional\">3. Synchronous Replication (Optional)<\/span><\/h3>\n<p>For a standalone synchronous example, require the named standby and durable remote flush on the primary:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">synchronous_commit = on\nsynchronous_standby_names = &#039;FIRST 1 (standby1)&#039;\n<\/code><\/pre>\n<p>standby1 matches application_name in the basebackup connection above. If the required standby is unavailable, affected commits wait. on waits for durable remote WAL flush; remote_write is only an operating-system write and remote_apply additionally waits for replay. An empty synchronous_standby_names does not require a remote acknowledgement. Per-transaction synchronous_commit overrides and choosing an ineligible promotion target change the protection. With only two database nodes, losing one means two-copy synchronous writes cannot continue.<\/p>\n<h3><span id=\"4_Automatic_Failover_with_Patroni_or_repmgr\">4. Automatic Failover with Patroni or repmgr<\/span><\/h3>\n<p>Choose manual or automatic failover from the tested RTO and operational capacity, not merely whether an application is customer-facing. Patroni owns PostgreSQL process and leader lifecycle; repmgr is a separate approach that needs its own supported configuration and failure policy.<\/p>\n<ul>\n<li>Run Patroni on each PostgreSQL node and three actual etcd members across DB1, DB2 and the helper; quorum is two of three. PostgreSQL itself is not the DCS backend in this example.<\/li>\n<li>Use the etcd3 section for the v3 API. Provision etcd cluster membership, peer\/client TLS, authentication and constrained key-prefix permissions separately.<\/li>\n<li>Do not let both the distribution\u2019s standalone service and Patroni start the same database. Existing-data adoption or fresh bootstrap needs an explicit migration plan.<\/li>\n<li>Test leader lease loss, lag\/timeline eligibility and fencing\/watchdog behavior. synchronous_mode does not always require two durable copies; synchronous_mode_strict can block writes without a suitable standby. Manual override and cancelled\/uncertain commits retain important limits.<\/li>\n<\/ul>\n<p>A role-aware proxy can check Patroni \/primary, which returns 200 only for a running primary holding the leader lock. PgBouncer is a pooler with no internal failover detection; use an external role-aware routing or target-update mechanism. Plan redundant proxies, pool reconnection and application recovery.<\/p>\n<h3><span id=\"Patroni_architecture_fragment\">Patroni architecture fragment<\/span><\/h3>\n<p>The YAML below is <strong>not a launch-ready cluster recipe<\/strong>. Pin compatible Patroni\/etcd versions and separately complete etcd peer\/client bootstrap, database initdb or existing-data adoption, PostgreSQL HBA\/TLS settings, backup\/restore, watchdog and client trust configuration. REPLACE_WITH_* values are literal placeholders; distribute actual secrets through a controlled process and restrict file ownership\/permissions. The YAML keys follow the Patroni 4.1.0 reference; compare them with the documentation for your selected supported Patroni release.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">scope: app-ha\nnamespace: \/service\/\nname: pg1\n\nrestapi:\n  listen: 10.0.0.1:8008\n  connect_address: pg1.internal.example.com:8008\n  certfile: \/etc\/patroni\/tls\/server.crt\n  keyfile: \/etc\/patroni\/tls\/server.key\n  authentication:\n    username: patroni_api\n    password: REPLACE_WITH_API_SECRET\n\netcd3:\n  hosts:\n    - etcd1.internal.example.com:2379\n    - etcd2.internal.example.com:2379\n    - etcd3.internal.example.com:2379\n  protocol: https\n  cacert: \/etc\/patroni\/tls\/etcd-ca.crt\n  cert: \/etc\/patroni\/tls\/etcd-client.crt\n  key: \/etc\/patroni\/tls\/etcd-client.key\n  username: patroni_dcs\n  password: REPLACE_WITH_DCS_SECRET\n\npostgresql:\n  listen: 10.0.0.1:5432\n  connect_address: pg1.internal.example.com:5432\n  data_dir: \/var\/lib\/postgresql\/17\/patroni\n  bin_dir: \/usr\/lib\/postgresql\/17\/bin\n  authentication:\n    superuser:\n      username: postgres\n      password: REPLACE_WITH_ADMIN_SECRET\n    replication:\n      username: repl\n      password: REPLACE_WITH_REPLICATION_SECRET\n      sslmode: verify-full\n      sslrootcert: \/etc\/postgresql\/tls\/ca.crt\n<\/code><\/pre>\n<p>For pg2, review name, every listen\/connect_address, node-specific certificate\/key, data path and binary path. The three DCS endpoints must already form the intended cluster. v2 keys do not become visible to v3 by renaming the config section; etcdv3 gRPC gateway does not turn a TLS common name into DCS user authorization. Configure REST server-certificate verification for all Patroni peers, proxies and administrative clients. Restrict API access to authorized network sources and authenticate mutation endpoints.<\/p>\n<p>If you are planning a serious PostgreSQL deployment on a VPS, also look at our performance-focused article <a href=\"https:\/\/www.dchost.com\/blog\/en\/postgresql-vps-memory-wal-pgbouncer\/\">The friendly VPS playbook for PostgreSQL performance<\/a> and our autovacuum tuning guide. Poorly tuned vacuum and WAL settings can increase replication lag and delay recovery.<\/p>\n<h2><span id=\"Automatic_Failover_Patterns_Proxy_VIP_and_DNS\">Automatic Failover Patterns: Proxy, VIP and DNS<\/span><\/h2>\n<h3><span id=\"1_Proxy-Led_HA_HAProxy_ProxySQL_PgBouncer\">1. Proxy-Led HA (HAProxy, ProxySQL, PgBouncer)<\/span><\/h3>\n<p>In this model, your applications talk to one or two proxy endpoints:<\/p>\n<ul>\n<li>For MySQL: ProxySQL or HAProxy.<\/li>\n<li>For PostgreSQL: PgBouncer and\/or HAProxy.<\/li>\n<\/ul>\n<p>The orchestrator selects and safely promotes an eligible replica; the role-aware proxy follows that decision. For PostgreSQL use a Patroni \/primary check with verified TLS, rather than a mere open TCP port. PgBouncer needs an external failover\/target-update mechanism and a tested server-connection refresh procedure. MySQL proxy routing must likewise follow the selected single-writer policy.<\/p>\n<p>This centralizes endpoint management. Redundant proxies add resource and operational costs; test that old direct-to-database writers cannot bypass the policy. A stable endpoint does not transfer open TCP sessions or in-flight transactions; reconnect, identify uncertain commits and use idempotent retries or reconciliation.<\/p>\n<h3><span id=\"2_Floating_IP_VRRP_with_keepalived\">2. Floating IP \/ VRRP with keepalived<\/span><\/h3>\n<p>A floating IP can be moved to the selected primary or active proxy when the provider network supports the chosen mechanism. keepalived\/VRRP requires suitable network, ARP and anti-spoof behavior; some platforms require a provider API instead. Couple IP movement to safe promotion and fencing: the address does not inherently know which database is primary.<\/p>\n<p>Advantages:<\/p>\n<ul>\n<li>Very simple for applications: they see only one IP.<\/li>\n<li>Can be combined with proxies (VIP pointing at the active proxy instead of the database).<\/li>\n<\/ul>\n<p>Disadvantages:<\/p>\n<ul>\n<li>Requires L2\/L3 network support for VRRP, which every VPS platform implements differently.<\/li>\n<li>Failover is at the IP level; you still need application-level reconnection logic and safe promotion steps to avoid split-brain.<\/li>\n<\/ul>\n<h3><span id=\"3_DNS-Based_Failover\">3. DNS-Based Failover<\/span><\/h3>\n<p>Another approach is to have a DNS name (e.g. <code>db.example.com<\/code>) that points to the current primary. When failover happens, automation updates the DNS record.<\/p>\n<p>Pros:<\/p>\n<ul>\n<li>Simpler from the network perspective (no VRRP).<\/li>\n<li>Works well for <strong>multi-region<\/strong> or multi-data-center replication where IP-level failover is harder.<\/li>\n<\/ul>\n<p>Cons:<\/p>\n<ul>\n<li>TTL and caching mean failover is not instant.<\/li>\n<li>Clients must honor DNS TTLs and reconnect properly.<\/li>\n<\/ul>\n<p>Changing DNS does not move existing connections. Driver caches and pool reuse can extend recovery beyond the authoritative TTL; verify the actual client resolver and retry behavior. Repeating an operation whose commit result is unknown can duplicate business effects.<\/p>\n<p>For high-end architectures, combining DNS geo\u2011routing with multi-region replication is powerful; our article <a href=\"https:\/\/www.dchost.com\/blog\/en\/anycast-dns-automatic-failover\/\">How Anycast DNS and automatic failover keep your site up<\/a> explains how DNS\u2011level strategies complement database HA.<\/p>\n<h3><span id=\"4_Avoiding_Split-Brain\">4. Avoiding Split-Brain<\/span><\/h3>\n<p>Split-brain happens when two nodes both believe they are primary and accept writes independently. Merging that data is painful or impossible.<\/p>\n<p>To avoid it:<\/p>\n<ul>\n<li>Use the chosen controller\u2019s tested membership\/lease and candidate eligibility rules. etcd\/Orchestrator controller quorum is distinct from data replication acknowledgements.<\/li>\n<li>Fence the old writer before advertising the new one. Block privileged jobs and direct clients as well as proxy traffic; database read-only settings alone are not external fencing.<\/li>\n<li>Keep the recovered old primary isolated. In MySQL compare GTID history and divergent writes, then reconcile or rebuild from a verified seed; do not automatically merge two writable histories.<\/li>\n<li>For PostgreSQL pg_rewind, the target must be stopped and have pre-existing checksums or wal_log_hints, plus full_page_writes and the required WAL history. Preserve the old data and verify standby configuration after rewind. A failed rewind can leave the target unusable; use a new base backup when prerequisites or recovery fail.<\/li>\n<\/ul>\n<h2><span id=\"Operational_Best_Practices_Backups_Monitoring_and_DR\">Operational Best Practices: Backups, Monitoring and DR<\/span><\/h2>\n<h3><span id=\"Replication_Is_Not_a_Backup\">Replication Is Not a Backup<\/span><\/h3>\n<p>Replication will happily replicate <em>mistakes<\/em>: dropped tables, bad migrations, or mass updates. You still need proper backups with versioning and point\u2011in\u2011time recovery.<\/p>\n<p>We strongly recommend:<\/p>\n<ul>\n<li>Regular logical or physical backups from a replica (to lighten load on the primary).<\/li>\n<li>Off\u2011site \/ off\u2011VPS backups, ideally to S3\u2011compatible object storage.<\/li>\n<li>Periodic <strong>restore drills<\/strong>, not just \u201cbackup completed\u201d checks.<\/li>\n<\/ul>\n<p>Two resources that pair perfectly with this article:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.dchost.com\/blog\/en\/the-little-freeze-that-saves-your-data-application-consistent-hot-backups-with-lvm-snapshots-for-mysql-and-postgresql\/\">Application\u2011consistent hot backups with LVM snapshots for MySQL and PostgreSQL<\/a> \u2014 for low\u2011impact, consistent backups.<\/li>\n<li><a href=\"https:\/\/www.dchost.com\/blog\/en\/postgresql-backup-pitr-pgbackrest\/\">PostgreSQL backups and PITR with pgBackRest<\/a> \u2014 if you are serious about Postgres.<\/li>\n<\/ul>\n<h3><span id=\"Monitoring_Replication_Lag_and_Health\">Monitoring Replication Lag and Health<\/span><\/h3>\n<p>Good HA is impossible without good observability. At minimum, monitor:<\/p>\n<ul>\n<li>MySQL: Seconds_Behind_Source with its limitations, receiver\/applier state, all worker errors and GTID progress.<\/li>\n<li>PostgreSQL: pg_stat_replication state\/sync_state and write\/flush\/replay LSN, standby receive\/replay state, retained WAL and slot availability.<\/li>\n<li>Archive failures, off-host backups and successful restores; WAL\/binlog disk capacity and disk latency.<\/li>\n<li>DCS quorum\/leader lease, fencing, proxy role checks and actual application write\/read\/reconnect probes.<\/li>\n<li>CPU, RAM, network loss and connection-pool pressure.<\/li>\n<\/ul>\n<p>You can build this with Prometheus + exporters + Grafana on a small VPS. We have a friendly starting point in <a href=\"https:\/\/www.dchost.com\/blog\/en\/vps-monitoring-prometheus-grafana-uptime-kuma\/\">VPS monitoring and alerts with Prometheus, Grafana and Uptime Kuma<\/a>. Alert not only on hard failures, but on <strong>trend warnings<\/strong> like increasing replication lag or WAL archive backlog.<\/p>\n<h3><span id=\"Disaster_Recovery_and_Failover_Drills\">Disaster Recovery and Failover Drills<\/span><\/h3>\n<p>Validate in an isolated environment first; production drills need an approved maintenance\/recovery plan. Re-run relevant cases when versions, capacity or network assumptions change.<\/p>\n<ul>\n<li>Exercise primary loss, network partitions, DCS majority loss, lagging replicas and full disks; stopping a service alone does not model a partition.<\/li>\n<li>Prove that the old primary cannot write and only one new writer is reachable; inspect controller and proxy behavior.<\/li>\n<li>Track unique transaction IDs and acknowledged commits to measure actual RPO; measure RTO through successful application operations, including pool reconnection and uncertain-commit handling.<\/li>\n<li>Restore a backup and reintegrate the old primary as a safe replica, checking schemas, routines, accounts and business invariants at corresponding GTID\/LSN points.<\/li>\n<\/ul>\n<p>pt-table-checksum writes checksum work on the source and has privilege, statement-logging and topology restrictions; validate support for the selected MySQL 8.4\/tool version before using it on a ROW topology. PostgreSQL pg_checksums inspects physical page checksums on a cleanly stopped cluster; it does not compare logical table contents between primary and standby.<\/p>\n<p>Our general DR planning article <a href=\"https:\/\/www.dchost.com\/blog\/en\/disaster-recovery-plan-rto-rpo-runbooks\/\">How I write a no\u2011drama DR plan<\/a> is a good companion read if you want to formalize this process.<\/p>\n<h2><span id=\"When_Replication_on_a_VPS_Is_and_Is_Not_the_Right_Choice\">When Replication on a VPS Is (and Is Not) the Right Choice<\/span><\/h2>\n<h3><span id=\"When_HA_Replication_Makes_Sense\">When HA Replication Makes Sense<\/span><\/h3>\n<p>Reasons to evaluate HA replication include:<\/p>\n<ul>\n<li>Your application generates direct revenue (e\u2011commerce, SaaS, booking platforms).<\/li>\n<li>Downtime during working hours is not acceptable for customers or internal teams.<\/li>\n<li>You already invested in caching and query optimization but still hit single-node limits.<\/li>\n<li>You need to reduce maintenance downtime, subject to database version compatibility and a tested upgrade path.<\/li>\n<\/ul>\n<p>Select the number of database, DCS, proxy and application nodes from the actual failure and durability targets. Two database nodes plus one helper can illustrate the design but do not guarantee end-to-end HA. When evaluating DCHost VPS, dedicated or colocation options, verify measured I\/O, independent failure domains, private networking, fencing\/VIP support and operational responsibilities for the chosen service.<\/p>\n<p>Related guide: <a href=\"https:\/\/www.dchost.com\/dedicated-server\">dedicated server<\/a>.<\/p>\n<h3><span id=\"When_a_Single_VPS_Strong_Backups_Is_Enough\">When a Single VPS + Strong Backups Is Enough<\/span><\/h3>\n<p>For small blogs, internal tools with low business impact, or early MVPs, HA may be overkill. In those cases:<\/p>\n<ul>\n<li>Run MySQL or PostgreSQL on a single, well\u2011sized VPS.<\/li>\n<li>Invest in <strong>good backups<\/strong>, automated restore tests, and careful schema migration practices.<\/li>\n<li>Plan an upgrade path: know when to add a read replica or separate database and application servers.<\/li>\n<\/ul>\n<p>The key is to design with <em>future HA<\/em> in mind: use connection strings, environment variables and configuration management that allow you to introduce proxies and replicas later without rewriting everything.<\/p>\n<h2><span id=\"Wrapping_Up_A_Practical_Path_to_HA_MySQLPostgreSQL_on_VPS\">Wrapping Up: A Practical Path to HA MySQL\/PostgreSQL on VPS<\/span><\/h2>\n<p>High availability on a VPS does not mean you need an enterprise-scale cluster from day one. It means being honest about your RPO\/RTO needs, designing a simple but solid topology, and gradually adding pieces: replication, a proxy, backup automation, monitoring, and tested failover procedures.<\/p>\n<p>For MySQL, validate the GTID seed, TLS channel, durability settings and manual recovery before adding automatic promotion. For PostgreSQL, validate streaming and recovery first, then plan a Patroni-managed lifecycle with genuine DCS quorum. In both cases test fencing, routing, old-primary return and application transaction recovery against explicit RPO\/RTO targets.<\/p>\n<p>Map data volume, recovery targets, off-host backups and independent failure domains to the actual DCHost infrastructure service you select. Add replicas, proxies and automation when measured needs and tested recovery behavior justify them.<\/p>\n<h2><span id=\"Primary_Technical_Sources\">Primary Technical Sources<\/span><\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.oracle.com\/cd\/E17952_01\/mysql-8.4-en\/mysqldump.html\" rel=\"nofollow noopener\" target=\"_blank\">MySQL 8.4: mysqldump<\/a><\/li>\n<li><a href=\"https:\/\/docs.oracle.com\/cd\/E17952_01\/mysql-8.4-en\/replication-encrypted-connections.html\" rel=\"nofollow noopener\" target=\"_blank\">MySQL 8.4: encrypted replication<\/a><\/li>\n<li><a href=\"https:\/\/docs.oracle.com\/cd\/E17952_01\/mysql-8.4-en\/replication-semisync.html\" rel=\"nofollow noopener\" target=\"_blank\">MySQL 8.4: semisynchronous replication<\/a><\/li>\n<li><a href=\"https:\/\/docs.oracle.com\/cd\/E17952_01\/mysql-shell-8.4-en\/mysql-innodb-cluster.html\" rel=\"nofollow noopener\" target=\"_blank\">MySQL Shell 8.4: InnoDB Cluster<\/a><\/li>\n<li><a href=\"https:\/\/www.postgresql.org\/docs\/17\/app-pgbasebackup.html\" rel=\"nofollow noopener\" target=\"_blank\">PostgreSQL 17: pg_basebackup<\/a><\/li>\n<li><a href=\"https:\/\/www.postgresql.org\/docs\/17\/runtime-config-wal.html\" rel=\"nofollow noopener\" target=\"_blank\">PostgreSQL 17: synchronous_commit<\/a><\/li>\n<li><a href=\"https:\/\/patroni.readthedocs.io\/en\/latest\/replication_modes.html\" rel=\"nofollow noopener\" target=\"_blank\">Patroni: replication modes<\/a><\/li>\n<li><a href=\"https:\/\/patroni.readthedocs.io\/en\/latest\/yaml_configuration.html\" rel=\"nofollow noopener\" target=\"_blank\">Patroni: configuration<\/a><\/li>\n<li><a href=\"https:\/\/etcd.io\/docs\/v3.5\/faq\/\" rel=\"nofollow noopener\" target=\"_blank\">etcd: quorum and failure tolerance<\/a><\/li>\n<li><a href=\"https:\/\/www.pgbouncer.org\/faq.html\" rel=\"nofollow noopener\" target=\"_blank\">PgBouncer: failover<\/a><\/li>\n<\/ul>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Build a version-scoped plan for MySQL GTID and PostgreSQL streaming replication, including consistent seeds, TLS, Patroni\/etcd quorum, fencing and application recovery.<\/p>\n","protected":false},"author":1,"featured_media":12563,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[],"class_list":["post-3565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/comments?post=3565"}],"version-history":[{"count":9,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3565\/revisions"}],"predecessor-version":[{"id":12565,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3565\/revisions\/12565"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/media\/12563"}],"wp:attachment":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/media?parent=3565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/categories?post=3565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/tags?post=3565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}