All we need is an easy explanation of the problem, so here it is.
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:
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 ?
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
You may have changed the port for the PostgreSQL database, but not the client.
- Update your PostgreSQL configuration to use port
- Test this by passing the port number when trying to connect:
psql -p 5332
- 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.
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂