1

I successfully followed the Postgres 11 installation instructions on Centos 7 found here. I am able to successfully create schemas / tables and insert data into the database over port 5432 with no problems.

Now I would like to change the default port to 5332 (or something else, doesn't matter), and I did the following:

 vi /var/lib/pgsql/11/data/postgresql.conf

Changed the line:

#port = 5432                            # (change requires restart) 

to look like:

port = 5332                            # (change requires restart) 

Then restarted postgres service by doing:

systemctl restart postgresql-11.service

Then I change to the postgres user:

su - postgres
psql

I'm getting the following error message:

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

So apparently there is another reference of port 5432 somewhere, but I am unable to find it.

FYI, if I undo the change I did above (in the file /var/lib/pgsql/11/data/postgresql.conf), then everything works perfectly again over default port 5432.

What else do I need to do to get postgres to run on a different port ?

1 Answer 1

3

You may have changed the port for the PostgreSQL database, but not the client.

Try this:

  1. Update your PostgreSQL configuration to use port 5332 again
  2. Test this by passing the port number when trying to connect:
    psql -p 5332
    
  3. If everything works, change the default port for the command-line client like this:
    PGPORT=5332; export PGPORT
    

Now all calls to psql will act as if it has been invoked with the -p 5332 command-line option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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