#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    209
    Rep Power
    9

    Use environment variables in postgresql.conf


    Is it possible to use environment variables in postgresql.conf and perhaps related configuration files?

    For example, I would like to use an env variable to specify the data directory.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    158
    Rep Power
    10
    I've never seen that, but I'd also advise against it because it makes your database depend on wether you remembered to setup your ENV variables properly. If you lose that var, for whatever reason, you cannot start the database. Murphy says that will happen at the most annoying moment you can imagine.

    *if* you want to switch the data directory around, why not specify it in the startup script? Then you can use an ENV in the command that starts the database and you'd basically have what you want (with the same reasons why you probably shouldn't do that either)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,781
    Rep Power
    348
    Originally Posted by imagenesis
    Is it possible to use environment variables in postgresql.conf and perhaps related configuration files?

    For example, I would like to use an env variable to specify the data directory.
    You can do it the other way round: Postgres will take the value of the environment variable DATADIR
    Originally Posted by The Manual
    -D datadir
    --pgdata datadir

    Specifies the file system location of the database configuration files. If this is omitted, the environment variable PGDATA is used.
    Taken from: http://www.postgresql.org/docs/current/static/app-pg-ctl.html
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

IMN logo majestic logo threadwatch logo seochat tools logo