innodb.lib.php 14 KB

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