array('RATIO', "select case when count(*)=3 then 'TRUE' else 'FALSE' end from pg_settings where (name='stats_block_level' or name='stats_row_level' or name='stats_start_collector') and setting='on' ", 'Value must be TRUE to enable hit ratio statistics (stats_start_collector,stats_row_level and stats_block_level must be set to true in postgresql.conf)'), 'data cache hit ratio' => array('RATIO', "select case when blks_hit=0 then 0 else (1-blks_read::float/blks_hit)*100 end from pg_stat_database where datname='\$DATABASE'", '=WarnCacheRatio'), 'IO', 'data reads' => array('IO', 'select sum(heap_blks_read+toast_blks_read) from pg_statio_user_tables', ), 'data writes' => array('IO', 'select sum(n_tup_ins/4.0+n_tup_upd/8.0+n_tup_del/4.0)/16 from pg_stat_user_tables', 'Count of inserts/updates/deletes * coef'), 'Data Cache', 'data cache buffers' => array('DATAC', "select setting from pg_settings where name='shared_buffers'", 'Number of cache buffers. Tuning'), 'cache blocksize' => array('DATAC', 'select 8192', '(estimate)' ), 'data cache size' => array( 'DATAC', "select setting::integer*8192 from pg_settings where name='shared_buffers'", '' ), 'operating system cache size' => array( 'DATA', "select setting::integer*8192 from pg_settings where name='effective_cache_size'", '(effective cache size)' ), 'Memory Usage', 'sort buffer size' => array('CACHE', "select setting::integer*1024 from pg_settings where name='sort_mem'", 'Size of sort buffer (per query)' ), 'Connections', 'current connections' => array('SESS', 'select count(*) from pg_stat_activity', ''), 'max connections' => array('SESS', "select setting from pg_settings where name='max_connections'", ''), 'Parameters', 'rollback buffers' => array('COST', "select setting from pg_settings where name='wal_buffers'", 'WAL buffers'), 'random page cost' => array('COST', "select setting from pg_settings where name='random_page_cost'", 'Cost of doing a seek (default=4). See random_page_cost'), false ); function perf_postgres(&$conn) { $this->conn =& $conn; } function Explain($sql) { $sql = str_replace('?',"''",$sql); $save = $this->conn->LogSQL(false); $s = '

Explain: '.htmlspecialchars($sql).'

'; $rs = $this->conn->Execute('EXPLAIN '.$sql); $this->conn->LogSQL($save); $s .= '
';
		if ($rs)
			while (!$rs->EOF) {
				$s .= reset($rs->fields)."\n";
				$rs->MoveNext();
			}
		$s .= '
'; $s .= $this->Tracer($sql); return $s; } } ?>