V
V
vlarkanov2020-01-21 09:26:07
PostgreSQL
vlarkanov, 2020-01-21 09:26:07

How to move postgres db to another server?

Actually, subject. There is a dump made via pg_dump.
There are two questions:
1) In the off-doc it is written:

psql dbname < infile... The database dbname will not be created by this command, so you must create it yourself from template0 before executing psql (eg, with createdb -T template0 dbname).

Those. base must be created. Is it possible to see how the portable database was created (similar to SHOW CREATE DATABASE db_name in MySQL) or is it safe to create via createdb -T template0 dbname in all cases?
2) Again, in the off-doc it says:
Before restoring an SQL dump, all the users who own objects or were granted permissions on objects in the dumped database must already exist. If they do not, the restore will fail to recreate the objects with the original ownership and/or permissions. (Sometimes this is what you want, but usually it is not.

Those. the same users must be created as on the server with the portable database. How is it customary to transfer users, is it possible to automate the process?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Swartalf, 2020-01-21
@vlarkanov

1. \d public.some_table you will be able to see the description of the table. Not quite the same as in MySQL.
Yes, through createdb -T template0 you just create an empty database, for 95% of cases it’s enough with your head.
2. Yes, there should already be users, since there will be commands for distributing rights in the sql dump. You can watch it through \du или выбрать из вью pg_user, if you want more hard roots, then watch how this view is assembled and choose from the source.
3. If your postgres version and platform do not differ, then you can transfer it through a binary dump - pg_basebackup

O
oller, 2020-01-21
@oller

Backup do pg-basebackup

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question