8

I'm trying to import a schema-dump into PostgreSQL with 'psql -U username -W dbname < migrations/schema.psql', the Schema is imported partly, but the console throws errors like "ERROR: permission denied for relation table_name" and "ERROR: relation table_name does not exist".

I've created the database like this: "createdb -O username dbname"

There are only 7 tables to import, and it breaks with just importing 3 of them.

Anybody a hint, what to do?

1
  • Check the dump file for any "ALTER OWNER ..." or "SET SESSION AUTHORIZATION..." statements. Commented Aug 18, 2010 at 13:29

3 Answers 3

3

If the backup was in the "custom" format (-Fc), you could use pg_restore instead so you can tell it to not apply ownership changes:

pg_restore -U username -W --no-owner --dbname=dbname migrations/schema.psql

All the objects will created with "username" as the owner.

Barring that, try to grep out the ALTER OWNER and SET SESSION AUTHORIZATION commands into new file (or through send grep output via pipe to psql). Those commands should always be on a single line in the plain-text output format.

Sign up to request clarification or add additional context in comments.

2 Comments

pg_restore can't handle SQL text files, only files created with pg_dump -Fc (which presumably this is not)
Duh. Forgot about that, I'll update my answer to another idea.
2

Sometimes this kind of problem is caused by case-sensitivity issues. PostgreSQL folds to lowercase all unquoted identifiers; if the tables are created with quoted names containing uppercase letters, later commands that don't quote the names may fail to find the table.

The permission errors may be related to the same thing, or it may be something else entirely. Hard to tell without seeing the failing commands.

Comments

0

As I work on my websites, I get that error all the time because I'll be creating a table as me, table that needs to be accessed by the Apache/PHP user that connects later.

There is a table named pg_class that defines your tables. This includes a column named relowner. Changing that with the correct number will give you the correct ownership.

I have details on this page:

http://linux.m2osw.com/table_owner_in_postgresql

The ALTER OWNER ... may be a better solution that does the same thing, although in older versions of PostgreSQL it did not exist!

3 Comments

I'm new to PG. But I was thinking about changing owner. In an environment where the owner is an administrator but the application has restricted access to the DB, shouldn't we just have a user with restricted permissions?
Yes. If you are the implementer, it is a good idea to use good permissions (as long as you don't over do it.) The system I've been using is called Drupal and it is expected to have full rights in creating, altering, and deleting tables. Not the best choice to my point of view, but that allows administrators to do everything directly from their website (i.e. install, upgrade, remove modules that create, alter, and delete tables...) I have another system, however, where the front end has no such permissions. All the tables must exist and only INSERT/UPDATE and at times DELETE work...
@Alexis_Wilke yes, in my opion we must use restricted permissions for the user. Looking at your scenario of Drupal, I find it scary to give the app full rights. If a user finds a flaw in the program logic, that could mean the end of data. Anyway, this is another issue...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.