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