PostgreSQL – How to (Re)start Postgres on Windows Command Line in Background

postgresqlstartup

My local Postgres server is configured to start when the computer starts. I just changed postgresql.conf file and had to restart the server. I did:

pg_ctl restart

from the command line BUT that started the server on the next command prompt:

pg_ctl: old server process (PID: 2968) seems to be gone
starting server anyway
server starting

D:\>2016-10-12 16:24:48 EDT LOG:  redirecting log output to logging collector proces
2016-10-12 16:24:48 EDT HINT:  Future log output will appear in directory "pg_log".

If I ctrl-c out of it or close the command window, that closes the server. How can I use pg_ctl to (re)start the server in the background, emulating how it works by default (as a Windows service)?

Best Answer

As it turns out, it was running in the console because I didn't tell it where to stream the log. The following sent the process in the background:

pg_ctl restart -l %PGDATA%\server.log