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

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

Hello,

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)  
Old
Registered User
 
Join Date: Dec 2012
Posts: 4
Hello,

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.

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

http://www.postgresql.org/docs/curre...pq-envars.html
__________________
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:

http://tkyte.blogspot.de/2005/06/how...questions.html
http://wiki.postgresql.org/wiki/SlowQueryQuestions
http://catb.org/esr/faqs/smart-questions.html
Reply With Quote
Reply

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