Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 23 down vote accepted

It appears that 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 as that user, but sudo fails.

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

You can either grant that permission to the user, using the postgres account which is the default management account on Ubuntu:

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

Or you can 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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .