Howto tell pg_ctl to use a non-default directory for config files

Поиск
Список
Период
Сортировка
Искать

Howto tell pg_ctl to use a non-default directory for config files

От:
Michael Grimm <trashcan@ellael.org>
Дата:
Hi,

FYI: I am pretty new to PostgreSQL, and I am intending to migrate from an MariaDB/Galera cluster to PostgreSQL with either Patroni or pg_auto_failover. And, I have successfully tested a stand-alone database with my client of interest [1], both running inside a FreeBSD jail. 

Question: 
Is there a way to tell PostgreSQL to look for config files in e.g. /usr/local/etc/postgres, where normally all config files reside in FreeBSD? [2]

Thanks and regards,
Michael


[1] https://dbmail.org
[2] As an intermediate solution I am using soft links from $PGDATA to /usr/local/etc/postgres

Re: Howto tell pg_ctl to use a non-default directory for config files

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Michael Grimm  writes:
> Question: 
> Is there a way to tell PostgreSQL to look for config files in e.g. /usr/local/etc/postgres, where normally all config files reside in FreeBSD? [2]

Typically you would say "pg_ctl -D /usr/local/etc/postgres" to point
it at the config file.  Then you would need the config file to include
data_directory and perhaps other settings pointing to wherever the
actual data files are.  See

https://www.postgresql.org/docs/current/runtime-config-file-locations.html

			regards, tom lane


Re: Howto tell pg_ctl to use a non-default directory for config files

От:
Michael Grimm <trashcan@ellael.org>
Дата:
Tom Lane  wrote:
> 
> Michael Grimm  writes:

>> Question: 
>> Is there a way to tell PostgreSQL to look for config files in e.g. /usr/local/etc/postgres, where normally all config files reside in FreeBSD? [2]
> 
> Typically you would say "pg_ctl -D /usr/local/etc/postgres" to point
> it at the config file.  Then you would need the config file to include
> data_directory and perhaps other settings pointing to wherever the
> actual data files are.  See
> 
> https://www.postgresql.org/docs/current/runtime-config-file-locations.html

Ah! That's what I failed to find in the documentation :-(

Thanks and regards,
Michael



Re: Howto tell pg_ctl to use a non-default directory for config files

От:
Ron Johnson <ronljohnsonjr@gmail.com>
Дата:
On Thu, Jun 4, 2026 at 4:02 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Michael Grimm <trashcan@ellael.org> writes:
> Question:
> Is there a way to tell PostgreSQL to look for config files in e.g. /usr/local/etc/postgres, where normally all config files reside in FreeBSD? [2]

Typically you would say "pg_ctl -D /usr/local/etc/postgres" to point
it at the config file.  Then you would need the config file to include
data_directory and perhaps other settings pointing to wherever the
actual data files are.
 
Is it standard to point PGDATA to an etc directory instead of to the "data" directory?

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

Re: Howto tell pg_ctl to use a non-default directory for config files

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Ron Johnson  writes:
> On Thu, Jun 4, 2026 at 4:02 PM Tom Lane  wrote:
>> Typically you would say "pg_ctl -D /usr/local/etc/postgres" to point
>> it at the config file.  Then you would need the config file to include
>> data_directory and perhaps other settings pointing to wherever the
>> actual data files are.

> Is it standard to point PGDATA to an etc directory instead of to the "data"
> directory?

It is if you want the server's configuration files to be separate from
the data.

			regards, tom lane


Re: Howto tell pg_ctl to use a non-default directory for config files

От:
Michael Grimm <trashcan@ellael.org>
Дата:
arif rahman  wrote:

> In PostgreSQL, the configuration files do not have to live inside the data directory. You can place them elsewhere and tell PostgreSQL where to find them.
> 
> # Set postgresql.conf outside the data directory
> hba_file = '/usr/local/etc/postgres/pg_hba.conf’
> 
> Then start 
> postgres -D /var/db/postgres/data \
>  -c config_file=/usr/local/etc/postgres/postgresql.conf

JFTR: that worked perfectly well.

But, I moved on to use pg_auto_failover which is very picky w.r.t. to the location of config files. Thus I will have to become used to keep config files where ever expected by the given service … shrug.

Thanks for your working setup and regards,
Michael

FAQ