Как посмотреть расположение файла конфигурации postgresql
Перейти к содержимому

Как посмотреть расположение файла конфигурации postgresql

  • автор:

Как посмотреть расположение файла конфигурации postgresql

In addition to the postgresql.conf file already mentioned, PostgreSQL uses two other manually-edited configuration files, which control client authentication (their use is discussed in Chapter 21). By default, all three configuration files are stored in the database cluster’s data directory. The parameters described in this section allow the configuration files to be placed elsewhere. (Doing so can ease administration. In particular it is often easier to ensure that the configuration files are properly backed-up when they are kept separate.)

Specifies the directory to use for data storage. This parameter can only be set at server start.

Specifies the main server configuration file (customarily called postgresql.conf ). This parameter can only be set on the postgres command line.

Specifies the configuration file for host-based authentication (customarily called pg_hba.conf ). This parameter can only be set at server start.

Specifies the configuration file for user name mapping (customarily called pg_ident.conf ). This parameter can only be set at server start. See also Section 21.2.

Specifies the name of an additional process-ID (PID) file that the server should create for use by server administration programs. This parameter can only be set at server start.

In a default installation, none of the above parameters are set explicitly. Instead, the data directory is specified by the -D command-line option or the PGDATA environment variable, and the configuration files are all found within the data directory.

If you wish to keep the configuration files elsewhere than the data directory, the postgres -D command-line option or PGDATA environment variable must point to the directory containing the configuration files, and the data_directory parameter must be set in postgresql.conf (or on the command line) to show where the data directory is actually located. Notice that data_directory overrides -D and PGDATA for the location of the data directory, but not for the location of the configuration files.

If you wish, you can specify the configuration file names and locations individually using the parameters config_file , hba_file and/or ident_file . config_file can only be specified on the postgres command line, but the others can be set within the main configuration file. If all three parameters plus data_directory are explicitly set, then it is not necessary to specify -D or PGDATA .

When setting any of these parameters, a relative path will be interpreted with respect to the directory in which postgres is started.

Prev Up Next
20.1. Setting Parameters Home 20.3. Connections and Authentication

Submit correction

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.

Команды для просмотра конфигурационных файлов и параметров в PostgreSQL

PostgreSQLПосле установки PostgreSQL часто нужно подправить конфигурационные параметры и потом посмотреть эффект. Лично у меня бывает так, что я не помню/не знаю, где находятся конфиг.файлы (например, если происходит установка PostgreSQL из пакетов — непонятно, куда эти файлы попадут).

Если устанавливать PostgreSQL из исходных кодов, можно задать расположение этих файлов — но это расположение можно забыть, через месяц-два.

Так что решил сохранить в одном месте все (мне) известные способы посмотреть места сохранения конфиг.файлов:

Для начала — в документации есть статья о том, какие есть конфигурационные файлы — расположение файлов .

Чтобы просмотреть расположение этих файлов, необходимо воспользоваться командой psql SHOW:

Файл postgresql.auto.conf находится в каталоге с данными — в указанном выше data_directory.

Копируем путь и далее уже можем отредактировать эти файлы:

Можно посмотреть некоторые из этих файлов и не уходя из PostgreSQL-клиента — с помощью SQL-запроса:

Возможно, есть еще какие-то полезные SQL-команды, буду находить и дополнять данный список.

Where does PostgreSQL store configuration/conf files?

I have recently installed PostgreSQL on Ubuntu with the EnterpriseDB package. I can connect to the database locally, but I can’t configure it because I can’t find config files. I searched through entire hard drive and found only samples like pg_hba.conf.sample

Where are the PostgreSQL .conf files?

29 Answers 29

Or ask your database:

or, if logged in as the ubuntu user:

Ubuntu 13.04 installed using software centre :

The location for mine is:

Where are my postgres *.conf files?

Query the database with the sql query:

The reason you may have trouble finding postgresql.conf is because it is owned by postgres, not root.

Here is where mine is on Fedora 17:

Notice it is owned by postgres:

It has permission 600 which explains why you have a hard time finding it with a file search. The location of postgresql.conf will be different depending on what operating system you are using.

Here is the contents of mine:

Eric Leschinski's user avatar

To get the location of the pg_hba.conf file, you can also query the database like

You should get something like

If you have just installed it, it is possible that locate doesn’t help. In that case, the service should be running and you can run

to see where the postgresql-master is loading the config files from.

On Mac (Postgres installed using brew) :

M.javid's user avatar

Print pg_hba.conf file location:

Print postgresql.conf file location:

Feriman's user avatar

Dan Johnson's user avatar

You can find other conf files by the following command:

Note: See usage using man:

For CentOS 6 and 7 and postgresql 9.2 (and below, I suppose, possibly Fedora and Redhat as well):

For CentOS 6 and 7 postgresql 9.3 or 9.4 (and above, I suppose):

For Ubuntu 14 and postgresql 9.3:

aaryno's user avatar

The answer may be that you have not initialized the database yet. After installing postgres, but before initializing the database, the postgres*.sql files will be absent. After initializing the database the postgres*.sql files will appear. (Centos 6, Postgres 9.3 demonstrated here)

30-07-2019

In Windows 10 pro:

Sampath's user avatar

As I don’t have access to postgres account (so can’t run SHOW config_file ) and my postgres is installed on Windows, none of the answers helped me, so I’m sharing my file location for future Windows readers:

In most cases: under $PGDATA , which is normally /var/lib/postgresql/data or something similar (at least it’s the default path if you use Docker images).

I like this thread because it documents the default locations for various postgresql.conf files on various architectures.

However, I’ve also gotten in trouble by relying on those defaults on installations where they have specified alternate locations. One way to find out where a particular config file is by querying the database directly:

How do I find the path to pg_hba.conf from the shell?

I would like to obtain the path to pg_hba.conf from the shell. The path varies between versions of PostgreSQL. For instance, for 8.4 and 9.1:

I have tried the pg_config command, but it does not seem to include this information.

This is so that I can use a uniform command for opening pg_hba.conf and other PostgreSQL configuration files for editing.

8 Answers 8

pg_config is for compliation information, to help extensions and client programs compile and link against PostgreSQL. It knows nothing about the active PostgreSQL instance(s) on the machine, only the binaries.

pg_hba.conf can appear in many other places depending on how Pg was installed. The standard location is pg_hba.conf within the data_directory of the database (which could be in /home , /var/lib/pgsql , /var/lib/postgresql/[version]/ , /opt/postgres/ , etc etc etc) but users and packagers can put it wherever they like. Unfortunately.

The only valid ways find pg_hba.conf is to ask a running PostgreSQL instance where it’s pg_hba.conf is, or ask the sysadmin where it is. You can’t even rely on asking where the datadir is and parsing postgresql.conf because an init script might passed a param like -c hba_file=/some/other/path when starting Pg.

What you want to do is ask PostgreSQL:

This command must be run on a superuser session, so for shell scripting you might write something like:

and set the environment variables PGUSER , PGDATABASE , etc to ensure that the connection is right.

Yes, this is somewhat of a chicken-and-egg problem, in that if the user can’t connect (say, after screwing up editing pg_hba.conf ) you can’t find pg_hba.conf in order to fix it.

Another option is to look at the ps command’s output and see if the postmaster data directory argument -D is visible there, e.g.

since pg_hba.conf will be inside the data directory (unless you’re on Debian/Ubuntu or some derivative and using their packages).

If you’re targeting specifically Ubuntu systems with PostgreSQL installed from Debian/Ubuntu packages it gets a little easier. You don’t have to deal with hand-compiled-from-source Pg that someone’s initdb ‘d a datadir for in their home dir, or an EnterpriseDB Pg install in /opt, etc. You can ask pg_wrapper , the Debian/Ubuntu multi-version Pg manager, where PostgreSQL is using the pg_lsclusters command from pg_wrapper .

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *