Error must be owner of schema public

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

I’m trying to take ownership of the «public» schema in the database I’m the owner of (but not superuser). I’m running alter schema public owner to username, where username is my user name. I’m getting the following error: ERROR: must be owner of schema public.

Is it possible for me as a non-superuser database owner to take ownership of a schema, (or generally any object) in my database?

asked May 20, 2021 at 5:54

Andrew Savinykh's user avatar

Andrew SavinykhAndrew Savinykh

1,2955 gold badges14 silver badges27 bronze badges

No. This is not possible. You can change the ownership of any object in PostgreSQL only if you are Superuser or if you are the owner of same object.

You should ask your DBA or owner of the schema to do change the owner.

answered May 20, 2021 at 7:17

pgyogesh's user avatar

Comments

@Jolg42

@albertoperdomo
albertoperdomo

changed the title
Improve error message Error: Database error: Error querying the database: db error: ERROR: must be owner of schema public 0: migration_core::api::Reset at migration-engine/core/src/api.rs:232

Prisma Migrate cannot reset the database when the user has insufficient privileges — this makes Prisma Migrate incompatible with some hosted cloud providers

Feb 3, 2021

tomhoule

added a commit
to prisma/prisma-engines
that referenced
this issue

Feb 10, 2021

@tomhoule

This is intended for users who do not have permissions to drop and
recreate the database.

This is not a perfect solution, because there are a lot of elements
sql_schema_describer does not know about (views, stored procedures,
roles, etc.), so the cleanup will be less than perfect.

closes prisma/prisma#4803

Для пользователей, использующих Виртуальную платформу 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

The Solution to How to solve privileges issues when restore PostgreSQL Database is

To solve the issue you must assign the proper ownership permissions. Try the below which should resolve all permission related issues for specific users but as stated in the comments this should not be used in production:

[email protected]:/var/log/postgresql# sudo -u postgres psql
psql (8.4.4)
Type "help" for help.

postgres=# du
               List of roles
    Role name    | Attributes  | Member of
-----------------+-------------+-----------
 <user-name>    | Superuser   | {}
                 : Create DB
 postgres       | Superuser   | {}
                 : Create role
                 : Create DB

postgres=# alter role <user-name> superuser;
ALTER ROLE
postgres=#

So connect to the database under a Superuser account sudo -u postgres psql and execute a ALTER ROLE <user-name> Superuser; statement.

Keep in mind this is not the best solution on multi-site hosting server so take a look at assigning individual roles instead: https://www.postgresql.org/docs/current/static/sql-set-role.html and https://www.postgresql.org/docs/current/static/sql-alterrole.html.

~ Answered on 2013-03-16 18:04:13

Для людей, использующих Google Cloud Platform, любая ошибка остановит процесс импорта. Лично я столкнулся с двумя разными ошибками в зависимости от введенной мной команды 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.

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

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

Это проблема с разрешением, которую мне не удалось исправить с помощью команды, представленной в Документы GCP, советы из этой текущей темы или следуйте советам команды 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

I just try the solution found here : https://stackoverflow.com/questions/31469008/postgresql-backup-database-and-restore-on-different-owner

And I still have an error on the inexistent object owner.

What I do:

pg_dump -F c -f fnam.sql.tgz -h postgresql.bizinnov.net -U bizinnov bizinnov_fnam
pg_restore -F c --clean --no-owner --role=fnam -h localhost -U fnam -d fnam_db1 fnam.sql.tgz

What I get:

pg_restore: [archiver (db)] Error from TOC entry 148; 1259 408716672
SEQUENCE auth_group_id_seq bizinnov

pg_restore: [archiver (db)] could not execute query: ERROR: sequence «auth_group_id_seq» does not exist
Command was: DROP SEQUENCE public.auth_group_id_seq;

pg_restore: [archiver (db)] Error from TOC entry 149; 1259 408716674
TABLE auth_group bizinnov

pg_restore: [archiver (db)] could not
execute query: ERROR: table «auth_group» does not exist
Command was: DROP TABLE public.auth_group;

pg_restore: [archiver (db)] Error from TOC entry 6; 2615 2200 SCHEMA
public postgres

pg_restore: [archiver (db)] could not execute query:
ERROR: must be owner of schema public
Command was: DROP SCHEMA public;

pg_restore: [archiver (db)] could not execute query: ERROR: schema
«public» already exists
Command was: CREATE SCHEMA public;

pg_restore: [archiver (db)] Error from TOC entry 2029; 0 0 COMMENT
SCHEMA public postgres

pg_restore: [archiver (db)] could not execute
query: ERROR: must be owner of schema public
Command was: COMMENT ON SCHEMA public IS ‘standard public schema’;

pg_restore: WARNING: no privileges could be revoked for «public»

pg_restore: WARNING: no privileges could be revoked for «public»

pg_restore: WARNING: no privileges were granted for «public»

pg_restore: [archiver (db)] Error from TOC entry 2030; 0 0 ACL public postgres

pg_restore: [archiver (db)] could not execute query: ERROR: role «bizinnov» does not exist
Command was: REVOKE ALL ON SCHEMA public FROM PUBLIC;

REVOKE ALL ON SCHEMA public FROM postgres;

GRANT ALL ON SCHEMA public TO

postgres; … WARNING: errors ignored on restore: 125

Skip to content



Open


Issue created Mar 01, 2019 by brancott@brancott

ERROR: relation «xxx» does not exist

All of a sudden my gitlab server’s begun to give me a bunch of errors while restoring a backup, I upgraded to version 11.7.0 several weeks ago and everything used to work fine till a couple of days ago, no changes to configuration were made. How can I fix it?

ERROR: relation «public.timelogs» does not exist

ERROR: relation «public.timelogs» does not exist

ERROR: relation «public.ci_builds_metadata» does not exist

ERROR: relation «public.resource_label_events» does not exist

ERROR: relation «public.cluster_groups» does not exist

ERROR: relation «public.board_project_recent_visits» does not exist

ERROR: relation «public.ci_runner_namespaces» does not exist

ERROR: relation «public.ci_build_trace_section_names» does not exist

ERROR: relation «public.merge_requests_closing_issues» does not exist

ERROR: relation «public.internal_ids» does not exist

ERROR: relation «public.events» does not exist

ERROR: relation «public.board_group_recent_visits» does not exist

ERROR: relation «public.import_export_uploads» does not exist

ERROR: relation «public.fork_network_members» does not exist

ERROR: relation «public.label_priorities» does not exist

ERROR: relation «public.merge_request_metrics» does not exist

ERROR: relation «public.ci_builds_metadata» does not exist

ERROR: relation «public.cluster_platforms_kubernetes» does not exist

ERROR: relation «public.label_priorities» does not exist

ERROR: table «abuse_reports» does not exist

ERROR: must be owner of extension pg_trgm

ERROR: must be owner of extension plpgsql

ERROR: must be owner of schema public

ERROR: schema «public» already exists

ALTER SCHEMA

ERROR: must be owner of schema public

CREATE EXTENSION

ERROR: must be owner of extension plpgsql

CREATE EXTENSION

ERROR: must be owner of extension pg_trgm

Edited Aug 27, 2020 by 🤖 GitLab Bot 🤖

Понравилась статья? Поделить с друзьями:
  • Error must be owner of extension plpgsql
  • Error must be owner of database
  • Error must be member of role postgres
  • Error music download
  • Error multiverse invalid