Copy PostgreSQL with pg_dump
For a database of PostgreSQL, TotalSQL can write the copy with pg_dump, the tool of PostgreSQL itself, when your computer has it.
Why use it
Compared with the copy by TotalSQL, the one by pg_dump:
- has everything that the database holds, with its permissions;
- takes the whole database at one instant, also while others use it;
- can be a compressed archive, from which you restore everything or only some tables.
Install pg_dump
| System | How |
|---|---|
| macOS | With Homebrew: brew install libpq. Postgres.app and the installer of postgresql.org have it too |
| Windows | The installer of postgresql.org. "Command Line Tools" is enough |
| Debian, Ubuntu | sudo apt install postgresql-client |
| Fedora, RHEL | sudo dnf install postgresql |
There is nothing to set up. TotalSQL looks for it in the usual places, and uses the newest if there are several. It must be of the same version as the server, or newer.
Make the copy
- Open the connection, and press Export the database…
- In What to write, choose one:
- SQL file of everything, by pg_dump, to read it or run it with
psql; - Archive for pg_restore (.dump), by pg_dump, compressed.
- SQL file of everything, by pg_dump, to read it or run it with
What to write is there only when TotalSQL finds pg_dump. The copy goes by the same way as your connection, also through SSH, and you do not write the password again.
Restore it
Make an empty database first. For the SQL file:
psql --dbname=shop_copy --file=shop.sqlThe SQL file ofpg_dumpdoes not run in a query of TotalSQL, because its rows are written in a way that onlypsqlreads.
For the archive, whole or one table:
pg_restore --dbname=shop_copy shop.dump
pg_restore --dbname=shop_copy --table=orders shop.dumpAdd --host, --port and --username when the server is not the one of your computer.
If it fails
- The pg_dump of this computer (…) is older than the server: install the tools of the version of the server, or make the copy by TotalSQL, which still works.
- A message that begins with pg_dump: comes from the tool itself. Your user may lack permission to read some table.