{"id":24931,"date":"2023-05-03T15:58:53","date_gmt":"2023-05-03T13:58:53","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=24931"},"modified":"2023-05-03T16:03:18","modified_gmt":"2023-05-03T14:03:18","slug":"mariadb-manual-switchover","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/","title":{"rendered":"MariaDB manual Switchover"},"content":{"rendered":"\n<p>I\u2019m going to explain how to do a manual Switchover in a MariaDB HA setups using master-slave replication.<\/p>\n\n\n\n<p>In my example, let\u2019s consider that I\u2019ve a server01 and server02, both running on Ubuntu 20.04.<\/p>\n\n\n\n<p>server02 is currently the master, server01 the slave.<\/p>\n\n\n\n<p>We\u2019ll perform a switchover to come back to a normal status, meaning server01 as master and server02 as slave.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Stop all the connections to the DB<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>root@server02:~# mysql\nmysql&gt; flush tables with read lock;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Recovering information from the master<\/h3>\n\n\n\n<p>Note the values for the parameters File and Position.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@server02:~# mysql\nmysql&gt; SHOW MASTER STATUS\\G;\n\n***** 1. row *****\nFile: mysql-bin.007747\nPosition: 5512879\nBinlog_Do_DB:\nBinlog_Ignore_DB:\nExecuted_Gtid_Set:\n1 row in set (0.00 sec)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Check slave status<\/h3>\n\n\n\n<p>We check that the replication is working properly and that the values for the parameters Master_Log_File and Read_Master_Log_Pos correspond to the values noted in point 1.3.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@server01:~# mysql\nmysql&gt; SHOW SLAVE STATUS\\G;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Stop slave and do the Switchover<\/h3>\n\n\n\n<p>From this step, the slave should switch back to master.<\/p>\n\n\n\n<p>Stop the slave, reset the slave configuration to 0, reset the master configuration to 0 and switch over.<\/p>\n\n\n\n<p>Finally we check that the changes have been made.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@server01:~# mysql\nmysql&gt; STOP SLAVE;\nmysql&gt; reset slave all;\nmysql&gt; RESET MASTER;\nmysql&gt; SHOW SLAVE STATUS\\G;\nmysql&gt; SHOW MASTER STATUS\\G<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Change configuration in my.cnf<\/h3>\n\n\n\n<p>In the configuration of the instance, we set the slave as read only and the opposite for the master.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>### On Master ###\nroot@server01:~# cd \/etc\/mysql\/\nroot@server01:\/etc\/mysql# vi mysql.conf.d\/mysqld.cnf\n\n# In my.cnf:\nread_only=0\nsuper_read_only=0\n\n### On slave ###\nroot@server02:~# cd \/etc\/mysql\/\nroot@server02:\/etc\/mysql# vi mysql.conf.d\/mysqld.cnf\n\n# In my.cnf:\nread_only=1\nsuper_read_only=1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Restart mysql service<\/h3>\n\n\n\n<p>Restart the service to apply the changes in my.cnf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>### On Master ###\n# Stop the MySQL service\nroot@server01:~# systemctl stop mysql.service\n\n# Start the MySQL service\nroot@server01:~# systemctl start mysql.service\n\n### On slave ###\n# Stop the MySQL service\nroot@server02:~# systemctl stop mysql.service\n\n# Start the MySQL service\nroot@server02:~# systemctl start mysql.service<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure replication on new slave<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>root@server02:~# mysql\nmysql&gt; CHANGE MASTER TO MASTER_HOST='MASTER IP', MASTER_USER='repl', MASTER_PASSWORD='***';\nmysql&gt; START SLAVE;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">VIP address swap<\/h3>\n\n\n\n<p>If the VIP address is on the server with the slave instance, we set up the VIP on the server with the master instance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>### On Slave ###\nroot@server02:~# ip addr del VIP.AD.DR.ESS\/28 dev ens160\n\n### On Master ###\nroot@server01:~# ip addr add VIP.AD.DR.ESS\/28 dev ens160\n\n### If blocked by firewall ###\niptables -I INPUT -i ens160 -d VIP.AD.DR.ESS -p icmp --icmp-type echo-request -j ACCEPT<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>The cluster is now back to a normal status, with server01 as master and server02 as slave.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m going to explain how to do a manual Switchover in a MariaDB HA setups using master-slave replication. In my example, let\u2019s consider that I\u2019ve a server01 and server02, both running on Ubuntu 20.04. server02 is currently the master, server01 the slave. We\u2019ll perform a switchover to come back to a normal status, meaning server01 [&hellip;]<\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,198,1726],"tags":[2947,141,2946,754,857],"type_dbi":[],"class_list":["post-24931","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-database-management","category-mariadb","tag-manual","tag-mariadb","tag-over","tag-switch","tag-switchover"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>MariaDB manual Switchover - dbi Blog<\/title>\n<meta name=\"description\" content=\"How to do a manual Switchover in a MariaDB HA setups using master-slave replication\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MariaDB manual Switchover\" \/>\n<meta property=\"og:description\" content=\"How to do a manual Switchover in a MariaDB HA setups using master-slave replication\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-03T13:58:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-03T14:03:18+00:00\" \/>\n<meta name=\"author\" content=\"Joan Frey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joan Frey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/\"},\"author\":{\"name\":\"Joan Frey\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/c03c47649664fe73b27ce457e99f5b06\"},\"headline\":\"MariaDB manual Switchover\",\"datePublished\":\"2023-05-03T13:58:53+00:00\",\"dateModified\":\"2023-05-03T14:03:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/\"},\"wordCount\":249,\"commentCount\":2,\"keywords\":[\"manual\",\"MariaDB\",\"over\",\"SWITCH\",\"switchover\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Database management\",\"MariaDB\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/\",\"name\":\"MariaDB manual Switchover - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"datePublished\":\"2023-05-03T13:58:53+00:00\",\"dateModified\":\"2023-05-03T14:03:18+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/c03c47649664fe73b27ce457e99f5b06\"},\"description\":\"How to do a manual Switchover in a MariaDB HA setups using master-slave replication\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/mariadb-manual-switchover\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MariaDB manual Switchover\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/c03c47649664fe73b27ce457e99f5b06\",\"name\":\"Joan Frey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g\",\"caption\":\"Joan Frey\"},\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/joanfrey\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"MariaDB manual Switchover - dbi Blog","description":"How to do a manual Switchover in a MariaDB HA setups using master-slave replication","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/","og_locale":"en_US","og_type":"article","og_title":"MariaDB manual Switchover","og_description":"How to do a manual Switchover in a MariaDB HA setups using master-slave replication","og_url":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/","og_site_name":"dbi Blog","article_published_time":"2023-05-03T13:58:53+00:00","article_modified_time":"2023-05-03T14:03:18+00:00","author":"Joan Frey","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joan Frey","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/"},"author":{"name":"Joan Frey","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06"},"headline":"MariaDB manual Switchover","datePublished":"2023-05-03T13:58:53+00:00","dateModified":"2023-05-03T14:03:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/"},"wordCount":249,"commentCount":2,"keywords":["manual","MariaDB","over","SWITCH","switchover"],"articleSection":["Database Administration &amp; Monitoring","Database management","MariaDB"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/","url":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/","name":"MariaDB manual Switchover - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2023-05-03T13:58:53+00:00","dateModified":"2023-05-03T14:03:18+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06"},"description":"How to do a manual Switchover in a MariaDB HA setups using master-slave replication","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/mariadb-manual-switchover\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"MariaDB manual Switchover"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06","name":"Joan Frey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g","caption":"Joan Frey"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/joanfrey\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/24931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=24931"}],"version-history":[{"count":11,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/24931\/revisions"}],"predecessor-version":[{"id":24949,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/24931\/revisions\/24949"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=24931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=24931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=24931"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=24931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}