9

I had installed PostgreSQL but when I do run command postgres in windows CMD

It gives following error:

postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

Even after running command

  • initdb postgres as maintained similar Issue
  • postgres -D C:\Program Files\PostgreSQL\data\ gave me following output:
2016-09-28 15:04:57 PDT LOG:  could not bind IPv6 socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.
2016-09-28 15:04:57 PDT HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-09-28 15:04:57 PDT LOG:  could not bind IPv4 socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.    
2016-09-28 15:04:57 PDT HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-09-28 15:04:57 PDT WARNING:  could not create listen socket for "*"
2016-09-28 15:04:57 PDT FATAL:  could not create any TCP/IP sockets
2016-09-28 15:04:57 PDT LOG:  database system is shut down
5
  • 1
    What exactly are you trying to do? You should use pg_ctl to start the Postgres server. Do not use postgres for that. Commented Sep 28, 2016 at 9:39
  • I want to connect database to my django application so I need some database as well user in my db Commented Sep 28, 2016 at 9:43
  • 2
    If you installed Postgres using the graphical installer it will create a Windows service that will start automatically. Do you have a Windows service for Postgres? Why do you think you need to run postgres.exe manually? What happens if you use psql to connect to Postgres? Commented Sep 28, 2016 at 9:46
  • Your second suggestion worked. thanks Commented Sep 28, 2016 at 9:51
  • 1
    For Mac, "brew services start postgresql" worked. Commented Mar 31, 2021 at 17:47

1 Answer 1

7

As the error says, to start a postgresql cluster you must set the path to the data folder. Probably something like:

postgres -D "C:\Program Files\PostgreSQL\data\"

but the use of pg_ctl instead postgres is recommended:

pg_ctl -D "C:\Program Files\PostgreSQL\data\" start

Don't forget to check the postgres documentation about how to start a server and how to use pg_ctl.

Usually, the postgres installlers creates a service/daemon so there is not need to launch the server by hand. So if you get an error like

Is another postmaster already running on port 5432?

It probably means that the server is already running. Try to connect to it using psql

Sign up to request clarification or add additional context in comments.

3 Comments

It gives: postgres: invalid argument: "Files\PostgreSQL\9.6\data" Try "postgres --help" for more information.
@AkhileshKumar Use double quotes: -D "C:\Program Files\PostgreSQL\data\" but you should use pg_ctl to start Postgres, not postgres.exe
Altough server is started but still when I'm running command "postgres" it gives the same error

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.