4 print sprintf(
"<title>%s</title>", isset(
$_GET[
'q'])?htmlspecialchars(
$_GET[
'q']):
'pginfo');
6 <style
type=
"text/css">
8 font-family: monospace;
11 background-color: darkgray;
14 background-color: lightgray;
16 .bar { text-align:right; }
20 <div
class=
"bar"><a href=
"#" onclick=
"window.location.reload()">refresh page</a></div>
23 define(
'PG_PAGE_SIZE', 8 * 1024);
25 include(
"../../../WHAT/Lib.Common.php");
29 $conn = pg_connect(
"service='$pgservice_core'");
30 if(
$conn ===
false ) {
37 $query[
'pg_settings'] = sprintf(
"SELECT name, setting, context, short_desc FROM pg_settings");
39 $query[
'pg_stat_activity'] = sprintf(
"SELECT datname, procpid, client_addr, client_port, waiting, query_start, now() - query_start AS time, current_query FROM pg_stat_activity WHERE procpid != pg_backend_pid()");
41 $query[
'tables'] = sprintf(
"SELECT s.schemaname, s.relname, c.oid, c.relfilenode, s.seq_scan, s.idx_scan, c.reltuples, c.relpages as pages FROM pg_stat_all_tables as s, pg_class as c WHERE s.relname = c.relname AND s.schemaname IN (SELECT nspname FROM pg_namespace WHERE oid = c.relnamespace) AND ( s.schemaname = 'public' OR s.schemaname = 'pg_toast' )");
43 $query[
'tables I/O'] = sprintf(
"SELECT schemaname, relname, heap_blks_read, heap_blks_hit, idx_blks_read, idx_blks_hit, toast_blks_read, toast_blks_hit, tidx_blks_read, tidx_blks_hit FROM pg_statio_all_tables WHERE schemaname IN ('public', 'pg_toast')");
45 $query[
'indexes'] = sprintf(
"SELECT s.schemaname, s.relname, s.indexrelname, c.oid, c.relfilenode, s.idx_scan, s.idx_tup_read, s.idx_tup_fetch, c.reltuples, c.relpages as pages FROM pg_stat_all_indexes as s, pg_class as c WHERE s.indexrelname = c.relname AND s.schemaname IN (SELECT nspname FROM pg_namespace WHERE oid = c.relnamespace) AND ( s.schemaname = 'public' OR s.schemaname = 'pg_toast' )");
47 $query[
'indexes I/O'] = sprintf(
"SELECT schemaname, relname, indexrelname, idx_blks_read, idx_blks_hit FROM pg_statio_all_indexes WHERE schemaname IN ('public', 'pg_toast')");
49 $query[
'vacuums'] = sprintf(
"SELECT s.schemaname, s.relname, c.reltuples, s.n_tup_ins, s.n_tup_upd, s.n_tup_del, s.n_tup_hot_upd, s.n_live_tup, s.n_dead_tup, s.last_vacuum, s.last_autovacuum FROM pg_stat_all_tables as s, pg_class as c WHERE s.relname = c.relname AND s.schemaname IN (SELECT nspname FROM pg_namespace WHERE oid = c.relnamespace) AND ( s.schemaname = 'public' OR s.schemaname = 'pg_toast' )");
51 $query[
'pg_buffercache'] = sprintf(
"SELECT c.relname, count(*) AS pages FROM pg_buffercache b INNER JOIN pg_class c ON b.relfilenode = c.relfilenode AND b.reldatabase IN (0, (SELECT oid FROM pg_database WHERE datname = current_database())) GROUP BY c.relname");
61 if( $parms[
'desc'] !=
'desc' && $parms[
'desc'] !=
'asc' ) {
62 $parms[
'desc'] =
'desc';
66 foreach(
$query as $k => $v ) {
67 $menu [] =
'<a href="?q='.htmlspecialchars($k).
'">'.htmlspecialchars($k).
'</a>';
69 print '<div class="menu"> '.join(
' | ',
$menu).
' </div>';
75 $orderby = $parms[
'orderby'];
76 $desc = $parms[
'desc'];
79 if( $orderby !=
'' ) {
80 $add = sprintf(
'ORDER BY "%s"', pg_escape_string($orderby));
82 $add = sprintf(
'%s %s', $add, pg_escape_string($desc));
86 $res = pg_prepare(
$conn,
'select', sprintf(
"%s %s",
$query, pg_escape_string($add)));
87 if( $res !==
false ) {
88 $res = pg_execute(
$conn,
'select', array());
90 if( $res ===
false ) {
91 print '<div class="error">';
97 $col_num = pg_num_fields($res);
98 $line_num = pg_num_rows($res);
101 for( $i = 0; $i < $col_num; $i++ ) {
102 $fields[$i] = pg_field_name($res, $i);
104 $desc = ($desc ==
'desc') ?
'asc' :
'desc';
106 print '<div class="table">';
109 foreach( $fields as $i => $name ) {
110 print '<td><a href="?q='.htmlspecialchars(
$q).
'&orderby='.htmlspecialchars($name).
'&desc='.htmlspecialchars($desc).
'">'.htmlspecialchars($name).
'</a></td>';
114 while( $row = pg_fetch_row($res) ) {
116 foreach( $fields as $i => $name ) {
118 if( $name ==
'pages' ) {
121 print '<td>'.htmlspecialchars($v).
'</td>';
130 function prettySize($bytes, $precision = 2) {
131 $units = array(
'B',
'KB',
'MB',
'GB',
'TB');
133 $bytes = max($bytes, 0);
134 $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
135 $pow = min($pow, count($units) - 1);
137 $bytes = $bytes / pow(1024, $pow);
139 return round($bytes, $precision) .
' ' . $units[$pow];
if(!isset($query[$parms['q']])) if($parms['desc']!= 'desc'&&$parms['desc']!= 'asc') $menu