Results 1 to 3 of 3
  1. #1
    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.

  2. #2
    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

  3. #3
    Join Date
    Nov 2003
    Posts
    2,825
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •