pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedcopying databases w/ indexes
6+ messages / 3 participants
[nested] [flat]
* copying databases w/ indexes
@ 2003-08-14 17:35 Yuji Shinozaki <ys2n@virginia.edu>
0 siblings, 2 replies; 6+ messages in thread
From: Yuji Shinozaki @ 2003-08-14 17:35 UTC (permalink / raw)
To: pgsql-admin
I have two questions about restoring and moving databases (in pg 7.3), to
which I have not been able to find a suitable answers in the documentation
(and searching the list archives has been painfully slow and fruitless).
1) What is the fastest way to restore a database *with indexes*?
We have situation where I need to make a duplicate of a production
database for development work, so that we can develop code without
interfering with the production database. I use pg_dump for this, but I
have not been able to get pg_restore to work (usually because of
constraint problems). So I do the restores from a text dump piped into
psql (with all the constraints applied last). Then the problem is that
reindexing takes a very long time. One particular index is taking on the
order of 12 hours to finish.
Is there a way to dump and restore the index itself so that the tables do
not need to be reindexed? The dumps and restores are between identical
installations of postgres, sometimes even the same running instance of
postgres.
And a tangentially related question:
2) Is there a way to rename a database? That is the other thing that I
occasionally need to do, and the only way I have found is dump/restore,
and again we pay the penalty of the 12-hour reindexing.
Any pointers?
Thanks!
yuji
----
Yuji Shinozaki Computer Systems Senior Engineer
ys2n@virginia.edu Advanced Technologies Group
(434)924-7171 Information Technology & Communication
http://www.people.virginia.edu/~ys2n University of Virginia
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: copying databases w/ indexes
@ 2003-08-14 17:58 Sam Barnett-Cormack <s.barnett-cormack@lancaster.ac.uk>
parent: Yuji Shinozaki <ys2n@virginia.edu>
1 sibling, 1 reply; 6+ messages in thread
From: Sam Barnett-Cormack @ 2003-08-14 17:58 UTC (permalink / raw)
To: Yuji Shinozaki <ys2n@virginia.edu>; +Cc: pgsql-admin
On Thu, 14 Aug 2003, Yuji Shinozaki wrote:
>
> I have two questions about restoring and moving databases (in pg 7.3), to
> which I have not been able to find a suitable answers in the documentation
> (and searching the list archives has been painfully slow and fruitless).
>
> 1) What is the fastest way to restore a database *with indexes*?
>
> We have situation where I need to make a duplicate of a production
> database for development work, so that we can develop code without
> interfering with the production database. I use pg_dump for this, but I
> have not been able to get pg_restore to work (usually because of
> constraint problems). So I do the restores from a text dump piped into
> psql (with all the constraints applied last). Then the problem is that
> reindexing takes a very long time. One particular index is taking on the
> order of 12 hours to finish.
I've been dumping and restoring a very very big database, with indexes,
with no such problems. The table details that get dumped setup the
indexes, and AIUI the indexes are kept up-to-date as items are added.
--
Sam Barnett-Cormack
Software Developer | Student of Physics & Maths
UK Mirror Service (http://www.mirror.ac.uk) | Lancaster University
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: copying databases w/ indexes
@ 2003-08-14 19:29 Tom Lane <tgl@sss.pgh.pa.us>
parent: Yuji Shinozaki <ys2n@virginia.edu>
1 sibling, 1 reply; 6+ messages in thread
From: Tom Lane @ 2003-08-14 19:29 UTC (permalink / raw)
To: Yuji Shinozaki <ys2n@virginia.edu>; +Cc: pgsql-admin
Yuji Shinozaki <ys2n@virginia.edu> writes:
> Then the problem is that
> reindexing takes a very long time. One particular index is taking on the
> order of 12 hours to finish.
Seems like a lot. What is the index definition exactly, and how many
rows in the table? If it's a btree, have you tried increasing sort_mem
in the restore session?
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: copying databases w/ indexes
@ 2003-08-14 19:36 Yuji Shinozaki <ys2n@virginia.edu>
parent: Sam Barnett-Cormack <s.barnett-cormack@lancaster.ac.uk>
0 siblings, 0 replies; 6+ messages in thread
From: Yuji Shinozaki @ 2003-08-14 19:36 UTC (permalink / raw)
To: Sam Barnett-Cormack <s.barnett-cormack@lancaster.ac.uk>; +Cc: pgsql-admin
Aha! Thanks for the reply, because it got me thinking, and I reexamined
the schema and discovered that the problem was that we had a foreign key
constraint involving two columns of different type (varchar vs. integer!).
[Yeesh.] I think the type conversion was what was making reindexing (not
to mention inserts) slow!
Now the restore only takes about 20 minutes (yay!)
Thanks,
yuji
----
On Thu, 14 Aug 2003, Sam Barnett-Cormack wrote:
> On Thu, 14 Aug 2003, Yuji Shinozaki wrote:
>
> >
> > I have two questions about restoring and moving databases (in pg 7.3), to
> > which I have not been able to find a suitable answers in the documentation
> > (and searching the list archives has been painfully slow and fruitless).
> >
> > 1) What is the fastest way to restore a database *with indexes*?
> >
> > We have situation where I need to make a duplicate of a production
> > database for development work, so that we can develop code without
> > interfering with the production database. I use pg_dump for this, but I
> > have not been able to get pg_restore to work (usually because of
> > constraint problems). So I do the restores from a text dump piped into
> > psql (with all the constraints applied last). Then the problem is that
> > reindexing takes a very long time. One particular index is taking on the
> > order of 12 hours to finish.
>
> I've been dumping and restoring a very very big database, with indexes,
> with no such problems. The table details that get dumped setup the
> indexes, and AIUI the indexes are kept up-to-date as items are added.
>
> --
>
> Sam Barnett-Cormack
> Software Developer | Student of Physics & Maths
> UK Mirror Service (http://www.mirror.ac.uk) | Lancaster University
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
Yuji Shinozaki Computer Systems Senior Engineer
ys2n@virginia.edu Advanced Technologies Group
(434)924-7171 Information Technology & Communication
http://www.people.virginia.edu/~ys2n University of Virginia
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: copying databases w/ indexes
@ 2003-08-14 19:45 Yuji Shinozaki <ys2n@virginia.edu>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Yuji Shinozaki @ 2003-08-14 19:45 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin
See my other reply, but the problem was that I had a foreign key
constraint between an integer and varchar. (The column was a varchar and
the foreign key was an integer field). Seems to me postgres shouldn't
have allowed me to do this at all, but I guess it did a slow automatic
type conversion. So, reindexing was deathly slow. It also explains the
fact that inserts into this table were getting increasingly slow as the
table grew.
I manually changed the type in the dump and restoring takes about 20
minutes instead of 12 hours! Phew!
yuji
----
On Thu, 14 Aug 2003, Tom Lane wrote:
> Yuji Shinozaki <ys2n@virginia.edu> writes:
> > Then the problem is that
> > reindexing takes a very long time. One particular index is taking on the
> > order of 12 hours to finish.
>
> Seems like a lot. What is the index definition exactly, and how many
> rows in the table? If it's a btree, have you tried increasing sort_mem
> in the restore session?
>
> regards, tom lane
>
Yuji Shinozaki Computer Systems Senior Engineer
ys2n@virginia.edu Advanced Technologies Group
(434)924-7171 Information Technology & Communication
http://www.people.virginia.edu/~ys2n University of Virginia
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: copying databases w/ indexes
@ 2003-08-14 19:47 Tom Lane <tgl@sss.pgh.pa.us>
parent: Yuji Shinozaki <ys2n@virginia.edu>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2003-08-14 19:47 UTC (permalink / raw)
To: Yuji Shinozaki <ys2n@virginia.edu>; +Cc: pgsql-admin
Yuji Shinozaki <ys2n@virginia.edu> writes:
> See my other reply, but the problem was that I had a foreign key
> constraint between an integer and varchar. (The column was a varchar and
> the foreign key was an integer field). Seems to me postgres shouldn't
> have allowed me to do this at all, but I guess it did a slow automatic
> type conversion. So, reindexing was deathly slow.
There was some talk recently of spitting out a NOTICE when the
referenced columns aren't the same type as the referencing columns.
It's not done yet, but it's starting to seem like a good idea.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2003-08-14 19:47 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-14 17:35 copying databases w/ indexes Yuji Shinozaki <ys2n@virginia.edu>
2003-08-14 17:58 ` Sam Barnett-Cormack <s.barnett-cormack@lancaster.ac.uk>
2003-08-14 19:36 ` Yuji Shinozaki <ys2n@virginia.edu>
2003-08-14 19:29 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-08-14 19:45 ` Yuji Shinozaki <ys2n@virginia.edu>
2003-08-14 19:47 ` Tom Lane <tgl@sss.pgh.pa.us>
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