在 Ubuntu 上使用 pgAdmin 恢复(还原)PostgreSQL 数据,通常有两种常见场景:恢复整个数据库备份(如 .sql / .dump) 和 恢复表数据。下面分步骤说明。
你之前用 pgAdmin 或 pg_dump 导出了:
.sql 文件.backup / .dump 文件Custom or tar → 对应 .dump / .backupPlain → 对应 .sql✅ 如果数据库不存在:
如果 pgAdmin 恢复失败,推荐用命令行:
sudo -u postgres psql dbname < backup.sql
或(压缩文件):
gunzip -c backup.sql.gz | sudo -u postgres psql dbname
如果你只有表数据:
COPY table_name FROM '/path/to/file.csv' DELIMITER ',' CSV HEADER;
或使用 Restore 时:
permission denied
解决:
sudo -u postgres pg_restore ...
role "xxx" does not exist
解决:
CREATE ROLE xxx LOGIN PASSWORD 'pwd';
解决:
pg_restore 命令行如果你能告诉我:
我可以给你更精确的操作步骤。