i'm tring to backup my database from production machine to a standby machine.
My production machine is a debian (unspecified version) distro
My standby machine is a ubuntu 20.10 distro
After some readings across the internet here is what i was able to accomplish
- pg_dump -h 123.123.123.123 -p 5432 my_db > my_db.bak -> check
- psql < createDateabase.sql -> check this make a simple drop/create database my_db owner my_db_backup;
- psql < my_db.back -> check
so far so good
- connect with my sqlworkbench to db -> check
- use table imported -> ehm, not check
the problem is the ownership of the tables and sequeces. When imported, postgres is their owner but i want my_db_backup as owner insted.
I have tryed, as a workaround, to
- alter table xxx OWNER TO my_db_backup; - > check for each table
- alter sequence if exists xxx OWNER TO my_db_backup; -> it takes forever and it is unable to finish;
the command for the final stage (change ownership) is psql < finalize.sql
and finalize.sql is
\connect my_db;
ALTER TABLE xxx OWNER TO my_db_backup;
ALTER SEQUENCE IF EXISTS seq_xxx OWNER TO my_db_backup; -- this takes forever
what i'm missing?
I would prefer to import directly with the right owner instead of altering owner after, but that's still acceptable as long as i can change all objects in my_db
tnx for the help