Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 57AFD64FDBB for ; Thu, 13 Nov 2008 16:42:44 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 02209-08 for ; Thu, 13 Nov 2008 16:42:34 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.225]) by mail.postgresql.org (Postfix) with ESMTP id E87D464FC39 for ; Thu, 13 Nov 2008 16:42:33 -0400 (AST) Received: by rv-out-0506.google.com with SMTP id b25so1002463rvf.43 for ; Thu, 13 Nov 2008 12:42:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=C+Kj3Pu3wjIi+0gdu+u238UJC3eIyL14ZfiH9TPlvwE=; b=jLpbDV9dPu8/hvJghnRKnox60Xn50ja3LPYYnXl9SSzJBhNY4ZqWCrEEFGc+VMnUG3 6fkFFakJlYuq4S8zLMduW1mGanUTY1jpxmyaED11aW2FZigeetrq6lz+Ic5qnfoc8QE+ Cc+1S957iIkiyC7Hiyet1git5ZAPoQ9b/bRFY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=K4/LGSXIwJ3t30NObq0VP2l0NKWcLJ7FXe16OrZw81Gpww2CLcTqj4k+GvGka++Hey pnfdH95uwCGH9MPb9Wed72cAtTDrMRC9uDAs2+DukNdtZ0G0DaNbIJMT/s8B7eX+rC8g V5Li2gJ+Mf2hPHG+4ipDjzOV+SUBSMiKoiNNs= Received: by 10.141.133.14 with SMTP id k14mr56515rvn.270.1226608952467; Thu, 13 Nov 2008 12:42:32 -0800 (PST) Received: by 10.140.200.8 with HTTP; Thu, 13 Nov 2008 12:42:32 -0800 (PST) Message-ID: Date: Thu, 13 Nov 2008 14:42:32 -0600 From: "Jeremiah Elliott" To: pgsql-performance@postgresql.org Subject: crosstab speed MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_9406_9159680.1226608952458" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200811/130 X-Sequence-Number: 31861 ------=_Part_9406_9159680.1226608952458 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline ok, I have an application that I am trying to speed up. Its a reporting application that makes heavy use of the crosstab function. Here is some of the setup / configuration details: Postgres 8.3.3 RedHat Enterprise 5.2 (2.6.18 kernel) sun x4600, 8 dual core opteron 8218 processors, 32BG, StorageTek SAN 6 15k FC disks raid 10 for data, 2 15k FC disks raid 1 for xlog, 2 10k SAS disks raid 1 for OS The table that I am querying has just under 600k records, 55 columns, 30 indexes The table is not static, there are several hundred inserts a day into it. This is not the only application that uses postgres on this server. There are several other transactional apps as well here is an example query select "COL_HEAD"[1] as site, "COL_HEAD"[2] as product_line_description, "COL_HEAD"[3] as report_sls, "COL_HEAD"[4] as fy_period, "2006" , "2007" , "2008" , "2009" from public.crosstab('select ARRAY[site::text,product_line_description::text,report_sls::text,fy_period::text] as COL_HEADER, fy_year, sum(invoice_value) from order_data_tbl where fy_year is not null group by site::text,product_line_description::text,report_sls::text,fy_period::text, fy_year order by site::text,product_line_description::text,report_sls::text,fy_period::text', 'select fy_year from order_data_tbl where fy_year is not null group by fy_year order by fy_year') as order_data_tbl("COL_HEAD" text[], "2006" numeric(20,2) , "2007" numeric(20,2) , "2008" numeric(20,2) , "2009" numeric(20,2) ) The crostab function is taking between 5 and 15 seconds to return. While the query is running one of the cores will be close to 100%, but watching iostat makes be believe that the entire table is cached and none of it is being read from disk. Depending on what report is being run the indexes may or may not be of any assistance. In the above query the planner does not use an index. Depending on what the user is looking for some indexes will be used because there is more specified in the where clause, at which point the query time can be under two seconds. The problem is that most reports that get generated with this application don't have a where clause. Are there any changes that can make to my config to speed up these huge aggregating queries? Here is my postgresql.conf max_connections = 1500 shared_buffers = 8GB work_mem = 2GB maintenance_work_mem = 8GB max_fsm_pages = 2048000 wal_buffers = 1024kB checkpoint_segments = 256 checkpoint_timeout = 10min effective_cache_size = 20GB default_statistics_target = 100 log_destination = 'stderr' logging_collector = on log_directory = 'pg_log' log_truncate_on_rotation = on log_rotation_age = 1d log_rotation_size = 1GB log_error_verbosity = default autovacuum = on autovacuum_max_workers = 9 datestyle = 'iso, mdy' lc_messages = 'en_US.UTF-8' lc_monetary = 'en_US.UTF-8' lc_numeric = 'en_US.UTF-8' lc_time = 'en_US.UTF-8' default_text_search_config = 'pg_catalog.english' synchronize_seqscans = on log_min_duration_statement = 250 -Jeremiah Elliott ------=_Part_9406_9159680.1226608952458 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ok, I have an application that I am trying to speed up. Its a reporting app= lication that makes heavy use of the crosstab function.

Here is som= e of the setup / configuration details:
Postgres 8.3.3
RedHat Enterpr= ise 5.2 (2.6.18 kernel)
sun x4600, 8 dual core opteron 8218 processors,  32BG, StorageTek SAN =
6 15k FC disks raid 10 for data,
2 15k FC disks raid 1 for xlog, 2 10k SAS disks raid 1 for OS
The table that I am querying has just u= nder 600k records, 55 columns, 30 indexes
The table is not static, there are several hundred inserts a day into it.This is not the only application that uses postgres on this server. There= are several other transactional apps as well

here is an example que= ry
  select "COL_HEAD"[1] as site, "COL_HEAD"[2] as p= roduct_line_description, "COL_HEAD"[3] as report_sls, "COL_H= EAD"[4] as fy_period, "2006"  , "2007"  = , "2008"  , "2009"   from public.crossta= b('select  ARRAY[site::text,product_line_description::text,report_= sls::text,fy_period::text] as COL_HEADER, fy_year, sum(invoice_value) from = order_data_tbl  where  fy_year is not null  group by site::t= ext,product_line_description::text,report_sls::text,fy_period::text, fy_yea= r order by site::text,product_line_description::text,report_sls::text,fy_pe= riod::text', 'select fy_year from order_data_tbl where   = fy_year is not null   group by fy_year  order by fy_year'= ;) as order_data_tbl("COL_HEAD" text[], "2006"  nu= meric(20,2) , "2007"  numeric(20,2) , "2008" = numeric(20,2) , "2009"  numeric(20,2) )

The crostab function is taking between 5 and 15 seconds to return. Whil= e the query is running one of the cores will be close to 100%, but watching= iostat makes be believe that the entire table is cached and none of it is = being read from disk. Depending on what report is being run the indexes may= or may not be of any assistance. In the above query the planner does not u= se an index. Depending on what the user is looking for some indexes will be= used because there is more specified in the where clause, at which point t= he query time can be under two seconds. The problem is that most reports th= at get generated with this application don't have a where clause. Are t= here any changes that can make to my config to speed up these huge aggregat= ing queries?

Here is my postgresql.conf

max_connections =3D 1500  &= nbsp;
shared_buffers =3D 8GB       
w= ork_mem =3D 2GB            maintenance_work_mem =3D 8GB   
max_fsm_pages =3D 20480= 00           
wal_buffers = =3D 1024kB           
checkpoint_segments =3D 256
checkpoint_timeout =3D 10min  &nbs= p;    
effective_cache_size =3D 20GB
default_statisti= cs_target =3D 100       
log_destination = =3D 'stderr'       
logging_colle= ctor =3D on       
log_directory =3D 'pg_log'        log_truncate_on_rotation =3D on
log_rotation_age =3D 1d  &nbs= p;    
log_rotation_size =3D 1GB
log_error_verbosity = =3D default
autovacuum =3D on
autovacuum_max_workers =3D 9
datesty= le =3D 'iso, mdy'
lc_messages =3D 'en_US.UTF-8'
lc_monetary =3D 'en_US.UTF-8&#= 39;   
lc_numeric =3D 'en_US.UTF-8'  &= nbsp;
lc_time =3D 'en_US.UTF-8'      &= nbsp;
default_text_search_config =3D 'pg_catalog.english'
synchronize_seqscans =3D on
log_min_duration_statement =3D 250

-Jeremiah Elliott
------=_Part_9406_9159680.1226608952458--