Re: Sequences not moved to new tablespace

From: Guillaume Drolet <droletguillaume(at)gmail(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Sequences not moved to new tablespace
Date: 2015-02-24 15:06:53
Message-ID: CAOkiyv7VXpygV=eeny-S-VbZavTLdAgOsJxqYf=feT0k4FrGNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2015-02-24 8:45 GMT-05:00 Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>:

> Guillaume Drolet wrote:
> > Digging a little more, I found that not only sequences were not moved
> but also many tables in
> > pg_catalog are still in my old tablespace. This is expected since the
> query in the SQL files I used to
> > move the tables and indexes had a WHERE clause like this:
> >
> > SELECT ' ALTER TABLE ' || schemaname || '.' || tablename || ' SET
> TABLESPACE pg_default;'
> > FROM pg_tables
> > WHERE schemaname NOT IN ('pg_catalog', 'information_schema');
> >
> > So I tried removing the WHERE clause and running the script again:
> > psql -U postgres -d mydb < move_tables_to_pg_default.sql | findstr /R
> /C:"[ALTER]" | psql -d mydb -U
> > postgres
> >
> > I got many errors like this one:
> > ERROR: permission denied: "pg_event_trigger" is a system catalog
> >
> > If I can't move tables from pg_catalog, how will I be able to drop that
> tablespace I don't want to use
> > anymore?
> >
> > I am thinking that maybe using "ALTER DATABASE mydb SET TABLESPACE
> pg_default;" instead would take
> > care of all this, no?
> >
> > But when I tried it last week, I got a message like: some relations
> already in target tablespace...
> >
> > Any help will be much appreciated.
>
> If you want to move a whole database to a different tablespace (the only
> reason
> I can think of for doing what you are trying to so), use the command
> ALTER DATABASE ... SET TABLESPACE ...
>

Thanks Laurenz. I tried your suggestion:

psql -U postgres -c "ALTER DATABASE mydb SET TABLESPACE pg_default;"

I get this message:

ERROR: some relations of database "mortalite" are already in tablespace
"pg_default"
HINT : You must move them back to the database's default tablespace before
using this command.

But if I do "SHOW default_tablespace;" in mydb, it showed "pg_default" as
the default tablespace.

So I tried changing it back to the tablespace I want to get rid of to
subsequently moved everything back there so that ultimately, it lets me
move everything to pg_default:

ALTER DATABASE mydb SET default_tablespace = diamonds;

And then:

psql -U postgres -c "ALTER DATABASE mydb SET TABLESPACE diamonds;"

ALTER DATABASE is issued but nothing gets physically moved to diamonds. Why?

> Yours,
> Laurenz Albe
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Drolet 2015-02-24 15:10:11 Re: Sequences not moved to new tablespace
Previous Message Adrian Klaver 2015-02-24 15:06:31 Re: Sequences not moved to new tablespace