I've upgraded Postgresql from 9.3 to 9.6 on my machine (linux mint rafaella- so ubuntu 14.04)

As the previous version was listening on 5432 the new version is listening on 5433, but I want to change that to 5432 so that the previous configuration (rails, phppgadmin etc) work with the new postgres server.

I have changed the port in postgresql.conf from 5433 to 5432 and restarted postgres, but this didn't work:

$ sudo netstat -nltp |grep 5432     
$ sudo netstat -nltp | grep 5433
tcp        0      0*               LISTEN      25467/postgres 

I also tried setting the environment variable and restarting postgres:

PGPORT=5432; export PGPORT

again, still listening on 5433 and nothing on 5432.

trying to connect gives me:

$ sudo -u postgres psql postgres 
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"?

What am I doing wrong?

Output of pg_lsclusters:

$ pg_lsclusters 
Ver Cluster Port Status Owner    Data directory               Log file 
9.6 main    5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log

contents of pg_hba.conf:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             postgres                                peer
# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all               md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
  • @ypercubeᵀᴹ running that gives me: $ pg_lsclusters Ver Cluster Port Status Owner Data directory Log file 9.6 main 5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log – BigJ Sep 11 '17 at 15:15
  • No - psql: could not connect to server: Connection refused Is the server running on host "" and accepting TCP/IP connections on port 5432? – BigJ Sep 11 '17 at 15:24
  • @ypercube - they do yes. – BigJ Sep 11 '17 at 15:30
  • I have edited the question to show pg_hba.conf – BigJ Sep 11 '17 at 15:37
  • Discussion moved in chat. – ypercubeᵀᴹ Sep 11 '17 at 16:18

ypercube and deszo were able to get this user's environment up and running (per the chat transcript).

The key seemed to be running:

sudo pg_ctlcluster 9.6 main restart

but not running it as the postgres user.

See the chat log for more details.


There should be a line in your postgresql.conf file that says:

port = 1486

Change that.

The location of the file can vary depending on your install options. On Debian-based distros it is


On Windows it is

C:\Program Files\PostgreSQL\9.3\data

  • 2
    May be you could read the question again; the OP said he'd done that already. – mustaccio Apr 10 '18 at 14:11

As per pg_lscluster output :-

It is showing port 5432 which indicate there is no other cluster of postgresql with port 5433.

Also sudo -u postgres psql postgres command output show :-

Your cluster main service is not running kindly restart that cluster using

pg_ctlcluster 9.6 main restart --if error post the log files

  • Also go to postgresql.conf file present in /etc/ find listen_address in it and set as per below i.e listen_address='*' and restart the service again .

In ubuntu 20.04 I solved it like this:

To list which ports is using:

sudo lsof -i -P -n | grep LISTEN

To list the paths of postgres and your respectives ports

grep -H '^port' /etc/postgresql/*/main/postgresql.conf

Choose the path of port you want change. In my case is


then I edit the configurations of port with:

sudo nano /etc/postgresql/13/main/postgresql.conf

Save the changes and restart the service with:

sudo service postgresql restart

Then you can run lsof -i -P -n | grep LISTEN to see the ports is correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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