Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My PostgreSQL default port is 5432, I want to change default port by using command line (in Windows 7).

I saw this solution before:

I tried running the following command, but it failed:

postgres --p 5431

Could someone tell me how to change port in using command line?

share|improve this question

migrated from May 3 '13 at 6:55

This question came from our site for professional and enthusiast programmers.

Since you're on Windows and are probably starting PostgreSQL as a Windows service, you'll need to edit postgresql.conf (inside your data directory) to set the new port there, then restart the postgresql service using the Services control panel or (as an Administrator) the net service command.

You can use a programmatic text editing tool to change postgresql.conf if you need to automate this. On a Linux/unix box you'd use a tool like sed or awk, but on Windows I imagine you'll be using VBS, powershell, or an add-on tool like Perl.

You'll need to change the connection settings in tools like PgAdmin-III to use the new port.

If you were starting PostgreSQL manually using pg_ctl you could set the PGPORT environment variable or pass a config option on the command line. This won't work when you're launching it as a Windows service.

share|improve this answer
I'm using "Swiss File Knife" to do replacement in text files on Windows. – a_horse_with_no_name May 3 '13 at 8:07
@a_horse_with_no_name Useful tool when you don't have fileutils/coreutils/etc; thanks for the tip. – Craig Ringer May 3 '13 at 8:30
So I can't use command line to change pgsql port in Windows? – Nick Hung May 7 '13 at 2:12
@NickHung Yes, you can, as explained above - use a text processor to change the config file, or don't run PostgreSQL as a Windows service and instead start it with pg_ctl. – Craig Ringer May 7 '13 at 5:05
  • go to ..\PostgreSQL\9.0\data and open the file postgresql.conf in text editor/notepad
  • search for port parameter .eg: port = 5433
  • edit this to your port number.
  • go to run type services.msc and restart postgresql service.

you can check wether the parameter is set or not via query tool. just execute show port query. it will display your current port number. If are using pgAdmin to connect to db make sure you changed your port number in connection settings.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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