I am running PostgreSQL on Windows, and my PostgreSQL server is correctly configured to use port 5432. However, when I open the SQL Shell (psql), it defaults to port 5433, as shown in the screenshot below:default value is 5433
Steps I Took to Resolve:
-
Verified the postgresql.conf file located at C:Program
FilesPostgreSQL17datapostgresql.conf and confirmed that port =
5432. -
Restarted the PostgreSQL service using net stop postgresql-x64-17
and net start postgresql-x64-17. -
Updated the pg_env.bat file located at C:Program
FilesPostgreSQL17pg_env.bat by changing the port variable to
5432. Restarted the computer after
this. -
Verified that the PGPORT environment variable wasn’t
explicitly defined -
Used SHOW port; within psql, and it correctly
displays 5432 as the active server port.
Despite these steps, SQL Shell (psql) still defaults to 5433 when prompting for the port. How can I make it default to 5432 permanently?
2
Answers
You probably have a previous version of Postgres installed. Uninstall it and ensure that 5432 is free. Check Windows Services to ensure no other old version is running. Also check netstat to ensure something else is not on that port. Then reinstall it. Postgres will automatically go to the next port up for another installation that is present on the default 5432.
There are two possibilities:
You have the environment variable
PGPORT
set to 5433. Remove that environment variable, and the PostgreSQL client library libpq will connect to port 5432 by default.Your PostgreSQL was configured to default to port 5433 when it was built from source. That would mean that you are using a custom build of PostgreSQL, because the publicly available binaries are not built like that.