PostgreSQL 9.1 pg_restore error regarding PLPGSQL

前端 未结 6 1487
-上瘾入骨i
-上瘾入骨i 2020-12-23 02:30

I am using Postgres for a django project and I am currently implementing a database backup/restore system that as simple as possible performs a pg_dump when the user clicks

相关标签:
6条回答
  • 2020-12-23 02:35

    It seems like pg_restore tries to restore some extra data which you don't own. Try to add -n public option to your pg_restore command line. It will tell pg_restore restore only contents of public schema. Your command line should looks like

    pg_restore -U username -c -n public -d database_name
    
    0 讨论(0)
  • 2020-12-23 02:44

    If possible, I recommend you remove the comment which fails to restore before creating any dumps.

    You can do so by:

    COMMENT ON EXTENSION plpgsql IS null;
    

    If you don't want to do this for every newly created database, remove the comment from the DB called template1 (CREATE DATABASE… copies this database.)

    Dumps created after that should restore with no error.

    0 讨论(0)
  • 2020-12-23 02:45

    Works for me after this command -

    Deepak@deepak:~$ sudo -i -u postgres
    postgres@deepak:~$ psql 
    psql (9.3.5)
    Type "help" for help.
    
    postgres=# GRANT ALL PRIVILEGES ON DATABASE database_name TO user;
    postgres=# GRANT
    
    0 讨论(0)
  • 2020-12-23 02:46

    If you're running Postgres 11's (or higher) version of pg_dump then you can take advantage of the new --no-comments flag.

    0 讨论(0)
  • 2020-12-23 02:50

    Are you loading into a DB that was created by a different user? If possible try restoring using the same user that created the DB and its existing objects.

    0 讨论(0)
  • 2020-12-23 02:53

    I found the following workaround on this page:

    http://archives.postgresql.org/pgsql-general/2011-10/msg00826.php

    The idea is to use pg_restore -l to list the contents of the archive, grep out the extension that the user doesn't have permission to restore, and use pg_restore -L to use this elided list when restoring.

    For example:

    pg_restore -l ~/database.dump | grep -v "EXTENSION - plpgsql" > ~/restore_elements
    pg_restore -L ~/restore_elements ~/database.dump
    
    0 讨论(0)
提交回复
热议问题