If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back  dBforums > Database Server Software > PostgreSQL > Any way to connect postgres through username

LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Registered User
Join Date: Dec 2012
Posts: 3
Any way to connect postgres through username


I am very new to PostgreSQL. I am trying to connect to database via a different user which is created by me.

psql -U user1
but this gives me error message saying database user1 does not exist.

When I try psql -d mydb -U user1 this works fine.

Can any body suggest me if there is any way to connect to database through psql command line without using the -d database parameter.
Reply With Quote
  #2 (permalink)  
Registered User
Join Date: Dec 2012
Posts: 4

When connecting to the PostgreSQL server through psql, the database must be specified so that PostgreSQL knows which database to run the SQL against.

For example, if you had an additional DB on your PostgreSQL server other than mydb called mydb2, and you connected to mydb2 through psql, queries against tables existing in mydb would fail because they do not exist in mydb2.

Therefore, the database must always be specified.

Reply With Quote
  #3 (permalink)  
Registered User
Join Date: Nov 2003
Posts: 2,807
Just set up the the environment variables as explained in the manual:

I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

Tips for good questions:

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On