stop reporting of a custom error (it is benign) to the php logfile
[openemr.git] / library / adodb / perf / perf-postgres.inc.php
blob2d5912ce5a16787aa84d1c75dff1d6418b01413b
1 <?php
3 /*
4 V4.20 22 Feb 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
5 Released under both BSD license and Lesser GPL library license.
6 Whenever there is any discrepancy between the two licenses,
7 the BSD license will take precedence. See License.txt.
8 Set tabs to 4 for best viewing.
10 Latest version is available at http://php.weblogs.com/
12 Library for basic performance monitoring and tuning
17 Notice that PostgreSQL has no sql query cache
19 class perf_postgres extends adodb_perf{
21 var $tablesSQL =
22 "select a.relname as tablename,(a.relpages+CASE WHEN b.relpages is null THEN 0 ELSE b.relpages END+CASE WHEN c.relpages is null THEN 0 ELSE c.relpages END)*8 as size_in_K,a.relfilenode as \"OID\" from pg_class a left join pg_class b
23 on b.relname = 'pg_toast_'||trim(a.relfilenode)
24 left join pg_class c on c.relname = 'pg_toast_'||trim(a.relfilenode)||'_index'
25 where a.relname in (select tablename from pg_tables where tablename not like 'pg_%')";
27 var $createTableSQL = "CREATE TABLE adodb_logsql (
28 created timestamp NOT NULL,
29 sql0 varchar(250) NOT NULL,
30 sql1 text NOT NULL,
31 params text NOT NULL,
32 tracer text NOT NULL,
33 timer decimal(16,6) NOT NULL
34 )";
36 var $settings = array(
37 'Ratios',
38 'statistics collector' => array('RATIO',
39 "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' ",
40 'Value must be TRUE to enable hit ratio statistics (<i>stats_start_collector</i>,<i>stats_row_level</i> and <i>stats_block_level</i> must be set to true in postgresql.conf)'),
41 'data cache hit ratio' => array('RATIO',
42 "select case when blks_hit=0 then 0 else (1-blks_read::float/blks_hit)*100 end from pg_stat_database where datname='\$DATABASE'",
43 '=WarnCacheRatio'),
44 'IO',
45 'data reads' => array('IO',
46 'select sum(heap_blks_read+toast_blks_read) from pg_statio_user_tables',
48 'data writes' => array('IO',
49 'select sum(n_tup_ins/4.0+n_tup_upd/8.0+n_tup_del/4.0)/16 from pg_stat_user_tables',
50 'Count of inserts/updates/deletes * coef'),
52 'Data Cache',
53 'data cache buffers' => array('DATAC',
54 "select setting from pg_settings where name='shared_buffers'",
55 'Number of cache buffers. <a href=http://www.varlena.com/GeneralBits/Tidbits/perf.html#basic>Tuning</a>'),
56 'cache blocksize' => array('DATAC',
57 'select 8192',
58 '(estimate)' ),
59 'data cache size' => array( 'DATAC',
60 "select setting::integer*8192 from pg_settings where name='shared_buffers'",
61 '' ),
62 'operating system cache size' => array( 'DATA',
63 "select setting::integer*8192 from pg_settings where name='effective_cache_size'",
64 '(effective cache size)' ),
65 'Memory Usage',
66 'sort buffer size' => array('CACHE',
67 "select setting::integer*1024 from pg_settings where name='sort_mem'",
68 'Size of sort buffer (per query)' ),
69 'Connections',
70 'current connections' => array('SESS',
71 'select count(*) from pg_stat_activity',
72 ''),
73 'max connections' => array('SESS',
74 "select setting from pg_settings where name='max_connections'",
75 ''),
76 'Parameters',
77 'rollback buffers' => array('COST',
78 "select setting from pg_settings where name='wal_buffers'",
79 'WAL buffers'),
80 'random page cost' => array('COST',
81 "select setting from pg_settings where name='random_page_cost'",
82 'Cost of doing a seek (default=4). See <a href=http://www.varlena.com/GeneralBits/Tidbits/perf.html#less>random_page_cost</a>'),
83 false
86 function perf_postgres(&$conn)
88 $this->conn =& $conn;
91 function Explain($sql,$partial=false)
93 $save = $this->conn->LogSQL(false);
95 if ($partial) {
96 $sqlq = $this->conn->qstr($sql.'%');
97 $arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like $sqlq");
98 if ($arr) {
99 foreach($arr as $row) {
100 $sql = reset($row);
101 if (crc32($sql) == $partial) break;
105 $sql = str_replace('?',"''",$sql);
106 $s = '<p><b>Explain</b>: '.htmlspecialchars($sql).'</p>';
107 $rs = $this->conn->Execute('EXPLAIN '.$sql);
108 $this->conn->LogSQL($save);
109 $s .= '<pre>';
110 if ($rs)
111 while (!$rs->EOF) {
112 $s .= reset($rs->fields)."\n";
113 $rs->MoveNext();
115 $s .= '</pre>';
116 $s .= $this->Tracer($sql,$partial);
117 return $s;