PostgreSQL Configuration – Modifying postgresql.conf Using pg_ctl

postgresqlpostgresql-9.5

I am programmatically starting PostgreSQL instances using pg_ctl init and pg_ctl start. I need to modify the configuration in postgresql.conf (specifically listen_addresses, and maybe some other values) and am trying to find a way to do this using pg_ctl, if possible. The documentation for pg_ctl and initdb make no mention of this. The section on Setting Parameters states that I can pass parameters to the postgres command, but in my case I am using pg_ctl to start the server process. Is this possible with pg_ctl or other command line tool included with PostgreSQL 9.5?

Best Answer

Reading the documentation page for pg_ctl carefully shows you what happens with the stuff you pass to it using -o:

-o options

Specifies options to be passed directly to the postgres command; multiple option invocations are appended.

So you can, for example, do the following:

pg_ctl -D {your data directory} -o "-c listen_addresses='*'" start

where the whole double-quoted expression is passed to postgres (for details, see its own documentation).

As Craig Ringer pointed out in a comment, it might be easier and, more importantly, has a lasting effect if you change these parameters using ALTER SYSTEM.