Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2012

    Unanswered: 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.

  2. #2
    Join Date
    Dec 2012

    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.


  3. #3
    Join Date
    Nov 2003
    Provided Answers: 23
    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:

    Tips for good questions:

Posting Permissions

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