Innodb.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * The InnoDB storage engine
  5. *
  6. * @package PhpMyAdmin-Engines
  7. */
  8. namespace PhpMyAdmin\Engines;
  9. use PhpMyAdmin\StorageEngine;
  10. use PhpMyAdmin\Util;
  11. /**
  12. * The InnoDB storage engine
  13. *
  14. * @package PhpMyAdmin-Engines
  15. */
  16. class Innodb extends StorageEngine
  17. {
  18. /**
  19. * Returns array with variable names related to InnoDB storage engine
  20. *
  21. * @return array variable names
  22. */
  23. public function getVariables()
  24. {
  25. return array(
  26. 'innodb_data_home_dir' => array(
  27. 'title' => __('Data home directory'),
  28. 'desc' => __(
  29. 'The common part of the directory path for all InnoDB data '
  30. . 'files.'
  31. ),
  32. ),
  33. 'innodb_data_file_path' => array(
  34. 'title' => __('Data files'),
  35. ),
  36. 'innodb_autoextend_increment' => array(
  37. 'title' => __('Autoextend increment'),
  38. 'desc' => __(
  39. 'The increment size for extending the size of an autoextending '
  40. . 'tablespace when it becomes full.'
  41. ),
  42. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  43. ),
  44. 'innodb_buffer_pool_size' => array(
  45. 'title' => __('Buffer pool size'),
  46. 'desc' => __(
  47. 'The size of the memory buffer InnoDB uses to cache data and '
  48. . 'indexes of its tables.'
  49. ),
  50. 'type' => PMA_ENGINE_DETAILS_TYPE_SIZE,
  51. ),
  52. 'innodb_additional_mem_pool_size' => array(
  53. 'title' => 'innodb_additional_mem_pool_size',
  54. 'type' => PMA_ENGINE_DETAILS_TYPE_SIZE,
  55. ),
  56. 'innodb_buffer_pool_awe_mem_mb' => array(
  57. 'type' => PMA_ENGINE_DETAILS_TYPE_SIZE,
  58. ),
  59. 'innodb_checksums' => array(),
  60. 'innodb_commit_concurrency' => array(),
  61. 'innodb_concurrency_tickets' => array(
  62. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  63. ),
  64. 'innodb_doublewrite' => array(),
  65. 'innodb_fast_shutdown' => array(),
  66. 'innodb_file_io_threads' => array(
  67. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  68. ),
  69. 'innodb_file_per_table' => array(),
  70. 'innodb_flush_log_at_trx_commit' => array(),
  71. 'innodb_flush_method' => array(),
  72. 'innodb_force_recovery' => array(),
  73. 'innodb_lock_wait_timeout' => array(
  74. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  75. ),
  76. 'innodb_locks_unsafe_for_binlog' => array(),
  77. 'innodb_log_arch_dir' => array(),
  78. 'innodb_log_archive' => array(),
  79. 'innodb_log_buffer_size' => array(
  80. 'type' => PMA_ENGINE_DETAILS_TYPE_SIZE,
  81. ),
  82. 'innodb_log_file_size' => array(
  83. 'type' => PMA_ENGINE_DETAILS_TYPE_SIZE,
  84. ),
  85. 'innodb_log_files_in_group' => array(
  86. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  87. ),
  88. 'innodb_log_group_home_dir' => array(),
  89. 'innodb_max_dirty_pages_pct' => array(
  90. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  91. ),
  92. 'innodb_max_purge_lag' => array(),
  93. 'innodb_mirrored_log_groups' => array(
  94. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  95. ),
  96. 'innodb_open_files' => array(
  97. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  98. ),
  99. 'innodb_support_xa' => array(),
  100. 'innodb_sync_spin_loops' => array(
  101. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  102. ),
  103. 'innodb_table_locks' => array(
  104. 'type' => PMA_ENGINE_DETAILS_TYPE_BOOLEAN,
  105. ),
  106. 'innodb_thread_concurrency' => array(
  107. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  108. ),
  109. 'innodb_thread_sleep_delay' => array(
  110. 'type' => PMA_ENGINE_DETAILS_TYPE_NUMERIC,
  111. ),
  112. );
  113. }
  114. /**
  115. * Returns the pattern to be used in the query for SQL variables
  116. * related to InnoDb storage engine
  117. *
  118. * @return string SQL query LIKE pattern
  119. */
  120. public function getVariablesLikePattern()
  121. {
  122. return 'innodb\\_%';
  123. }
  124. /**
  125. * Get information pages
  126. *
  127. * @return array detail pages
  128. */
  129. public function getInfoPages()
  130. {
  131. if ($this->support < PMA_ENGINE_SUPPORT_YES) {
  132. return array();
  133. }
  134. $pages = array();
  135. $pages['Bufferpool'] = __('Buffer Pool');
  136. $pages['Status'] = __('InnoDB Status');
  137. return $pages;
  138. }
  139. /**
  140. * returns html tables with stats over inno db buffer pool
  141. *
  142. * @return string html table with stats
  143. */
  144. public function getPageBufferpool()
  145. {
  146. // The following query is only possible because we know
  147. // that we are on MySQL 5 here (checked above)!
  148. // side note: I love MySQL 5 for this. :-)
  149. $sql
  150. = '
  151. SHOW STATUS
  152. WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\'
  153. OR Variable_name = \'Innodb_page_size\';';
  154. $status = $GLOBALS['dbi']->fetchResult($sql, 0, 1);
  155. $output = '<table class="data" id="table_innodb_bufferpool_usage">' . "\n"
  156. . ' <caption class="tblHeaders">' . "\n"
  157. . ' ' . __('Buffer Pool Usage') . "\n"
  158. . ' </caption>' . "\n"
  159. . ' <tfoot>' . "\n"
  160. . ' <tr>' . "\n"
  161. . ' <th colspan="2">' . "\n"
  162. . ' ' . __('Total') . "\n"
  163. . ' : '
  164. . Util::formatNumber(
  165. $status['Innodb_buffer_pool_pages_total'],
  166. 0
  167. )
  168. . '&nbsp;' . __('pages')
  169. . ' / '
  170. . join(
  171. '&nbsp;',
  172. Util::formatByteDown(
  173. $status['Innodb_buffer_pool_pages_total']
  174. * $status['Innodb_page_size']
  175. )
  176. ) . "\n"
  177. . ' </th>' . "\n"
  178. . ' </tr>' . "\n"
  179. . ' </tfoot>' . "\n"
  180. . ' <tbody>' . "\n"
  181. . ' <tr>' . "\n"
  182. . ' <th>' . __('Free pages') . '</th>' . "\n"
  183. . ' <td class="value">'
  184. . Util::formatNumber(
  185. $status['Innodb_buffer_pool_pages_free'],
  186. 0
  187. )
  188. . '</td>' . "\n"
  189. . ' </tr>' . "\n"
  190. . ' <tr>' . "\n"
  191. . ' <th>' . __('Dirty pages') . '</th>' . "\n"
  192. . ' <td class="value">'
  193. . Util::formatNumber(
  194. $status['Innodb_buffer_pool_pages_dirty'],
  195. 0
  196. )
  197. . '</td>' . "\n"
  198. . ' </tr>' . "\n"
  199. . ' <tr>' . "\n"
  200. . ' <th>' . __('Pages containing data') . '</th>' . "\n"
  201. . ' <td class="value">'
  202. . Util::formatNumber(
  203. $status['Innodb_buffer_pool_pages_data'],
  204. 0
  205. ) . "\n"
  206. . '</td>' . "\n"
  207. . ' </tr>' . "\n"
  208. . ' <tr>' . "\n"
  209. . ' <th>' . __('Pages to be flushed') . '</th>' . "\n"
  210. . ' <td class="value">'
  211. . Util::formatNumber(
  212. $status['Innodb_buffer_pool_pages_flushed'],
  213. 0
  214. ) . "\n"
  215. . '</td>' . "\n"
  216. . ' </tr>' . "\n"
  217. . ' <tr>' . "\n"
  218. . ' <th>' . __('Busy pages') . '</th>' . "\n"
  219. . ' <td class="value">'
  220. . Util::formatNumber(
  221. $status['Innodb_buffer_pool_pages_misc'],
  222. 0
  223. ) . "\n"
  224. . '</td>' . "\n"
  225. . ' </tr>';
  226. // not present at least since MySQL 5.1.40
  227. if (isset($status['Innodb_buffer_pool_pages_latched'])) {
  228. $output .= ' <tr>'
  229. . ' <th>' . __('Latched pages') . '</th>'
  230. . ' <td class="value">'
  231. . Util::formatNumber(
  232. $status['Innodb_buffer_pool_pages_latched'],
  233. 0
  234. )
  235. . '</td>'
  236. . ' </tr>';
  237. }
  238. $output .= ' </tbody>' . "\n"
  239. . '</table>' . "\n\n"
  240. . '<table class="data" id="table_innodb_bufferpool_activity">' . "\n"
  241. . ' <caption class="tblHeaders">' . "\n"
  242. . ' ' . __('Buffer Pool Activity') . "\n"
  243. . ' </caption>' . "\n"
  244. . ' <tbody>' . "\n"
  245. . ' <tr>' . "\n"
  246. . ' <th>' . __('Read requests') . '</th>' . "\n"
  247. . ' <td class="value">'
  248. . Util::formatNumber(
  249. $status['Innodb_buffer_pool_read_requests'],
  250. 0
  251. ) . "\n"
  252. . '</td>' . "\n"
  253. . ' </tr>' . "\n"
  254. . ' <tr>' . "\n"
  255. . ' <th>' . __('Write requests') . '</th>' . "\n"
  256. . ' <td class="value">'
  257. . Util::formatNumber(
  258. $status['Innodb_buffer_pool_write_requests'],
  259. 0
  260. ) . "\n"
  261. . '</td>' . "\n"
  262. . ' </tr>' . "\n"
  263. . ' <tr>' . "\n"
  264. . ' <th>' . __('Read misses') . '</th>' . "\n"
  265. . ' <td class="value">'
  266. . Util::formatNumber(
  267. $status['Innodb_buffer_pool_reads'],
  268. 0
  269. ) . "\n"
  270. . '</td>' . "\n"
  271. . ' </tr>' . "\n"
  272. . ' <tr>' . "\n"
  273. . ' <th>' . __('Write waits') . '</th>' . "\n"
  274. . ' <td class="value">'
  275. . Util::formatNumber(
  276. $status['Innodb_buffer_pool_wait_free'],
  277. 0
  278. ) . "\n"
  279. . '</td>' . "\n"
  280. . ' </tr>' . "\n"
  281. . ' <tr>' . "\n"
  282. . ' <th>' . __('Read misses in %') . '</th>' . "\n"
  283. . ' <td class="value">'
  284. . ($status['Innodb_buffer_pool_read_requests'] == 0
  285. ? '---'
  286. : htmlspecialchars(
  287. Util::formatNumber(
  288. $status['Innodb_buffer_pool_reads'] * 100
  289. / $status['Innodb_buffer_pool_read_requests'],
  290. 3,
  291. 2
  292. )
  293. ) . ' %') . "\n"
  294. . '</td>' . "\n"
  295. . ' </tr>' . "\n"
  296. . ' <tr>' . "\n"
  297. . ' <th>' . __('Write waits in %') . '</th>' . "\n"
  298. . ' <td class="value">'
  299. . ($status['Innodb_buffer_pool_write_requests'] == 0
  300. ? '---'
  301. : htmlspecialchars(
  302. Util::formatNumber(
  303. $status['Innodb_buffer_pool_wait_free'] * 100
  304. / $status['Innodb_buffer_pool_write_requests'],
  305. 3,
  306. 2
  307. )
  308. ) . ' %') . "\n"
  309. . '</td>' . "\n"
  310. . ' </tr>' . "\n"
  311. . ' </tbody>' . "\n"
  312. . '</table>' . "\n";
  313. return $output;
  314. }
  315. /**
  316. * returns InnoDB status
  317. *
  318. * @return string result of SHOW ENGINE INNODB STATUS inside pre tags
  319. */
  320. public function getPageStatus()
  321. {
  322. return '<pre id="pre_innodb_status">' . "\n"
  323. . htmlspecialchars(
  324. $GLOBALS['dbi']->fetchValue('SHOW ENGINE INNODB STATUS;', 0, 'Status')
  325. ) . "\n"
  326. . '</pre>' . "\n";
  327. }
  328. /**
  329. * returns string with filename for the MySQL helppage
  330. * about this storage engine
  331. *
  332. * @return string mysql helppage filename
  333. */
  334. public function getMysqlHelpPage()
  335. {
  336. return 'innodb-storage-engine';
  337. }
  338. /**
  339. * Gets the InnoDB plugin version number
  340. *
  341. * @return string the version number, or empty if not running as a plugin
  342. */
  343. public function getInnodbPluginVersion()
  344. {
  345. return $GLOBALS['dbi']->fetchValue('SELECT @@innodb_version;');
  346. }
  347. /**
  348. * Gets the InnoDB file format
  349. *
  350. * (do not confuse this with phpMyAdmin's storage engine plugins!)
  351. *
  352. * @return string the InnoDB file format
  353. */
  354. public function getInnodbFileFormat()
  355. {
  356. return $GLOBALS['dbi']->fetchValue(
  357. "SHOW GLOBAL VARIABLES LIKE 'innodb_file_format';",
  358. 0,
  359. 1
  360. );
  361. }
  362. /**
  363. * Verifies if this server supports the innodb_file_per_table feature
  364. *
  365. * (do not confuse this with phpMyAdmin's storage engine plugins!)
  366. *
  367. * @return boolean whether this feature is supported or not
  368. */
  369. public function supportsFilePerTable()
  370. {
  371. return (
  372. $GLOBALS['dbi']->fetchValue(
  373. "SHOW GLOBAL VARIABLES LIKE 'innodb_file_per_table';",
  374. 0,
  375. 1
  376. ) == 'ON'
  377. );
  378. }
  379. }