patternsqlModerate
Postgresql: Move database to new tablespace
Viewed 0 times
postgresqltablespacenewdatabasemove
Problem
I'd like to completely move a database (tables, indexes, etc.) to a new tablespace. I know how to move each item individually but is there a way to move it all in one go? I'm using postgresql 9.1.
Solution
ALTER DATABASE name SET TABLESPACE new_tablespaceExcerpt from the docs:
... changes the default tablespace of the database. Only the database owner or a superuser can do this; you must also have create privilege for the new tablespace. This command physically moves any tables or indexes in the database's old default tablespace to the new tablespace. Note that tables and indexes in non-default tablespaces are not affected.
Code Snippets
ALTER DATABASE name SET TABLESPACE new_tablespaceContext
StackExchange Database Administrators Q#11851, answer score: 18
Revisions (0)
No revisions yet.