---
title: Copy PostgreSQL with pg_dump
project: TotalSQL
version: Latest
section: guides
language: en
license: 
url: https://totaljs.es/docs/totalsql/latest/guides/pg-dump/
updated: 2026-12-02T15:40:26.075Z
---

# 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](/totalsql/latest/guides/copy-a-database/), 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](https://brew.sh): `brew install libpq`. [Postgres.app](https://postgresapp.com) and the installer of [postgresql.org](https://www.postgresql.org/download/macosx/) have it too |
| Windows | The installer of [postgresql.org](https://www.postgresql.org/download/windows/). "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

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.
3. Leave **With the rows of every table** on, or turn it off to have only the structure.
4. 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:

```bash
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:

```bash
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.
