Spanish Total.js
English
Documentation For AI agents
Contents

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.

.md GitHub
On this page

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

SystemHow
macOSWith Homebrew: brew install libpq. Postgres.app and the installer of postgresql.org have it too
WindowsThe installer of postgresql.org. "Command Line Tools" is enough
Debian, Ubuntusudo apt install postgresql-client
Fedora, RHELsudo 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

  1. Open the connection, and press Export the database…
  2. 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.
  • Leave With the rows of every table on, or turn it off to have only the structure.
  • Press Choose where…
  • 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.sql
    The SQL file of pg_dump does not run in a query of TotalSQL, because its rows are written in a way that only psql reads.

    For the archive, whole or one table:

    pg_restore --dbname=shop_copy shop.dump
    pg_restore --dbname=shop_copy --table=orders shop.dump

    Add --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.
    Made in Europe