postgresqlcmdcommand-line-interfacerunas

How to connect to PostgreSQL through CLI?


I am trying to access postgresql through the command line. However, whenever it is time for me to enter my password, I get the following error: Fatal: password authentication failed for user RMehta. I am pretty sure the reason that password authentication fails is that the user for my database is postgres, and not RMehta.

The only solution I found was using runas in the command line, but I couldn't figure how to get runas to work. Thanks a lot for any advice. I am using windows 7, and postgresql 9.3


Solution

  • For Unix environnement the command line is

    psql -U USERNAME -h localhost dbname
    

    For a Windows environment, you may consider replacing "-" with "/"

    -U option able you to choose a user to connect with

    -h option able you to connect with the TCPIP protocol, you may consider it useless for Windows