pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Iain <iain@mst.co.jp>
Cc: pgsql-admin@postgresql.org
Subject: Re: pg_restore TODO - delay PK creation
Date: Sun, 31 Oct 2004 21:36:06 -0500 (EST)
Message-ID: <200411010236.iA12a6V19009@candle.pha.pa.us> (raw)
In-Reply-To: <017501c4bfb9$a70b7f20$7201a8c0@mst1x5r347kymb>

Iain wrote:
> Hi,
> 
> I'm wondering if this is already on some todo list for pg_restore but I 
> didn't find any mention of it anywhere, so I thought I should post this and 
> see what people think..
> 
> Basically, I'd like to see an option at restore time to not include the 
> primary key constraint when issuing the create table command. I'd like the 
> PK to be added after data has been loaded using an ALTER command.
> 
> The principle reason for this is performance.
> 
> There may also be a bug somewhere, or perhaps just a problem with my system, 
> but I was trying to restore a fairly large table (over 7000000 rows) which 
> would run for a couple hours before failing. Dropping the PK enabled the 
> load to complete in 3 or 4 minutes. Adding the PK took another 3 or 4 
> minutes which adds up to quite a difference.

I don't know what PostgreSQL version you have but we currently do what
you suggest and I think have been doing it for a few releases now:

---------------------------------------------------------------------------

--
-- Name: test; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE test (
    x integer NOT NULL
);


ALTER TABLE public.test OWNER TO postgres;

--
-- Data for Name: test; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY test (x) FROM stdin;
1
\.


--
-- Name: test_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY test
    ADD CONSTRAINT test_pkey PRIMARY KEY (x);



-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



view thread (8+ messages)  latest in thread

Message-ID: <200411010236.iA12a6V19009@candle.pha.pa.us>
Permalink:  ../200411010236.iA12a6V19009@candle.pha.pa.us/
Also on:    postgresql.org/message-id/200411010236.iA12a6V19009@candle.pha.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: pgman@candle.pha.pa.us, iain@mst.co.jp
  Subject: Re: pg_restore TODO - delay PK creation
  In-Reply-To: <200411010236.iA12a6V19009@candle.pha.pa.us>
  References: <017501c4bfb9$a70b7f20$7201a8c0@mst1x5r347kymb> <200411010236.iA12a6V19009@candle.pha.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox