Reputation: 36422
I want to find out the installation location of Postgresql and need to make some changes in postgresql.conf and pg_hba.conf files and restart Postgresql.
Is there any way to identify the installation directory which can be applied to Windows/Unix/Linux ? Any help or suggestion will be really appreciated.
Upvotes: 0
Views: 786
Reputation: 324501
Ask PostgreSQL:
SHOW config_file;
SHOW hba_file;
or:
SELECT current_setting('config_file');
SELECT current_setting('hba_file');
This, of course, requires PostgreSQL to be running, listening on TCP/IP, and on the default port. It also requires you to be able to authenticate. You would need to prompt the user for the port (default to 5432) and credentials.
There is no generic way to determine the PostgreSQL data directory location without asking a running PostgreSQL instance, because:
pg_ctl
, etc. A data directory can be specified on the startup command line.So the whole idea that you can figure out "the" location of the PostgreSQL datadir is bogus.
If you're writing software that relies on PostgreSQL, consider bundling your own copy with the .zip binaries, starting it with pg_ctl
and running it on a non-default port so it doesn't interfere with any PostgreSQL install the user may've put on their system themselves.
Upvotes: 1
Reputation: 19185
You can define custom environment variable like POSTGRES_HOME
and use it similar to JAVA_HOME
POSTGRES_HOME = /usr/local/pgsql
pg_hba.conf path = POSTGRES_HOME/data/pg_hba.conf
Upvotes: 0