Error must be owner of extension plpgsql

I have dumped a clean, no owner backup for Postgres Database with the command pg_dump sample_database -O -c -U Later, when I restore the database with psql -d sample_database -U app_name Howev...

For people using Google Cloud Platform, any error will stop the import process.
Personally I encountered two different errors depending on the pg_dump command I issued :

1- The input is a PostgreSQL custom-format dump. Use the pg_restore command-line client to restore this dump to a database.

Occurs when you’ve tried to dump your DB in a non plain text format. I.e when the command lacks the -Fp or —format=plain parameter. However, if you add it to your command, you may then encounter the following error :

2- SET SET SET SET SET SET CREATE EXTENSION ERROR: must be owner of extension plpgsql

This is a permission issue I have been unable to fix using the command provided in the GCP docs, the tips from this current thread, or following advice from Google Postgres team here. Which recommended to issue the following command :

pg_dump -Fp --no-acl --no-owner -U myusername myDBName > mydump.sql

The only thing that did the trick in my case was manually editing the dump file and commenting out all commands relating to plpgsql.

I hope this helps GCP-reliant souls.

Update :

It’s easier to dump the file commenting out extensions, especially since some dumps can be huge :
pg_dump ... | grep -v -E '(CREATE EXTENSION|COMMENT ON)' > mydump.sql

Which can be narrowed down to plpgsql :
pg_dump ... | grep -v -E '(CREATE EXTENSION IF NOT EXISTS plpgsql|COMMENT ON EXTENSION plpgsql)' > mydump.sql

Seeing error «Must be owner of extension plpgsql» during a Postgres database restore.

calendar_today

Updated On:

Products

CA Application Performance Management Agent (APM / Wily / Introscope)

INTROSCOPE

Issue/Introduction

The following message appears in the console when executing «dbrestore-postgres.bat» or «dbrestore-postgres.sh»:

pg_restore: [archiver (db)] Error while PROCESSING TOC: 

pg_restore: [archiver (db)] Error from TOC entry nnnnn; 0 0 COMMENT EXTENSION plpgsql 
pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of extension plpgsql 
Command was: COMMENT ON EXTENSION plpgsql IS ‘PL/pgSQL procedural language’;

Environment

All supported APM Releases.

Cause

The message means that the command «COMMENT ON EXTENSION plpgsql IS ‘PL/pgSQL procedural language'» had the error. In most cases, this message can be ignored. 
During the restore, it tries restoring this comment. However, the restore user was not owner of the extension plpgsql, causing the error.
The comment of extension plpgsql already exists, there is no problem as a result.

Resolution

Feedback

thumb_up
Yes

thumb_down
No

I see this when I push my database to Heroku.

Locally, I have OS X 10.11.2 and:

$ psql --version
psql (PostgreSQL) 9.4.4

The pg:push:

$ heroku pg:push -a myapp mydb DATABASE_URL

...

pg_restore: connecting to database for restore
pg_restore: creating SCHEMA public
pg_restore: creating COMMENT SCHEMA public
pg_restore: creating EXTENSION plpgsql
pg_restore: creating COMMENT EXTENSION plpgsql
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2509; 0 0 COMMENT EXTENSION plpgsql
pg_restore: [archiver (db)] could not execute query: ERROR:  must be owner of extension plpgsql
    Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';



pg_restore: creating TABLE mytable

...

WARNING: errors ignored on restore: 1
$ heroku pg:info -a myapp
=== DATABASE_URL
Plan:        Hobby-basic
Status:      Available
Connections: 2/20
PG Version:  9.4.5
Created:     2015-12-15 18:14 UTC
Data Size:   116.6 MB
Tables:      0
Rows:        0/10000000 (In compliance) - refreshing
Fork/Follow: Unsupported
Rollback:    Unsupported
Region:      Europe
Add-on:      postgresql-parallel-5079

Locally I have:

$ heroku update
Updating plugins... no plugins to update.
$ heroku version
heroku-toolbelt/3.42.25 (x86_64-darwin14.5.0) ruby/1.9.3
heroku-cli/4.27.9-cce0260 (amd64-darwin) go1.5.2
=== Installed Plugins
heroku-accounts
heroku-apps@1.0.0
heroku-cli-addons@0.1.1
heroku-fork@4.0.0
heroku-git@2.4.4
heroku-local@4.1.5
heroku-redis@1.1.1
heroku-run@2.9.2
heroku-status@1.2.4

Says «The error is harmless» over at http://dba.stackexchange.com/questions/90258/pg-restore-archiver-db-could-not-execute-query-error-schema-public-alre, but I thought I make a note here anyway. I haven’t noticed any problems.

Environment

  • Red Hat Virtualization 4.2
    • Upgrade from 4.2.4 to 4.2.5.

Issue

  • Upgrade from 4.2.4 to 4.2.5 failed.
  • Upgrade from 4.2.4 to 4.2.5 initially failed due to other reason, and then automatic roll-back also failed when restoring engine and ovirt_engine_history databases.
  • The following error is shown:
ERROR:  must be owner of extension plpgsql

Resolution

A workaround exists but it requires manual database manipulation. Please contact Red Hat Support and mention this article.

The problem is currently being investigated in Bugzilla 1611617 — During 4.2.4 to 4.2.5 upgrade: «ERROR: must be owner of extension plpgsql during Restoring DWH database ovirt_engine_history and engine».

Root Cause

By default Postgres creates new databases with the extension plpgsql. However, to manually create this extension on some databases, owning the database is not enough and actual admin permissions are required.

When engine-backup restores a database, it always uses only the credentials of the engine database user, not postgres, thus (by default) has no admin privileges at this point, which makes the extrension creation fail.

Diagnostic Steps

pg_restore returns the following errors:

pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 7309; 0 0 COMMENT EXTENSION plpgsql 
pg_restore: [archiver (db)] could not execute query: ERROR:  must be owner of extension plpgsql
    Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';

pg_restore: [archiver (db)] Error from TOC entry 2; 3079 32579416 EXTENSION uuid-ossp 
pg_restore: [archiver (db)] could not execute query: ERROR:  permission denied to create extension "uuid-ossp"
HINT:  Must be superuser to create this extension.
    Command was: CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;

pg_restore: [archiver (db)] Error from TOC entry 7310; 0 0 COMMENT EXTENSION "uuid-ossp" 
pg_restore: [archiver (db)] could not execute query: ERROR:  extension "uuid-ossp" does not exist
    Command was: COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';


  • Product(s)

  • Red Hat Virtualization


  • Component

  • upgrade


  • Category

  • Upgrade


  • Tags

  • rhev
  • upgrade

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Mike Hardy

unread,

Jul 24, 2017, 7:05:16 PM7/24/17

to Google Cloud SQL discuss

Hey Guys, I am trying to migrate our postgres DB from compute engine to Cloud SQL. I’ve followed the documentation, but I’m getting two error messages. 

The first message is from the console and that says: 

 

ERROR: (gcloud.sql.instances.import) ERROR_RDBMS

I understand that’s related to permissions, so I inspected the logs, and I see ERROR: must be owner of extension plpgsql. This is where I get stuck — any suggestions on how to fix this?

Thanks,
Mike

Carlos (Cloud Platform Support)

unread,

Jul 25, 2017, 5:40:59 PM7/25/17

to Google Cloud SQL discuss

Hi Mike,

It does seems that the dump file you are trying to import includes some plpgsql statements requiring Superuser role. This role is certainly not available on hosted PostgreSQL.

It is unlikely that you need to import plpgsql related statements since by default, the database has the plpgsql extension already installed. So there is no need to install it again via the import.

The suggested workaround is to inspect you inspect your dump file and remove all sql statement related to «plpgsql».

Mike Hardy

unread,

Jul 27, 2017, 6:57:01 AM7/27/17

to Google Cloud SQL discuss

Thanks Carlos, for anyone who comes across this problem, we solved it with this:

pg_dump -Fc —no-acl —no-owner -h <connection> -d <database> -U <user>

Yevhen Sytnik

unread,

Aug 16, 2017, 4:04:27 PM8/16/17

to Google Cloud SQL discuss

Hello Mike, I’ve tried to use this comand pg_dump -Fc —no-acl —no-owner -h <connection> -d <database> -U <user> , but I’ve got error when tried restore database that dump file has custom format and should be use psql. Maybe you have some ideas. P.S. I’ve tried to migrate postgres db from another server to Google Cloud.

Vladimir Rusinov

unread,

Aug 16, 2017, 4:17:47 PM8/16/17

to google-cloud…@googlegroups.com

Hi Yevhen,

I’m afraid we only support plain next sql dumps, so you will need to change ‘-Fc’ to ‘-Fp’ or ‘—format=p’.

Stanislas drg

unread,

Oct 11, 2017, 4:02:55 PM10/11/17

to Google Cloud SQL discuss

The above code doesn’t work in my case.

The following command :

pg_dump -Fp —no-acl —no-owner -h localhost -d test2 -U myusername —file sth.sql

Returns : 

SET SET SET SET SET SET SET SET CREATE EXTENSION ERROR: must be owner of extension plpgsql

Tbh, I find it baffling that the command provided in [the documentation](https://cloud.google.com/sql/docs/postgres/import-export/creating-sqldump-csv) doesn’t work either (returns the same error as above).

I’ve been trying to overcome this for the past three hours using numerous methods. I’ve recreated an instance, dumped a test and production DB using various combinations, tried to DROP plpsql and change user privileges. Nothing worked so far.

I’ve also carefully looked at this [S.O thread](https://stackoverflow.com/questions/13410631/how-to-solve-privileges-issues-when-restore-postgresql-database)

Contrarily to what is described for Amazon RDS, the error seems blocking (I can’t see any changes in the DB).

What is the proper way to dump a simple DB as of now ?

Thank you for your help

Stanislas drg

unread,

Oct 11, 2017, 4:43:56 PM10/11/17

to Google Cloud SQL discuss

The only thing that solved the issue in my case was commenting out all lines relating to plpgsql, by manually editing the dump.

I hope this helps anyone.

James Petty

unread,

Nov 7, 2017, 4:43:01 AM11/7/17

to Google Cloud SQL discuss

The error you’re seeing is annoying, but easily avoidable. The problem is that exports attempt to reimport the comments associated with extensions, and attaching the comment requires superadmin privileges. If you edit your export file to remove lines like «SET COMMENT ON EXTENSION <extension> TO …» you should no longer have this problem.

Tianzhou Chen

unread,

Apr 13, 2018, 12:16:25 PM4/13/18

to Google Cloud SQL discuss

The proper way to dump a single DB is via the export option from your console or via gcloud, which would skip dumping plpgsql stuff.

Using pg_dump directly will not work as it has the permission issue of plpgsql.

Maksym Domarev

unread,

Sep 25, 2018, 2:03:28 AM9/25/18

to Google Cloud SQL discuss

so there is no way to import any big external db into gcloud, also, there is no way for master-slave config streaming replication… and 1 year passed. 

Olu

unread,

Sep 25, 2018, 6:52:34 AM9/25/18

to Google Cloud SQL discuss

On the Cloud PostgreSQL, the documentation confirms that configuring External Masters are not supported. However, this is supported within the CloudSQL first and Second Generations. About the implementation on Cloud PostgreSQL, I can confirm that there are internal ongoing processes to ensure this feature is available soon. 

Для пользователей, использующих Виртуальную платформу Google, любая ошибка остановит процесс импорта.
Лично я столкнулся с двумя разными ошибками в зависимости от команды pg_dump, которую я выпустил:

1- The input is a PostgreSQL custom-format dump. Use the pg_restore command-line client to restore this dump to a database.

Возникает, когда вы пытались сбрасывать свою БД в текстовом формате. I. когда команда не имеет параметра -Fp или -формат = простой. Однако, если вы добавите его в свою команду, вы можете столкнуться со следующей ошибкой:

2- SET SET SET SET SET SET CREATE EXTENSION ERROR: must be owner of extension plpgsql

Это проблема с разрешением, которую я не смог исправить, используя команду, представленную в GCP docs, советы от этого текущего потока, или после консультации с командой Google Postgres здесь. Который рекомендовал выпустить следующую команду:

pg_dump -Fp --no-acl --no-owner -U myusername myDBName > mydump.sql

Единственное, что делало трюк в моем случае, это вручную редактировать файл дампа и комментировать все команды, относящиеся к plpgsql.

Я надеюсь, что это поможет душам, поддерживающим GCP.

Обновление:

Легче сбрасывать файлы с комментариями расширений, тем более, что некоторые дампы могут быть огромными:
pg_dump ... | grep -v -E '(CREATE EXTENSION|COMMENT ON)' > mydump.sql

Которое можно сузить до plpgsql:
pg_dump ... | grep -v -E '(CREATE EXTENSION IF NOT EXISTS plpgsql|COMMENT ON EXTENSION plpgsql)' > mydump.sql

Понравилась статья? Поделить с друзьями:
  • Error must be member of role postgres
  • Error music download
  • Error multiverse invalid
  • Error multiplex veritas una перевод
  • Error multiple updates to a row by the same query is not allowed