PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/openarkkit/doc/html/oak-hook-general-log.html

http://openarkkit.googlecode.com/
HTML | 273 lines | 235 code | 38 blank | 0 comment | 0 complexity | ea203e545303070d9512e0ebe6a343da MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title>oak-hook-general-log: openark kit documentation</title>
  6. <meta name="description" content="oak-hook-general-log: openark kit" />
  7. <meta name="keywords" content="oak-hook-general-log: openark kit" />
  8. <link rel="stylesheet" type="text/css" href="style.css" />
  9. </head>
  10. <body>
  11. <div id="main">
  12. <div id="header">
  13. <h1>openark kit documentation</h1>
  14. <div class="subtitle">Common utilities for MySQL</div>
  15. </div>
  16. <div id="contentwrapper">
  17. <div id="content">
  18. <h2><a href="oak-hook-general-log.html">oak-hook-general-log</a></h2>
  19. <h3>NAME</h3>
  20. oak-hook-general-log: hook up and filter general log entries based on entry type or execution plan criteria.
  21. <h3>SYNOPSIS</h3>
  22. Hook up the general log and dump everything:
  23. <blockquote>oak-hook-general-log --user=root --socket=/tmp/mysql.sock</blockquote>
  24. Only dump connect/disconnect events:
  25. <blockquote>oak-hook-general-log --user=root --socket=/tmp/mysql.sock --filter-connection</blockquote>
  26. Same as above, use defaults file:
  27. <blockquote>oak-hook-general-log --defaults-file=/home/myuser/.my-oak.cnf --filter-connection</blockquote>
  28. Only dump queries which make for a full table scan <i>and</i> use the City table:
  29. <blockquote>oak-hook-general-log --defaults-file=/home/myuser/.my-oak.cnf --filter-explain-fullscan --filter-explain-table=City</blockquote>
  30. Only dump queries which make for a filesort:
  31. <blockquote>oak-hook-general-log --defaults-file=/home/myuser/.my-oak.cnf --filter-explain-filesort</blockquote>
  32. Only dump queries which make for an implicit temporary table creation:
  33. <blockquote>oak-hook-general-log --defaults-file=/home/myuser/.my-oak.cnf --filter-explain-temporary</blockquote>
  34. Only dump queries where the execution plan expects at least <b>100,000</b> rows in any of the tables:
  35. <blockquote>oak-hook-general-log --defaults-file=/home/myuser/.my-oak.cnf --filter-explain-rows-exceed=100000</blockquote>
  36. Only dump queries where the execution plan expects at least <b>1,000,000</b> rows combined:
  37. <blockquote>oak-hook-general-log --defaults-file=/home/myuser/.my-oak.cnf --filter-explain-total-rows-exceed=1000000</blockquote>
  38. Only dump queries where the execution plan uses given index (`first_name` index on `authors` table):
  39. <blockquote>oak-hook-general-log --defaults-file=/home/myuser/.my-oak.cnf --filter-explain-key=actor.first_name</blockquote>
  40. Only dump queries where the execution plan contains given text anywhere (e.g. in key name, ref, etc.)
  41. This serves as a <i>grep</i> on the execution plan.
  42. <blockquote>oak-hook-general-log --defaults-file=/home/myuser/.my-oak.cnf --filter-explain-contains=my_column_name</blockquote>
  43. <h3>DESCRIPTION</h3>
  44. <p><i>oak-hook-general-log</i> hooks up to a MySQL >= 5.1 server, and dumps general log to standard output, allowing for sophisticated filtering.</p>
  45. <p>Query filtering relies not only on query text (for which <i>grep</i> or <i>awk</i> are good tools) but rather on query type and query execution plan.
  46. It is possible to only dump connect/disconnect queries; queries which make for a table scan; queries which scan more than <b>100,000</b> rows; or queries which use a specific index.
  47. </p>
  48. <p>The tool activates the server's <i>general log</i>, and instructs it to write to log table (<b>mysql.general_log</b>).
  49. The <b>general_log</b> table is periodically polled for new entries and rotated. Tool's output corresponds to the <b>general_log</b> table schema: </p>
  50. <blockquote><pre>mysql-5.1.51> DESC mysql.general_log;
  51. +--------------+------------------+------+-----+-------------------+-----------------------------+
  52. | Field | Type | Null | Key | Default | Extra |
  53. +--------------+------------------+------+-----+-------------------+-----------------------------+
  54. | event_time | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
  55. | user_host | mediumtext | NO | | NULL | |
  56. | thread_id | int(11) | NO | | NULL | |
  57. | server_id | int(10) unsigned | NO | | NULL | |
  58. | command_type | varchar(64) | NO | | NULL | |
  59. | argument | mediumtext | NO | | NULL | |
  60. +--------------+------------------+------+-----+-------------------+-----------------------------+
  61. </pre></blockquote>
  62. <p>A sample output may look like this:</p>
  63. <blockquote><pre>2010-12-07 11:30:23 root[root] @ localhost [] 8 1 Connect root@localhost on
  64. 2010-12-07 11:30:23 root[root] @ localhost [] 8 1 Query select 1
  65. 2010-12-07 11:30:39 root[root] @ localhost [] 8 1 Query show processlist
  66. 2010-12-07 11:30:45 root[root] @ localhost [] 8 1 Query desc mysql.general_log</pre></blockquote>
  67. <p>Activation of the <i>general_log</i>, and in particular writing to the <b>general_log</b> table makes for considerable overhead.
  68. The tool is configured to automatically terminate after one minute from the time of execution, or as configured by <b>--timeout-minutes</b>.
  69. Upon termination the tool restores original <i>general_log</i> settings.</p>
  70. <p>Interrupting the tool via Ctrl-C makes for a graceful termination, and original settings are restored. Any other means of termination
  71. (e.g. via <i>kill -9</i> results with the <i>general_log</i> remaining active. Make sure to disable it!</p>
  72. <p>The reason the <b>general_log</b> table is used is that the <i>general_log</i> file is in inconsistent format, and lacks some information such as user & host,
  73. which must be cross referenced to previous entries. This makes it impossible to diagnose existing connections when no log entries are present.</p>
  74. <p>Even so, the <b>general_log</b> table lacks the current database for the given connection, information which is critical to understanding the context of the query
  75. (this information <i>can</i> be found in the <b>slow_log</b> table). To overcome this limitation, <i>oak-hook-general-log</i> cross-references the general log
  76. entries with PROCESSLIST entries. There may still be mismatches, but on most situations this should work well.</p>
  77. <p>When asked to filter by execution plan criteria, <i>oak-hook-general-log</i> invokes an <b>EXPLAIN</b> query for each <b>SELECT</b> query encountered.
  78. This may further slow down your overall performance if execution plans are complicated. However, you should note it does not delay the execution of the query itself.
  79. In fact, the execution plan is calculated after the query is invoked.
  80. </p>
  81. <p>
  82. It is possible to specify multiple filter criteria. For a query to be logged, it must answer for <i>all</i> specified filters.
  83. </p>
  84. <h3>OPTIONS</h3>
  85. --ask-pass
  86. <p class="indent">Prompt for password.</p>
  87. --debug
  88. <p class="indent">Print stack trace on error.</p>
  89. --defaults-file=DEFAULTS_FILE
  90. <p class="indent">Read from MySQL configuration file. Overrides --user, --password, --socket, --port.</p>
  91. <p class="indent">Configuration needs to be in the following format:</p>
  92. <p class="indent"><strong>[client]<br/>
  93. user=my_user<br/>
  94. password=my_pass<br/>
  95. socket=/tmp/mysql.sock<br/>
  96. port=3306</strong>
  97. </p>
  98. --filter-connection
  99. <p class="indent">Only output connect/disconnect entries</p>
  100. --filter-explain-contains=FILTER_EXPLAIN_CONTAINS
  101. <p class="indent">
  102. Only output queries whose execution plan contains
  103. given text
  104. </p>
  105. --filter-explain-filesort
  106. <p class="indent">
  107. Only output queries where execution plan indicates
  108. filesort
  109. </p>
  110. --filter-explain-fulljoin
  111. <p class="indent">
  112. Only output queries where execution plan indicates
  113. full join
  114. </p>
  115. --filter-explain-fullscan
  116. <p class="indent">
  117. Only output queries where execution plan indicates
  118. </p>
  119. --filter-explain-indexscan
  120. <p class="indent">
  121. Only output queries where execution plan indicates
  122. full index scan
  123. </p>
  124. --filter-explain-key=FILTER_EXPLAIN_KEY
  125. <p class="indent">
  126. Only output queries where given key is used (specify
  127. key_name or table_name.key_name)
  128. </p>
  129. --filter-explain-rows-exceed=FILTER_EXPLAIN_ROWS_EXCEED
  130. <p class="indent">
  131. Only output queries where some path in the execution
  132. plan expects more than given number of rows scanned
  133. </p>
  134. --filter-explain-table=FILTER_EXPLAIN_TABLE
  135. <p class="indent">
  136. Only output queries where given table is used
  137. </p>
  138. --filter-explain-temporary
  139. <p class="indent">
  140. Only output queries where execution plan indicates use
  141. of temporary tables
  142. </p>
  143. --filter-explain-total-rows-exceed=FILTER_EXPLAIN_TOTAL_ROWS_EXCEED
  144. <p class="indent">
  145. Only output queries where execution plan expects at least as given total
  146. number of rows scanned
  147. </p>
  148. --filter-query
  149. <p class="indent">
  150. Only output queries
  151. </p>
  152. --filter-query-contains=FILTER_QUERY_CONTAINS
  153. <p class="indent">
  154. Only consider queries containing given text
  155. </p>
  156. -H HOST, --host=HOST
  157. <p class="indent">MySQL host (default: localhost)</p>
  158. --include-existing
  159. <p class="indent">
  160. Include possibly pre-existing entries in the general
  161. log table (default: disabled)
  162. </p>
  163. -p PASSWORD, --password=PASSWORD
  164. <p class="indent">MySQL password</p>
  165. -P PORT, --port=PORT
  166. <p class="indent">TCP/IP port (default: 3306)</p>
  167. -s SLEEP_TIME, --sleep-time=SLEEP_TIME
  168. <p class="indent">Number of seconds between log polling (default: 1)</p>
  169. -S SOCKET, --socket=SOCKET
  170. <p class="indent">MySQL socket file. Only applies when host is localhost</p>
  171. -t TIMEOUT_MINUTES, --timeout-minutes=TIMEOUT_MINUTES
  172. <p class="indent">Auto disconnect after given number of minutes (default: 1)</p>
  173. -u USER, --user=USER
  174. <p class="indent">MySQL user</p>
  175. -v, --verbose
  176. <p class="indent">Print user friendly messages</p>
  177. <h3>ENVIRONMENT</h3>
  178. Requires MySQL 5.1 or newer, python 2.3 or newer.
  179. python-mysqldb must be installed in order to use this tool. You can
  180. <blockquote>apt-get install python-mysqldb</blockquote>
  181. or
  182. <blockquote>yum install mysql-python</blockquote>
  183. <p>Please note that in MySQL versions &lt; <b>5.1.46</b> you may run into <a href="http://bugs.mysql.com/bug.php?id=49823">this bug</a>, in which MySQL
  184. allows for invalid <b>general_log</b> CSV tables. You may wish to either upgrade your MySQL version or issue:</p>
  185. <blockquote>mysql&gt; ALTER TABLE mysql.general_log ENGINE=MyISAM;</blockquote>
  186. <h3>SEE ALSO</h3>
  187. <h3>LICENSE</h3>
  188. This tool is released under the BSD license.
  189. <blockquote><pre>Copyright (c) 2008 - 2010, Shlomi Noach
  190. All rights reserved.
  191. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  192. * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  193. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  194. * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  195. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  196. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  197. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  198. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</pre>
  199. </blockquote>
  200. <h3>AUTHOR</h3>
  201. Shlomi Noach
  202. <br/>
  203. </div>
  204. <div id="sidebarwrapper">
  205. <div id="menu">
  206. <h3>openark kit tools</h3>
  207. <ul>
  208. <li><a title="Introduction" href="introduction.html">Introduction</a></li>
  209. <li><a title="Download" href="download.html">Download</a></li>
  210. <li><a title="Install" href="install.html">Install</a></li>
  211. <li><a title="oak-apply-ri" href="oak-apply-ri.html">oak-apply-ri</a></li>
  212. <li><a title="oak-block-account" href="oak-block-account.html">oak-block-account</a></li>
  213. <li><a title="oak-chunk-update" href="oak-chunk-update.html">oak-chunk-update</a></li>
  214. <li><a title="oak-get-slave-lag" href="oak-get-slave-lag.html">oak-get-slave-lag</a></li>
  215. <li><a title="oak-hook-general-log" href="oak-hook-general-log.html">oak-hook-general-log</a></li>
  216. <li><a title="oak-kill-slow-queries" href="oak-kill-slow-queries.html">oak-kill-slow-queries</a></li>
  217. <li><a title="oak-modify-charset" href="oak-modify-charset.html">oak-modify-charset</a></li>
  218. <li><a title="oak-online-alter-table" href="oak-online-alter-table.html">oak-online-alter-table</a></li>
  219. <li><a title="oak-prepare-shutdown" href="oak-prepare-shutdown.html">oak-prepare-shutdown</a></li>
  220. <li><a title="oak-purge-master-logs" href="oak-purge-master-logs.html">oak-purge-master-logs</a></li>
  221. <li><a title="oak-repeat-query" href="oak-repeat-query.html">oak-repeat-query</a></li>
  222. <li><a title="oak-security-audit" href="oak-security-audit.html">oak-security-audit</a></li>
  223. <li><a title="oak-show-limits" href="oak-show-limits.html">oak-show-limits</a></li>
  224. <li><a title="oak-show-replication-status" href="oak-show-replication-status.html">oak-show-replication-status</a></li>
  225. </ul>
  226. </div>
  227. </div>
  228. <div class="clear">&nbsp;</div>
  229. <div id="footnote" align="center">
  230. <a href="">openark kit</a> documentation
  231. </div>
  232. </div>
  233. </div>
  234. </body>
  235. </html>