Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I THINK I have PostgreSQL running correctly on my box: I have a PID and I see that postgres is "listening" on port 5432.

I'm trying to create a DB to experiment with, using the "Book" db outlined in C. Fehily's book "Visual Quickstart SQL".

I've tried a bunch of approaches, but have had no joy. Latest approach is:

$ su postgres
Password: 
postgres@piglet:/etc$ createdb books
createdb: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
postgres@piglet:/etc$ 

I'm not sure if I'm hitting the wall on passwords or authorizations, or something else. I'd sure welcome some suggestions. Thanks in advance!

share|improve this question
    
You first have to install postgres-xc-client sudo apt-get install postgres-xc-client and then sudo apt-get install postgres-xc And then do postgres -D <Postgres Data Dir> -X This will start the server And then do createdb books NOTE: I personally think, setting up postgres is very vague or broad question –  thefourtheye May 4 '13 at 3:51
    
@thefourtheye What's this got to do with postgres-xc? Looks like regular PostgreSQL to me. –  Craig Ringer May 4 '13 at 12:25
add comment

1 Answer

up vote 1 down vote accepted

If PostgreSQL is running and listening on port 5432 according to netstat but when you run psql you get an error like:

psql: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

then most likely the issue is that you're using the psql from an earlier version of PostgreSQL that's also installed on your system. This version is probably configured to use a different unix_socket_directory.

The best option is to set your PATH environment variable to point to the directory containing the correct psql, createdb, etc versions before the old ones.

Alternately, you can use TCP/IP connections by explicitly specifying -h localhost, eg:

psql -h localhost ...

(and thus createdb -h localhost ...). This will result in you using old versions of the createdb, psql, etc commands, so it's better to just set your PATH. The same is true of using -h to set the unix socket path, which is somewhat of an advanced option.

Fix your PATH environment variable and all will be well. You can test this temporarily with something like the following, where you'd replace /usr/pgsql-9.2/bin with the bin directory under your PostgreSQL 9.2 installation:

export PATH=/usr/pgsql-9.2/bin:$PATH
psql

If that works, you'll need to make the change permanent by editing /etc/environment, your .bash_profile, or other appropriate settings files. Search for "ubuntu permanently set PATH" for more info.

share|improve this answer
    
Thanks for this, I'll do some checking with your suggestions. I have a related question, though: I have Postgresql 9.1.x as well as 9.2.4 installed (9.1.x came with the original install, and then I upgraded as recommended on the PostgreSQL.org site)... Would these problems also disappear if I just removed 9.1.x via apt-get remove command string? –  Red Spanner May 6 '13 at 16:08
    
I removed the 9.1 version OK but psql still returns error. I'm working on the $PATH activity now. –  Red Spanner May 6 '13 at 16:24
    
Hi Craig, I tried the command 'export PATH=/usr/lib/postgresql/9.2/bin:$PATH' but received same error message 'psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?' I'll try the localhost option to see if that works. –  Red Spanner May 6 '13 at 17:04
    
Turns out Postgresql 9.2.4 is listening on port 5433 –  Red Spanner May 6 '13 at 17:24
    
I can see the DB now -- there are still some dball config issue to fix, but I'm on the right track. Thanks Craig! –  Red Spanner May 6 '13 at 17:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.