在 Linux 下使用 pgAdmin 导入(执行)SQL 脚本,常见有几种方式,下面按最常用 → 命令行补充给你说明。
.sql 脚本✅ 适合:小到中型 SQL 文件
注意:Restore 不是普通 SQL 脚本,而是
pg_dump生成的备份文件
.backup / .dump)❌ 不适合普通 .sql 文本脚本
如果你在 Linux 服务器上,更简单的是用 psql:
psql -U 用户名 -d 数据库名 -f 脚本.sql
示例:
psql -U postgres -d testdb -f /home/user/init.sql
如果提示密码:
export PGPASSWORD=你的密码
psql -U postgres -d testdb -f init.sql
psql -fpsql -U postgres -d testdb --single-transaction -f big.sql
脚本头部加:
SET client_encoding = 'UTF8';
确保用户有:
CREATE / INSERT / SELECT
权限
如果你愿意,可以告诉我:
我可以给你更精确的操作步骤。