Take the 2-minute tour ×
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. It's 100% free, no registration required.

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

1 Answer 1

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: http://www.postgresql.org/docs/current/static/app-psql.html

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

 
discard

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.