Mastodon Mastodon - Postgres - restore database with different owner
 logo
  • Home 
  • Tags 
  • Blog posts 
  1. Home
  2. Blog posts
  3. Postgres - restore database with different owner

Postgres - restore database with different owner

Posted on March 24, 2022  (Last modified on October 23, 2024) • 1 min read • 116 words
Postgres   Solved  
Postgres   Solved  
Share via

Situation:

  • You have a database
  • You want to “clone” this database into another database
  • That one should get a different owner

Go.

Step one, dump the database.

pg_dump -h database.host            \
  -U database_user                  \
  -W                                \
  -O -Ft                            \
  database                          \
  > database.dump.tar

Important here is -O, which means --no-owner, which means “do not include owner information.

Step two, restore the database. The database in which the dump file is restored has to exist. If you don’t know how to create it, see here.

pg_restore                          \
  -h database.host                  \
  -U different_database_user        \
  -W                                \
  -d different_database             \
  --no-owner                        \
  --role=different_database_user    \
   -Ft                              \
   database.dump.tar

DISCLAIMER: I have no idea if there is a better way. That just worked.

 "Old" K8S API reference docs
"Fix" Raindrop addon in Firefox 
In case you want to follow me

Here are some links. The further to the right, the less active.

           
(c) Axel Bock | Powered by Hinode.
Link copied to clipboard
Code copied to clipboard