Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. 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 normally get to the console in UBUNTU by typing:

sudo -u postgres psql

But I need to delete a database owned by a different user.

When I type:

sudo -u username psql

It tells me "database "username" does not exist.

But... I wasn't trying to connect to a database, I was trying to connect as a user.

share|improve this question
I did make a lot of research effort, I went through the documentation linked below and somehow I still did not arrive at the answer below. – Sephethus Dec 26 '12 at 20:57
up vote 2 down vote accepted

psql assumes you want to connect to the database named as the current user if you don't provide any login details.

But you can ovverride the defaults using parameters to psql, there is no need to use sudo in order to connect as a different username.

Simply run:

psql -U username -d databasename

where username is the user you want to use and databasename the database you want to connect to.

If you don't know which database you can connect to, use

psql -l

to show them all.

All this and a lot more is nicely documented in the manual:

share|improve this answer
Thanks I finally got in as myself. Yet despite my database showing up under \l I can't seem to delete it using DROP DATABASE databasename; It says it doesn't exist. – Sephethus Dec 26 '12 at 20:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.