2

我一直在尝试导入 postgres 转储(psql dbname < dump.sql及其变体,指定主机名和用户名等),但到目前为止我一直没有成功。

我是 Postgres 的新手,所以我可能在这里错过了明显的东西。根据导入命令的输出,扩展 plpgsql 可能不存在。我应该在导入之前设置 plpgsql 扩展吗?

以下是输出的前几行:

SET
ERROR:  unrecognized configuration parameter "lock_timeout"
SET
SET
SET
SET
CREATE EXTENSION
ERROR:  must be owner of extension plpgsql
ERROR:  could not open extension control file "/usr/share/postgresql/9.1/extension/hstore.control": No such file or directory
ERROR:  extension "hstore" does not exist
SET
SET
SET
ERROR:  relation "active_admin_comments" already exists
ERROR:  role "finalstep" does not exist
ERROR:  relation "active_admin_comments_id_seq" already exists
ERROR:  role "finalstep" does not exist
ALTER SEQUENCE
ERROR:  relation "admin_users" already exists
ERROR:  role "finalstep" does not exist

后来,看起来它正在尝试将一些内容作为 sql 查询执行(内容包含 mathml 标记):

ERROR:  syntax error at or near "</"
LINE 1: </mo> <msqrt>
        ^
ERROR:  syntax error at or near "&"
LINE 1: &nbsp;
        ^
ERROR:  syntax error at or near "</"
LINE 1: </mi> <mi>&alpha;

任何指针?我的 Postgres 版本是 9.1(最初是 9.3,但在看到错误消息后我将其降级为 9.1)。

4

1 回答 1

3

没有文件本身很难说。一些指示:

  • 如果可能的话,我会坚持使用9.3版。9.1 的许多改进,您将有更多时间再次升级。此外,第一条错误消息表明您仍然需要Postgres 9.3,因为 GUC(配置设置)lock_timeout是在 Postgres 9.3 中引入的。

  • psql-f开关一起使用以获得更详细的错误消息:

    psql dbname -f dump.sql
    

    (而且:-前面没有,我想这只是一个错字?)dbname-dbname

  • 如果您的安装没有损坏,语言plpgsql应该不是问题。 根据文档:

    在 PostgreSQL 9.0 及更高版本中,默认安装 PL/pgSQL。

  • 这些错误消息表明在操作系统级别从您的 contrib 包中读取文件时出现问题。

    ERROR:  must be owner of extension plpgsql
    ERROR:  could not open extension control file "/usr/share/postgresql/9.1/extension/hstore.control": No such file or directory
    ERROR:  extension "hstore" does not exist
    
    • 您需要为附加模块postgresql-contrib-9.1postgresql-contrib-9.3hstore. 此相关答案中的详细信息:
      在 PostgreSQL 上创建非重音扩展时出错

    • postgres启动 Postgres 的系统用户(通常是操作系统用户)必须可以访问这些文件。即,whoami在 shell 中键入时,答案应该是postgres.

    • 此外,您必须以超级用户身份执行 bash 命令,通常以postgres(DB 用户)身份执行。通常,如果您未指定用户名,并且IDENT/或PEER启用了身份验证(默认),则会自动使用与 OS 用户匹配的 DB 用户。此相关答案中的详细信息:
      Run batch file with psql command without password
于 2014-02-25T21:24:07.130 回答