The Computer Oracle

User permissions for creating PostgreSQL DB

--------------------------------------------------
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
--------------------------------------------------

Track title: CC E Schuberts Piano Sonata D 784 in A

--

Chapters
00:00 Question
00:43 Accepted answer (Score 51)
01:36 Thank you

--

Full question
https://superuser.com/questions/507721/u...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#postgresql

#avk47



ACCEPTED ANSWER

Score 51


It appears you have a database user named kuser, but there is no system user with that name. This is why you're able to get a postgres prompt, but sudo fails.

That user isn't able to create a database because the account doesn't have the createdb permission.

You can either grant that permission to the user using the postgres account (the default management account on Ubuntu):

sudo -u postgres psql -c 'alter user kuser with createdb' postgres

Or just use that management account to create the database and specify that it is owned by the kuser account:

sudo -u postgres createdb -O kuser kdb

If that user isn't going to be creating other databases I'd advise using the latter option, better to limit the privileges that are granted to the account.