Re: [SQL] Newbie dbadmin out of his league

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] Newbie dbadmin out of his league
Дата
Msg-id 7648.935788758@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Newbie dbadmin out of his league  (Tim Pizey <tim@paneris.co.uk>)
Ответы Re: [SQL] Newbie dbadmin out of his league  ("Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>)
Re: [SQL] Newbie dbadmin out of his league  (Herouth Maoz <herouth@oumail.openu.ac.il>)
Список pgsql-sql
Tim Pizey <tim@paneris.co.uk> writes:
> 2. How do I use COPY?

>    Presumably I again have to take control of the key values,
>    drop the index
>    copy from tab delimited file containing hard ids
>    create id sequence
>    create index
>    modify id definition

Yup, that's about what you need to do.  You can leave the "DEFAULT"
clause where it is, since it won't be invoked during a COPY that's
supplying non-default values for the ID column.  (A good thing too,
since I don't think we support ALTER TABLE ADD DEFAULT...)

Just create the sequence with the right starting value (one past last
ID being loaded).  You can do that before or after the COPY, doesn't
matter.

A COPY will be way faster than a series of INSERT commands, especially
if each INSERT is invoking a nextval().  nextval() is great for
serializing live updates but it's pretty inefficient for a bulk-loading
situation.  Creating the index after the load is reputed to be faster
than building it incrementally, as well.

BTW, I believe pg_dump gets this right, so you could look at the script
generated by pg_dump of a small sample table for details.
        regards, tom lane


В списке pgsql-sql по дате отправления:

Предыдущее
От: Tim Pizey
Дата:
Сообщение: Newbie dbadmin out of his league
Следующее
От: Michael Richards
Дата:
Сообщение: RE: [SQL] 2 million+ entries