Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id A6ABA6327A8 for ; Sun, 8 Nov 2009 00:55:18 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 23836-04 for ; Sun, 8 Nov 2009 04:55:07 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtpauth23.prod.mesa1.secureserver.net (smtpauth23.prod.mesa1.secureserver.net [64.202.165.47]) by mail.postgresql.org (Postfix) with SMTP id D6DA763268E for ; Sun, 8 Nov 2009 00:55:07 -0400 (AST) Received: (qmail 7204 invoked from network); 8 Nov 2009 04:55:05 -0000 Received: from unknown (12.110.105.2) by smtpauth23.prod.mesa1.secureserver.net (64.202.165.47) with ESMTP; 08 Nov 2009 04:55:05 -0000 From: "Aris Samad-Yahaya" To: "'Craig Ringer'" Cc: References: <008801ca6021$c1cc7630$45656290$@com> <4AF63F5B.2060300@postnewspapers.com.au> In-Reply-To: <4AF63F5B.2060300@postnewspapers.com.au> Subject: Re: CREATE TABLE slowing down significantly over time Date: Sat, 7 Nov 2009 23:55:00 -0500 Message-ID: <009501ca602f$a13169e0$e3943da0$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcpgJj17xVyV6oFgRwKILOMjVnUUvwACOMDg Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=AWL=0.001, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/82 X-Sequence-Number: 36250 Hi Craig, Yes we do put the creation of the 300 tables into a single transaction. The difference between putting them in a single transaction and individual transactions is about 30 seconds over the 3 minutes. As for the creation of 300 individual tables for an account... yes we were trying to think through that issue very hard. It's the SaaS maturity levels discussion: How much do you separate the databases for each account, vs sharing customer information into large tables. I hear SalesForce puts most everything in giant tables, whereas we've decided to separate customer accounts into separate schemas. -----Original Message----- From: Craig Ringer [mailto:craig@postnewspapers.com.au] Sent: Saturday, November 07, 2009 10:48 PM To: Aris Samad-Yahaya Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] CREATE TABLE slowing down significantly over time On 8/11/2009 11:15 AM, Aris Samad-Yahaya wrote: > It used to take about 15 seconds to create those 300 tables in a new > schema (when there were only a few schemas, say about 50). It now takes > about 3 minutes (and now we have about 200 schemas, with more data but > not hugely so). 200 schemas, 300 tables per schema. That's sixty THOUSAND tables. > * Is the problem caused by the increasing number of schemas? and increasing table count, I expect. You do batch the table and schema creation into a single transaction, right? If not, do that first, rather than creating each table in a separate transaction (ie: relying on autocommit). It may also be worth thinking about the app's design. Is a new schema and 300 new tables for each user really the best way to tackle what you're doing? (It might be, but it's a question worth asking yourself). -- Craig Ringer