Tuesday, March 1, 2016

Postgresql: How to login through psql from command line? - resolved

When trying psql, you get error like "psql: Could not connect to server: Connection refused. Is the server running on host xxxxxxxxxx and accepting TCP/IP connections on port 5432?", you would like to read this article to check if things are set and used correctly.

On the database server:

1. Modify the pg_hba.conf file to add client authentication record. The file is located at <postgresql home>/data directory. Add the following line to the file.

          host     all     all     <client ip address>     trust or password

2. Modify the postgresql.conf to change the listen address. This file is also located at <postgresql home>/data directory. Change listen_addresses to listen_addresses = '*'.

On the client machine:

1. Install postgresql on your client machine. Choose to only install User Interface/psql.

2. Add your <Postgresql home>/BIN to your environmental path.

3. Set PGHOST environment variable with the value of your database server IP address. Set PGPORT to the port of the database.

4. At your command line, type the following.

      If you skipped step 3:
            psql postgresql://<db ip>:<port>/<database name> <username> 
                  OR
             psql -U <username> -h <db ip> -p <port>
     
      If you did not skip step 3:
            psql -U <username>

If you have installed the postgresql on your desktop using port 5433. You named the database moneyOcean and created a user: greatSea, Of course, you can always go to the program and open the SQL Shell to automatically have the psql started. However, if you really want to start psql from commanc line, you may type the following at your command line.

      psql postgresql://localhost:5433/moneyOcean greatSea
            OR
      psql -U greatSea -p 5433

It will then prompt you for password.

------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment