How to migrate postgres DB to another server?

Actually, a subject. There is a dump made using pg_dump.
There are two questions:
1) In off the dock 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 (e.g., with createdb -T template0 dbname).

I.e., the database must be created. Is it possible to see how was created the portable database (similar to SHOW CREATE DATABASE db_name MySQL) or all instances can be safely created using createdb -T template0 dbname ?

2) Again, in off the dock it is written:
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.

Ie needs to be created the same users on the server from the portable database. As they migrate users, is it possible to automate the process?
April 4th 20 at 13:07
2 answers
April 4th 20 at 13:09
1. \d public.some_table you can see the description of the table. Not exactly what in MySQL.
Yes using createdb -T template0 you just create an empty database, for 95% of cases with the head missing.
2. Yes, users must already be, as in the sql dump will be the team on the distribution rights. You can see through \du or choose from pg_user view, if you want more hadcore, and then see how this is going and choose view source.
3. If you have a version of Postgres and platform don't differ, then can be transferred using the binary dump pg_basebackup
Regarding point 2: do I need users? On the server I transferred the database will only use one superuser for all databases, delineation is not necessary (it's a dev server). Or when zalitye dump error? - zander commented on April 4th 20 at 13:12
bugs will not be able to give rights for a not existing user, but the recovery process is not affected, as it will appoint the owner of the postgres user.
they would not be better to remove the sql dump using pg_dump --no-owner - tressa_Hilll commented on April 4th 20 at 13:15
@tressa_Hilll, got it, thanks! - zander commented on April 4th 20 at 13:18
April 4th 20 at 13:11
Backup do pg-basebackup

Find more questions by tags PostgreSQLDatabase administration