1
votes

I want to create a database ABC. I want to load data into ABC using a dump file say ABC_DUMP. I want an user ABC_USER to have all access on database ABC including create, select, alter, update. I login to psql using:

postgres@ubuntu:~$ psql
postgres=# CREATE DATABASE ABC;
postgres=# GRANT ALL PRIVELEGES ON DATABASE ABC TO ABC_USER;
postgres=# \q
postgres@ubuntu:~$ psql -h localhost ABC -U ABC_USER < ABC_DUMP
Password for user ABC_USER xxxxxx
CREATE FUNCTION
ERROR:  must be member of role "postgres"
CREATE FUNCTION
ERROR:  must be member of role "postgres"
CREATE FUNCTION
ERROR:  must be member of role "postgres"
CREATE FUNCTION
ERROR:  must be member of role "postgres"
CREATE AGGREGATE
ERROR:  must be member of role "postgres"
SET
SET
CREATE TABLE
ERROR:  must be member of role "postgres"
CREATE TABLE
ERROR:  must be member of role "postgres"
CREATE SEQUENCE
ERROR:  must be member of role "postgres"
ALTER SEQUENCE
CREATE SEQUENCE
ERROR:  must be member of role "postgres"
...

How can I avoid these errors? I have tried giving all privileges on schema public to user ABC_USER but still I am getting errors.

Role name : ABC_USER, Role Attributes list - Create DB, Create role
Role name : Postgres, Role Attributes list - Superuser, Create role, Create DB, Replication, Bypass RLS

Using postgres version 9.5.6

1
"I want an user ABC_USER to have all access on database ABC including create, select, alter, update." FWIW, there's a lot more to all access than create, select, alter, and update. You might want to make ABC_USER the owner of the database and everything in it, but be careful with that. Load the dump as postgresql, then GRANT privileges.Mike Sherrill 'Cat Recall'
I did what you proposed already but no help. While using psql, no errors while loading dump but still no permissions for select even after running GRANT ALL PRIVILEGES ON SCHEMA public TO ABC_USER;rohanagarwal
"GRANT ALL PRIVILEGES ON SCHEMA..." doesn't do what you think it does. It might also be that you're confused by terminology: schema and database are different things in this context.Mike Sherrill 'Cat Recall'
Yeah, I'm migrating to postgres from mysql, so you can understand, so what solution do you suggest now?rohanagarwal

1 Answers

3
votes

The problem was with the dump file. It had owner set, so I can't dump the data using user ABC_USER. I created another dump file but this time using --no-owner flag and used that dump file and it worked.

pg_dump ABC -no-owner > ABC_DUMP