← 返回命令列表

Linux command

pg_dumpall 命令

文件

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Dump all databases

pg_dumpall > [backup.sql]

Dump only roles and tablespaces

pg_dumpall --globals-only > [globals.sql]

Dump specific host

pg_dumpall -h [hostname] -U [username] > [backup.sql]

Compressed backup

pg_dumpall | gzip > [backup.sql.gz]

说明

pg_dumpall extracts all PostgreSQL databases including cluster-wide objects like roles and tablespaces. Unlike pg_dump, it handles the entire cluster. Output is a SQL script that can be restored with psql.

参数

-h, --host _host_
Database server host.
-U, --username _name_
Connect as user.
-p, --port _port_
Server port.
-g, --globals-only
Only roles and tablespaces.
-r, --roles-only
Only roles.
-t, --tablespaces-only
Only tablespaces.
--clean
Add DROP statements.
-f _file_
Output file.

FAQ

What is the pg_dumpall command used for?

pg_dumpall extracts all PostgreSQL databases including cluster-wide objects like roles and tablespaces. Unlike pg_dump, it handles the entire cluster. Output is a SQL script that can be restored with psql.

How do I run a basic pg_dumpall example?

Run `pg_dumpall > [backup.sql]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -h, --host _host_ do in pg_dumpall?

Database server host.