Can someone help me please? :)
Ive 2 servers, want to split databases in exclusive instances, so im migrating my databases 1 by 1 to second server
Postgres version 11.16 both servers
so here's my command on s1
pg_dump db1 > /tmp/db1.dump
then i restore on my s2:
psql -p 5432 db1 < /tmp/db1.dump
then i get this error
error: invalid value for parameter "default_tablestapce": "tbs_db1_index"
DETAIL: Tablespace "tbs_db1_index" does not exist
Thing is, db1 location on s1 is not the same as at s2, this might be the problem since i have no errors or any problems on s1 my db are fine
Also, restore process doesnt stop or breaks it is still in process(my db is huge)
PS and yes, i can do this directly without dumping file by this command
pg_dump --no-owner db1 | psql -p 5432 -v ON_ERROR_STOP=1 -h 192.168.1.2 -U postgres db1
but doesnt work either
-
So, what do you want to do? Preserve the tablespaces structure? Get rid of it?– jjanesCommented Sep 4, 2022 at 12:23
2 Answers
Tablespaces are not part of any database, so they are not included in pg_dump
output. If you want to dump and restore the tablespaces as well, use pg_dumpall -t
in addition of the pg_dump
you are performing (and restore the tablespaces first). If you want to ignore the tablespaces in the dump, use pg_dump --no-tablespaces
.
This is how i solved this:
drop existing tbs_db1_index AND tbs_db1_data (EVEN IF ITS EMPTY!), because when u create database this file are created in db directory
create new tablespaces with name as in old server
then this command works without problems on old server(s1)
pg_dump --no-owner db1 | psql -p 5432 -v ON_ERROR_STOP=1 -h 192.168.1.2 -U postgres db1
where 192.168.1.2 - address of targeted server, in my case its s2