psql -h localhost won't connect on Mac OS X

1.9k views Asked by At

Per Postgresapp.com

psql is the PostgreSQL command-line interface to your database. Mac OS 10.7 ships with an older version of PostgreSQL, which can be started with the following command:

$ psql -h localhost

So I run psql -h localhost and get

Dans-MacBook-Pro:~ djechlin$ psql -h localhost
psql: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

As far as I can tell psql is simply client side, and Postgresapp.com's documentation is talking smack. I still have no idea how to start a postgres server locally and haven't been able to find any documentation on that.

Version:

Dans-MacBook-Pro:~ djechlin$ psql --version
psql (PostgreSQL) 9.1.5
contains support for command-line editing

I'm on Mac 10.8.4.

2

There are 2 answers

0
nil On

Try changing to postgres user and open psql prompt

 sudo -u postgres psql postgres

From here you can create more roles, databases, etc and connect to what you created from whatever you're trying to connect from.

Here is a useful cheat-sheet of commands I have often referred to:

 http://blog.jasonmeridth.com/posts/postgresql-command-line-cheat-sheet/
0
djechlin On

This was admittedly more confusing than it should have been, but...