Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C169C1337B4F for ; Mon, 29 Nov 2010 08:24:01 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 49601-05 for ; Mon, 29 Nov 2010 12:23:54 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from out.mail.amis.hr (out2.mail.amis.hr [188.129.0.5]) by mail.postgresql.org (Postfix) with ESMTP id E6DF41335B36 for ; Mon, 29 Nov 2010 08:23:53 -0400 (AST) Received: from out.fsec.sm.srv.amis.hr (out.fsec.sm.srv.amis.hr [192.168.106.22]) by out.mail.amis.hr (Postfix) with ESMTP id 329A1203FF; Mon, 29 Nov 2010 13:23:52 +0100 (CET) Received: from pps.filterd (out [127.0.0.1]) by out.fsec.sm.srv.amis.hr (8.14.3/8.14.3) with SMTP id oATCLu3Z007389; Mon, 29 Nov 2010 13:23:52 +0100 Received: from smtp.amis.hr (smtp.sm.srv.amis.hr [192.168.106.39]) by out.fsec.sm.srv.amis.hr with ESMTP id svab3g14t-1; Mon, 29 Nov 2010 13:23:51 +0100 A-Original-Client-UID: 188.129.73.52 splivalo Received: from [192.168.10.1] (cpe-188-129-73-52.dynamic.amis.hr [188.129.73.52]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: splivalo) by smtp.amis.hr (Postfix) with ESMTPSA id 8DF61273; Mon, 29 Nov 2010 13:23:51 +0100 (CET) Message-ID: <4CF39B57.9030306@megafon.hr> Date: Mon, 29 Nov 2010 13:23:51 +0100 From: Mario Splivalo User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Lightning/1.0b1 Thunderbird/3.0.10 MIME-Version: 1.0 To: Pierre C CC: pgsql-performance@postgresql.org Subject: Re: SELECT INTO large FKyed table is slow References: <4CF24103.8030209@megafon.hr> <4CF2A8A6.4010400@megafon.hr> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15, 1.0.148, 0.0.0000 definitions=2010-11-29_06:2010-11-29, 2010-11-29, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=6.0.2-1010190000 definitions=main-1011290039 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201011/396 X-Sequence-Number: 41420 On 11/28/2010 10:50 PM, Pierre C wrote: > >> I pasted DDL at the begining of my post. > > Ah, sorry, didn't see it ;) > >> The only indexes tables have are the ones created because of PK >> constraints. Table drones has around 100k rows. Table drones_history >> has around 30M rows. I'm not sure what additional info you'd want but >> I'll be more than happy to provide more relevant information. > > Can you post the following : > > - pg version > - output of VACCUM ANALYZE VERBOSE for your 2 tables Here it is: realm_51=# vacuum analyze verbose drones; INFO: vacuuming "public.drones" INFO: scanned index "drones_pk" to remove 242235 row versions DETAIL: CPU 0.02s/0.11u sec elapsed 0.28 sec. INFO: "drones": removed 242235 row versions in 1952 pages DETAIL: CPU 0.01s/0.02u sec elapsed 0.03 sec. INFO: index "drones_pk" now contains 174068 row versions in 721 pages DETAIL: 107716 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: "drones": found 486 removable, 174068 nonremovable row versions in 1958 out of 1958 pages DETAIL: 0 dead row versions cannot be removed yet. There were 64 unused item pointers. 0 pages are entirely empty. CPU 0.22s/0.90u sec elapsed 22.29 sec. INFO: vacuuming "pg_toast.pg_toast_2695558" INFO: index "pg_toast_2695558_index" now contains 0 row versions in 1 pages DETAIL: 0 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: "pg_toast_2695558": found 0 removable, 0 nonremovable row versions in 0 out of 0 pages DETAIL: 0 dead row versions cannot be removed yet. There were 0 unused item pointers. 0 pages are entirely empty. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: analyzing "public.drones" INFO: "drones": scanned 1958 of 1958 pages, containing 174068 live rows and 0 dead rows; 174068 rows in sample, 174068 estimated total rows VACUUM realm_51=# vacuum analyze verbose drones_history; INFO: vacuuming "public.drones_history" INFO: index "drones_history_pk" now contains 25440352 row versions in 69268 pages DETAIL: 0 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU 0.38s/0.12u sec elapsed 16.56 sec. INFO: "drones_history": found 0 removable, 16903164 nonremovable row versions in 129866 out of 195180 pages DETAIL: 0 dead row versions cannot be removed yet. There were 0 unused item pointers. 0 pages are entirely empty. CPU 2.00s/1.42u sec elapsed 49.24 sec. INFO: vacuuming "pg_toast.pg_toast_2695510" INFO: index "pg_toast_2695510_index" now contains 0 row versions in 1 pages DETAIL: 0 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: "pg_toast_2695510": found 0 removable, 0 nonremovable row versions in 0 out of 0 pages DETAIL: 0 dead row versions cannot be removed yet. There were 0 unused item pointers. 0 pages are entirely empty. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: analyzing "public.drones_history" INFO: "drones_history": scanned 195180 of 195180 pages, containing 25440352 live rows and 0 dead rows; 600000 rows in sample, 25440352 estimated total rows VACUUM realm_51=# select version(); version --------------------------------------------------------------------------------------------- PostgreSQL 8.4.2 on i686-pc-linux-gnu, compiled by GCC gcc (Debian 4.3.2-1.1) 4.3.2, 32-bit (1 row) Mario