User permissions for creating PostgreSQL DB
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay
--
Chapters
00:00 User Permissions For Creating Postgresql Db
00:35 Accepted Answer Score 51
01:17 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
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay
--
Chapters
00:00 User Permissions For Creating Postgresql Db
00:35 Accepted Answer Score 51
01:17 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.