PostgreSQL 9.1 pg_restore error regarding PLPGSQL

一世执手 提交于 2019-11-29 20:23:24
Roman Akinfold

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

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

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.

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!