{"id":3342,"date":"2024-10-14T06:47:25","date_gmt":"2024-10-14T06:47:25","guid":{"rendered":"https:\/\/kedar.nitty-witty.com\/blog\/?p=3342"},"modified":"2024-10-14T08:22:04","modified_gmt":"2024-10-14T08:22:04","slug":"understanding-return-codes-of-pt-upgrade-a-quick-guide","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/understanding-return-codes-of-pt-upgrade-a-quick-guide","title":{"rendered":"Understanding Return Codes of pt-upgrade: A quick guide"},"content":{"rendered":"\n<p>Interpreting the results and exit codes of your upgrade tests is essential for assessing the process&#8217;s outcome. In this blog, we&#8217;ll explore the significance of pt-upgrade return codes and how to evaluate your upgrade tests effectively.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Unnecessary Background<\/h3>\n\n\n\n<p>&#8220;A friend of mine&#8221; recently told me that the pt-upgrade isn&#8217;t working and it is failing. The friend suggested that the tool is exiting with the return code of 4 for every execution.<br>I quickly opened the pt-upgrade git page, found information on return codes (exit status) and enlightened him from the information in source with a tip.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Don&#8217;t hesitate to open the source of your open source.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">What is pt-upgrade<\/h2>\n\n\n\n<p>pt-upgrade is part of the Percona Toolkit, which is specifically designed to help database administrators (DBAs) compare query performance between different versions of MySQL or MariaDB. It executes queries on both the current and upgraded versions of the database, allowing DBAs to identify any discrepancies in results, performance, or query execution behavior.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Query Classes and Differences<\/h3>\n\n\n\n<p>When pt-upgrade runs, it groups queries into &#8220;Query classes&#8221; based on their execution characteristics. This classification is crucial for identifying QUERY DIFFERENCES\u2014the discrepancies between the results returned by the queries on different versions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is query class?<\/h3>\n\n\n\n<p>That&#8217;s a query fingerprint. A query fingerprint is a unique identifier generated from a SQL query that captures its structure and semantics, but ignoring specific variable values or session-specific details. Later this structure is passed to hashing algorithm like SHA-1 or MD5. Specific to pt-upgrade you can see md5_hex.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">When queries are reported?<\/h3>\n\n\n\n<p>A query class is reported as soon as a predefined number of QUERY DIFFERENCES is reached. By default the &#8211;max-examples is defined as 3 to list a query as difference found.<\/p>\n\n\n\n<p>For example, if two differences in query execution time are identified, the class remains unreported until a third difference is found. This helps in reducing noise in the report, focusing only on significant discrepancies.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Output and Monitoring Progress<\/h2>\n\n\n\n<p>pt-upgrade generates output to STDOUT and STDERR. The report detailing the results is printed to STDOUT while warnings and errors are sent to STDERR. To keep the outputs separate and monitor progress efficiently, it is recommended to run the tool like so:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pt-upgrade ... 1>report 2>err &amp;\ntail -f err<\/code><\/pre>\n\n\n\n<p>This setup allows you to track ongoing operations while reviewing the results in real-time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Exit status or Return codes<\/h2>\n\n\n\n<p>It is typical for a consultant to evaluate the return code and look for 0 to feel confident. A non-zero return code typically means an error. That said, it is important to understand that every non-zero return code has their specific meanings and &#8220;assuming&#8221; failure of a tool is not right. The exit status codes from pt-upgrade provide insights into the execution outcome and potential issues.<\/p>\n\n\n\n<p>In general, the tool exits zero if it finishes normally and there were no internal warnings or errors, and no &#8220;QUERY DIFFERENCES&#8221; were found. Thus, it is very common to get a non-zero return code though that doesn&#8217;t mean that the tool did not do its stuff.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pt-upgrade return codes<\/h2>\n\n\n\n<p>For quick reference, here\u2019s the summarized table of return codes:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Exit Code<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>0<\/td><td>No errors; the upgrade is successful.<\/td><\/tr><tr><td>1<\/td><td>Too many internal errors or warnings; check STDERR.<\/td><\/tr><tr><td>4<\/td><td>There were QUERY DIFFERENCES; see the report.<\/td><\/tr><tr><td>8<\/td><td>&#8211;run-time expired; the tool did not finish reading the logs.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Reference: <a href=\"https:\/\/github.com\/percona\/percona-toolkit\/blob\/3.x\/bin\/pt-upgrade#L11047\">https:\/\/github.com\/percona\/percona-toolkit\/blob\/3.x\/bin\/pt-upgrade#L11047<\/a><\/p>\n\n\n\n<p>To check for specific exit codes, you can perform a logical AND operation with the final exit status. For example, if you receive an exit status of 5, it implies that codes 1 and 4 were also present, as both conditions are met (5 &amp; 1 and 5 &amp; 4 are true).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Understanding the return codes for determining your next steps are important. It\u2019s wise to refer to the documentation or code for a better understanding the meaning of these return codes. Let me know if you\u2019re using pt-upgrade for your upgrades and if you encounter any challenges. Here\u2019s wishing you smooth upgrades and plenty of 0 return codes!<\/p>\n","protected":false},"excerpt":{"rendered":"Interpreting the results and exit codes of your upgrade tests is essential for assessing the process&#8217;s outcome. In this blog, we&#8217;ll explore the significance of pt-upgrade return codes and how&hellip;\n","protected":false},"author":1,"featured_media":3343,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,867,6],"tags":[984,986,983,427,993,990,991,989,994],"class_list":{"0":"post-3342","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-mysql","8":"category-mysql-upgrade","9":"category-technical","10":"tag-database-upgrade","11":"tag-error-codes","12":"tag-exit-codes","13":"tag-mysql","14":"tag-open-source","15":"tag-percona-toolkit","16":"tag-pt-upgrade","17":"tag-query-performance","18":"tag-return-codes"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=3342"}],"version-history":[{"count":2,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3342\/revisions"}],"predecessor-version":[{"id":3345,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3342\/revisions\/3345"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media\/3343"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=3342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=3342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=3342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}