【问题标题】:How to fix psql SYNTAX error when trying to migrate using a tar file?尝试使用 tar 文件迁移时如何修复 psql SYNTAX 错误?
【发布时间】:2021-09-02 17:57:57
【问题描述】:

下面的结果显示了我遇到的问题。请让我知道我做错了什么。我正在尝试将 PostGreSQL 数据库迁移到另一台服务器。在第一台服务器上执行 pg_dump 并将 tar 文件转移到这个新服务器后,我在尝试将数据上传到新数据库时遇到了这个问题。

[postgres@host ~]$ psql newdb < newdb.tar
ERROR:  syntax error at or near "toc" at character 1
LINE 1: toc.datREVOKE ALL ON SCHEMA public FROM postgres;
        ^
GRANT
GRANT
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE auth_group FROM postgres;
        ^
ERROR:  relation "auth_group" does not exist
ERROR:  relation "auth_group" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE auth_group_permissions FROM postgres;
        ^
ERROR:  relation "auth_group_permissions" does not exist
ERROR:  relation "auth_group_permissions" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE auth_permission FROM postgres;
        ^
ERROR:  relation "auth_permission" does not exist
ERROR:  relation "auth_permission" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE auth_user FROM postgres;
        ^
ERROR:  relation "auth_user" does not exist
ERROR:  relation "auth_user" does not exist
ERROR:  syntax error at or near "id" at character 1
LINE 1: id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE auth_user_groups FROM postgres;
        ^
ERROR:  relation "auth_user_groups" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     START WITH 1
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE auth_user_user_permissions FROM postgr...
        ^
ERROR:  relation "auth_user_user_permissions" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE dashboard_account FROM postgres;
        ^
ERROR:  relation "dashboard_account" does not exist
ERROR:  relation "dashboard_account" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE dashboard_account_organizations FROM p...
        ^
ERROR:  relation "dashboard_account_organizations" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE dashboard_budget FROM postgres;
        ^
ERROR:  relation "dashboard_budget" does not exist
ERROR:  syntax error at or near "id" at character 1
LINE 1: id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE dashboard_budget_categories FROM postg...
        ^
ERROR:  relation "dashboard_budget_categories" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE dashboard_budget_comments FROM postgre...
        ^
ERROR:  relation "dashboard_budget_comments" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     START WITH 1
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE dashboard_budget_restricted FROM postg...
        ^
ERROR:  relation "dashboard_budget_restricted" does not exis
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^
ERROR:  syntax error at or near "" at character 1
LINE 1: REVOKE ALL ON TABLE dashboard_category FROM postgres;
        ^
ERROR:  relation "dashboard_category" does not exist
ERROR:  relation "dashboard_category" does not exist
ERROR:  syntax error at or near "WITH" at character 7
LINE 1: START WITH 1
              ^
ERROR:  syntax error at or near "" at character 1
LINE 1:     id integer NOT NULL,
        ^

invalid command \N
invalid command \N
invalid command \.
invalid command \.
invalid command \.

ERROR:  syntax error at or near "" at character 1
LINE 1: 3 Account User

【问题讨论】:

  • 这里有很多错误,我只是无法将它们全部放在这篇文章中。

标签: postgresql terminal syntax migration psql


【解决方案1】:

您可能正在处理使用pg_dump -F t 创建的“TAR 格式转储”。

要恢复这样的转储,不要使用psql(用于恢复纯格式转储),而是使用pg_restore

pg_restore -d newdb newdb.tar

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 2021-09-23
    • 2019-01-12
    • 2015-07-10
    相关资源
    最近更新 更多