Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 9F9952E0037 for ; Wed, 18 Jun 2008 13:18:12 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40363-02 for ; Wed, 18 Jun 2008 13:18:08 -0300 (ADT) 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.236]) by developer.postgresql.org (Postfix) with ESMTP id 100872E0055 for ; Wed, 18 Jun 2008 13:18:08 -0300 (ADT) Received: by rv-out-0506.google.com with SMTP id b25so6834677rvf.43 for ; Wed, 18 Jun 2008 09:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :content-type:content-transfer-encoding:mime-version:subject:date :x-mailer; bh=JdrdgKza55KlOUSMfAnsuEUkIRZ3ZoqnOnb88p4MdLg=; b=Znya1mKQb2yw3Ketc6VfET7cTh9f/BiABngeyE1O/G4X38Q4ZmEAmbWguKJFopUnO8 ff3EAK7N++Qg4WfhUDzy1n/pAu4kqF8Bs8Eg6L+krQDuHdQFOVuM1n0BY6K/bt2I8/d0 /ibCgka9bgX6CNJHzfd3Tqn8YB9w1ZfSshY+M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:content-type:content-transfer-encoding :mime-version:subject:date:x-mailer; b=szUA8AT2ME/g8BUJu6E2xDhVUovkBVj4aN1rJvEXNP8tVCCXyZuX78LLbagJo3AJx2 tFZc9r3qp9s/MiHi/Qw7vaByd4Y/mFXfyZA3CxUydjZd6S02J+Wgj8on8dFFcAnkhEp4 osNntZqOBzKorL6y7cIGj9Ul4QsoD3K73UGLI= Received: by 10.141.198.2 with SMTP id a2mr501050rvq.219.1213805888082; Wed, 18 Jun 2008 09:18:08 -0700 (PDT) Received: from ?172.31.3.21? ( [81.174.26.25]) by mx.google.com with ESMTPS id k2sm13049340rvb.4.2008.06.18.09.18.04 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 18 Jun 2008 09:18:06 -0700 (PDT) Message-Id: <29C5C371-FCE7-4271-AB9A-1C2A8CDDDFDE@gmail.com> From: Cisko <78cisko78@gmail.com> To: pgsql-performance@postgresql.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v924) Subject: Partial backup of linked tables Date: Wed, 18 Jun 2008 18:18:00 +0200 X-Mailer: Apple Mail (2.924) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200806/92 X-Sequence-Number: 30442 Hi, i'm new to this ML, i'll try to explain my issue: I've two tables defined as is (postgresql 8.1): CREATE TABLE table1 ( _id serial, num1 int4 not null, num2 int4 not null, primary key(_id) ); CREATE INDEX table1IDX1 ON table1(num1); CREATE TABLE table2 ( _id serial, _table1_id int not null, num3 int4 not null, num4 int4 not null, primary key(_id), foreign key(_table1_id) references table1(_id) on delete CASCADE ); CREATE INDEX table2IDX1 ON table2(_table1_id); I need to select only a subset of table1/table2 records and backup them (to disk). I proceed as following: 1. Create equivalent tables with _tmp name with indexes and cascade; CREATE TABLE table1_tmp ( _id serial, num1 int4 not null, num2 int4 not null, primary key(_id) ); CREATE INDEX table1_tmpIDX1 ON table1_tmp(num1); CREATE TABLE table2_tmp ( _id serial, _table1_id int not null, num3 int4 not null, num4 int4 not null, primary key(_id), foreign key(_table1_id) references table1_tmp(_id) on delete CASCADE ); CREATE INDEX table2_tmpIDX1 ON table2_tmp(_table1_id); 2. Select and insert into table1_tmp a subset of table1 based on a query (num1 < 10) INSERT INTO table1_tmp SELECT * from table1 WHERE num1 < 10; 3. Populate other tables with a foreign key; INSERT INTO table2_tmp SELECT table2.* from table2, table1_tmp WHERE table2._table1_id = table1_tmp._id; 4. Copy each table into a file (i don't have an 8.2, so that i can't execute pg_dump with several -t options) COPY table1_tmp TO "/tmp/table1_tmp.data"; COPY table2_tmp TO "/tmp/table2_tmp.data"; This is only an example, i've more complex tables, but schema is equivalent to previous. My question is: There'are some optimization/tips that i can do for achieve better performance? When i have several rows (10^6 or greater) returned by query into table1, that starts to hogs time and CPU. Doing an EXPLAIN, all queries on join are performed using indexes. Thanks in advance, Cisko