Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently upgraded to Natty (Ubuntu 11.04) and now my postgresql does not seem to connect.

I am using pgadmin3 which throws the following error:

could not connect to server: Connection refused Is the server running on host "localhost" and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?

typing psql on the terminal gives the following error:

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"?

following are the files under var/run/postgresql/

total 8 
drwxrwsr-x  2 postgres postgres 100 2011-05-15 14:35 . 
drwxr-xr-x 19 root     root     720 2011-05-15 14:35 ..
-rw-------  1 postgres postgres   5 2011-05-15 14:35 
srwxrwxrwx  1 postgres postgres   0 2011-05-15 14:35 .s.PGSQL.5433
-rw-------  1 postgres postgres  34 2011-05-15 14:35 .s.PGSQL.5433.lock

netstat shows

sudo netstat -lp | grep postgresql 
unix  2      [ ACC ]     STREAM     LISTENING     7763     1025/postgres   /var/run/postgresql/.s.PGSQL.5433

I believe the problem is that its looking to start on 5432 but it should be starting in 5433 but how do I change this??

share|improve this question
up vote 1 down vote accepted

The default port for Postgres is 5432. Therefore, all tools (pgadmin3, psql) will default to using this port unless you specify otherwise.

You have Pg running on port 5433. Therefore to connect with any tool, you'll have to manually specify the port number. On pgadmin3, it's a textbox in the connection GUI somewhere (if I remember right). psql takes the --port option as follows:

psql --port 5433 [database]
share|improve this answer
I changed it in the conf file and restarted the service. that helped – Omnipresent May 15 '11 at 19:42

I just upgraded PostgreSQL and ran into the same problem. The problem was my new postgres server running version (9.1) was installed in parallell with my old server running version (8.4). I guess the default configuration is to run on an alternative port (5433).

So my solution was to make sure the new server ran on 5432.

So edit your postgres configuration

sudo -u postgres gedit /etc/postgresql/9.1/main/postgresql.conf

Make sure that the port is 5432:

port = 5432

And restart the postgres server by issuing :

sudo -u postgres /etc/init.d/postgresql restart

An untested alternative would be to first uninstall the old postgres server, before installing the new version.

share|improve this answer

Your Answer


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.