sql - 导入没有角色的postgres数据库

标签 sql database postgresql import psql

我有一个用 pg_dump 导出的数据库,但现在当我试图用以下命令再次导入它时:

psql -d databasename < mydump.sql

尝试将角色授予不存在的人时失败。 (错误提示“角色“xxx”不存在”)

有没有办法为我的用户自动导入和设置所有角色?

最佳答案

导入的默认行为是用您正在导入的角色替换它不知道的所有角色。因此,根据您需要数据库的用途,您可能只需导入它并忽略错误消息即可。

引自http://www.postgresql.org/docs/9.2/static/backup-dump.html#BACKUP-DUMP-RESTORE

Before restoring an SQL dump, all the users who own objects or were granted permissions on objects in the dumped database must already exist. If they do not, the restore will fail to recreate the objects with the original ownership and/or permissions. (Sometimes this is what you want, but usually it is not.)

关于sql - 导入没有角色的postgres数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17153008/

相关文章:

postgresql - 星火 SQL 2.0 : NullPointerException with a valid PostgreSQL query

sql - 结果在 SQL 查询中获取 NULL

mysql - 如何比较两个表并显示每个差异

mysql - 我将如何正确构建该数据库?

postgresql - 临时 Postgres 表过早丢失

perl - 允许 unix 用户 'postgres' 访问 plperlu 的外部 .pm 文件

java - JDBC 中 Types.NULL 的使用

mysql - SQL 添加列一个唯一的哈希

sql - 如何在编辑后将文本框查询结果保存到数据库? - 微软 Access

c++ - C数据库线程安全