0

I want to make a typical user in postgres that will be used by my web application.

  1. The web application will require access to all tables.
  2. The user should be able to read/write to all tables (select, update, delete, insert)

All tables belong to the public schema

What is the best practise for creating this user?

database name: acmeinc user: acmeuser

I tried this so far and I was not able to even update a table (permission error on the relation):

create user acmeuser
grant all privileges on database acmeinc to acmeuser
alter schema public owner to acmeuser

ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO acmeuser

Update:

I was running the above like:

psql acmeinc -c "create user acmeuser"

Should I be creating a role and then associating the user acmeuser to the role?

5
  • 1
    You forgot the semicolons. Commented Nov 19, 2014 at 13:38
  • I updated my question to show how I ran the statements, I'll try again with the semicolons. BTW, when I ran the commands, I did get a response back like "GRANT". Still getting the error ERROR: permission denied for relation tableabc Commented Nov 19, 2014 at 13:41
  • At which command did you get the permission denied message? Commented Nov 19, 2014 at 14:13
  • update table123 set col3='23' where id=1; Selects work fine. Commented Nov 19, 2014 at 14:18
  • 1
    Ah. Granting on a database doesn't grant on tables within it. Also alter default privs only affects tables created after that is run. You want grant ... on all tables in schema. Commented Nov 19, 2014 at 14:40

1 Answer 1

3

I think your issue stems from two misunderstandings around GRANT:

  • Granting on a database doesn't grant on tables within it, it only grants rights on the database object its self; and

  • ALTER DEFAULT PRIVILEGES only affects tables created after that is run, it doesn't change existing tables.

You want GRANT ... ON ALL TABLES IN SCHEMA ....

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

1 Comment

I have to run a separate query for sequences and functions?

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.