Re: [PATCHES] ALTER TABLE ... SET TABLESPACE - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [PATCHES] ALTER TABLE ... SET TABLESPACE
Date
Msg-id 12077.1087785029@sss.pgh.pa.us
Whole thread Raw
In response to Re: [PATCHES] ALTER TABLE ... SET TABLESPACE  (Gavin Sherry <swm@linuxworld.com.au>)
Responses Re: [PATCHES] ALTER TABLE ... SET TABLESPACE
List pgsql-hackers
Gavin Sherry <swm@linuxworld.com.au> writes:
> But I did implement it as a tuple at a time thing. I reused the code from
> rebuild_relation()...

> What did you have in mind?

Something about like
for (b = 0; b < RelationGetNumberOfBlocks(src); b++){    smgrread(src, b, buf);    smgrwrite(dst, b, buf);}

Given that the only files people are going to be troubling to reassign
to new tablespaces are enormous ones, you'd want the transfer to be as
efficient as reasonably possible.

The main thing this is omitting is "what about wal-logging the move"?
Perhaps we could emit one WAL record showing the source and dest
RelFileNodes and number of blocks for the copy, and then LSN-stamp
each copied block with that record's LSN.  However I'm not sure how to
replay that if the source file isn't there anymore when the replay needs
to run :-(.  Maybe you have to dump each block into WAL as you copy it.
That would be kinda ugly ... though in point of fact less of a WAL load
than writing individual tuples ...
        regards, tom lane


pgsql-hackers by date:

Previous
From: Gavin Sherry
Date:
Subject: Re: [PATCHES] ALTER TABLE ... SET TABLESPACE
Next
From: Gavin Sherry
Date:
Subject: Re: [PATCHES] ALTER TABLE ... SET TABLESPACE