I'm working on Ubuntu. Following is one of my commands.
$ psql -U kuser -d postgres Then this connects to the database. But from postgres terminal when i try
postgres=> CREATE DATABASE kdb; ERROR: permission denied to create database When I try a similar command in Ubuntu, it gives the following
$ sudo -u kuser createdb kdb sudo: unknown user: kuser sudo: unable to initialize policy plugin How do I create this DB?. I have sudo rights and kuser is not me.
1 Answer
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.
1