Reputation: 1
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 Files\PostgreSQL\17\data\postgresql.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 Files\PostgreSQL\17\pg_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?
Upvotes: 0
Views: 122
Reputation: 41
Set the PGPORT Environment Variable
setx PGPORT 5432 /M and export PGPORT=5432
Upvotes: 0
Reputation: 19724
This is controlled by:
C:\Program Files\PostgreSQl\17\scripts\runpsql.bat
Specifically this:
SET port=5433
SET /P port="Port [%port%]: "
At some point this file was configured during the Postgresql install to point at 5433
.
Edit the file to:
SET port=5432
Upvotes: 2
Reputation: 247625
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.
Upvotes: 0
Reputation: 809
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.
Upvotes: -2