2

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?

  • Why do you need this to be done through pg_ctl? Why can't you edit the file or use alter system? – a_horse_with_no_name Nov 10 '16 at 15:10
3

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.

  • 1
    Note that this doesn't persistently modify the config, it's only for that invocation. You can use ALTER SYSTEM SET ... to modify config permanently. – Craig Ringer Nov 10 '16 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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