{"id":6732,"date":"2014-03-06T11:12:49","date_gmt":"2014-03-06T09:12:49","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=6732"},"modified":"2014-03-06T11:38:44","modified_gmt":"2014-03-06T09:38:44","slug":"the-once-and-for-all-show-slave-status-log-files-positions-explained","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/the-once-and-for-all-show-slave-status-log-files-positions-explained","title":{"rendered":"The &#8220;once and for all&#8221; SHOW SLAVE STATUS log files &#038; positions explained"},"content":{"rendered":"<p>True, GTID is upon us whether via MySQL 5.6 or Tungsten Replicator (and wasn&#8217;t it in Google Patches since 2009?).<\/p>\n<p>But some of us are still using standard replication with MySQL 5.5, and the &#8220;what&#8217;s with all these binary log files and positions&#8221; question is ever erupting. The output of <strong>SHOW SLAVE STATUS<\/strong> confuses people new to it. It confuses me time and again.<\/p>\n<p>So here&#8217;s the semi visual guide to interpreting the <strong>SHOW SLAVE STATUS<\/strong>.<\/p>\n<h4>About binary logs and relay logs<\/h4>\n<p>A master writes binary logs. These are typically and conventionally called <strong>mysql-bin.#####<\/strong> or <strong>mysqld-bin.#####<\/strong> (replace ##### with digits).<\/p>\n<p>A slave connects to its master, and reads entries from the master&#8217;s binary logs. The slave writes those entries into its own relay logs. These are typically and conventionally called <strong>mysql-relay.#####<\/strong> or <strong>mysqld-relay.#####<\/strong> (replace ##### with digits).<\/p>\n<p>There is nothing at all that connects the name or number of a slave&#8217;s relay log with the master&#8217;s binary log. There is nothing at all that connects the position within the relay log with the position within the master binary log. Files are flushed\/rotated; have different size configuration; are re-created. However the slave does keep track on the current relay-log entry: it knows what&#8217;s the matching entry on the master&#8217;s binary logs. This is an important piece of information.<\/p>\n<p>While the slave fetches entries and writes them into the relay log (via the <strong>IO_THREAD<\/strong>), it also reads the relay log to replay those entries (via the <strong>SQL_THREAD<\/strong>).<\/p>\n<p>And so at each point in time we are interested in the following &#8220;coordinates&#8221;:<\/p>\n<ul>\n<li>What are we fetching from the master? Which file are we fetching and from which position?<\/li>\n<li>Where are we writing this to? (This is implicitly the latest relay log file and its size)<\/li>\n<li>What&#8217;s the position of currently executing slave query, in relay-log coordinates? As the slave lags these coordinates are farther (smaller) than the written-to position.<\/li>\n<li>What&#8217;s the position of currently executing slave query, in master binary-log coordinates? This information really tells us how far apart we are from the master.<!--more--><\/li>\n<\/ul>\n<p>How do we interpret the above from <strong>SHOW SLAVE STATUS<\/strong> output? Take the following two images as guidelines. The first presents an up-to-date slave, the second presents a lagging slave.<\/p>\n<blockquote><p><a href=\"http:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/03\/slave_status_explained_uptodate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6734\" alt=\"slave_status_explained_uptodate\" src=\"http:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/03\/slave_status_explained_uptodate.png\" width=\"677\" height=\"636\" srcset=\"https:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/03\/slave_status_explained_uptodate.png 677w, https:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/03\/slave_status_explained_uptodate-300x281.png 300w\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" \/><\/a><\/p><\/blockquote>\n<blockquote><p><a href=\"http:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/03\/slave_status_explained_lagging.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6735\" alt=\"slave_status_explained_lagging\" src=\"http:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/03\/slave_status_explained_lagging.png\" width=\"677\" height=\"636\" srcset=\"https:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/03\/slave_status_explained_lagging.png 677w, https:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/03\/slave_status_explained_lagging-300x281.png 300w\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" \/><\/a><\/p><\/blockquote>\n<p>Hopefully this &#8220;once and for all&#8221; explanation will last a couple weeks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>True, GTID is upon us whether via MySQL 5.6 or Tungsten Replicator (and wasn&#8217;t it in Google Patches since 2009?). But some of us are still using standard replication with MySQL 5.5, and the &#8220;what&#8217;s with all these binary log files and positions&#8221; question is ever erupting. The output of SHOW SLAVE STATUS confuses people [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[5],"tags":[8],"class_list":["post-6732","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-replication"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-1KA","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/comments?post=6732"}],"version-history":[{"count":10,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6732\/revisions"}],"predecessor-version":[{"id":6744,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6732\/revisions\/6744"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=6732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=6732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=6732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}