24

Where are the files postgresql.conf and pg_hba.conf on a Linux server running PostgreSQL 8.4 installed from Ubuntu repos?

3
  • 4
    The problem is b/w the chair and the keyboard. It depends on how you installed it. Did you use source tar-gz file or did you use apt utility. If you download tar-gzipped file and installed it. The pg_hba.conf file does not exist yet unless you initialize your data directory. The INSTALL/Readme file has that info. You will find pg_hba.conf file in whatever you selected as your data directory. Secondly, if you used apt utility then you should find it in /etc/postgresql/8.4/main you can also do a 'find' on the filename but doing that on the entire disk is cpu-consuming. Jun 20, 2010 at 17:56
  • 1
    Installing from source to the default install location, you run the following: /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data before starting postgres and hba file will be created in that directory. Jun 20, 2010 at 17:59
  • in kubuntu v20.04 i used sudo updatedb and sudo locate pg_hba.conf
    – SL5net
    Jan 4, 2022 at 18:52

6 Answers 6

17

Looking for "pg_hba.conf ubuntu" on Google gives you

https://help.ubuntu.com/community/PostgreSQL

which shows the location of the files.

The documentation states the following:

Client authentication is controlled by a configuration file, which traditionally is named pg_hba.conf and is stored in the database cluster's data directory. (HBA stands for host-based authentication.) A default pg_hba.conf file is installed when the data directory is initialized by initdb. It is possible to place the authentication configuration file elsewhere, however; see the hba_file configuration parameter.

Note it says stored in the database cluster's data directory and that it's possible to place it elsewhere, via a configuration parameter. Official documentation cannot point you to a specific folder because the actual location depends on both how the OS maker and the machine's administrator have set PostgreSQL up. Remember PostgreSQL supports a lot of different operating systems (and Linux distributions.)

As Neutrino shows, if you can access your server via psql, you can tell it to show you the file location.

Also, two tips:

  1. locate will help you find files you know the name of but not the location
  2. Debian based distributions place under /usr/share/doc documentation on how they set up different packages by default, I'm sure you'll find under /usr/share/doc/postgresql-8.4 (or maybe just postgresql) info about the configuration files. Very useful to read in case they have modified some standard behavior.
3
  • 2
    Give a man a fish... blah blah, teach a man how to fish.. etc. The right way is to know how to have postgres tell you where the file is. Universally. show hba_file; in psql. See @neutrino's answer. Jul 17, 2019 at 10:20
  • 1
    If and only if you can access your running PostgreSQL instance. If your HBA file is messed up you might not be able to. I've linked to Neutrino's answer.
    – Vinko Vrsalovic
    Jul 18, 2019 at 8:32
  • How to find it at the remote server then? Apr 6, 2020 at 18:30
30

Open a command prompt.

> psql -U postgres
=# show hba_file;
=# show config_file

When they change the names of the config settings, or you want to see something else.

=# show all;
2
  • Yeah, this doesn't work if you can't start your pgsql database because of a "missing" postgresql.conf! It's "missing" because it's not located in /var/lib/postgresql/<VERSION>/<CLUSTER_NAME> on Ubuntu, but as someone else pointed out, in /etc/postgresql/<VERSION>/<CLUSTER_NAME>. Why does Ubuntu have to be different from everybody else? Ugh..... And because of this, simply issuing sudo -u postgres pg_ctl -D /var/lib/postgres/<VERSION>/<CLUSTER_NAME> results in an error because the postgresql.conf file is not found. Geez. :/ Jan 29 at 23:09
  • And as I learned from @milen-a-radev answer, the docs say that the -D option value really needs to be set to where the postgresql.conf file is located. That option should be renamed to -C (for --configuration) since it doesn't really need to be set to the data directory--which on most normal distros happens to be the (default) location of the postgresql.conf file, but not always (glaring at you Ubuntu....). Jan 29 at 23:16
5

Possibly

/etc/postgresql/9.*/main
4

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

1
  • As always, RTF(riendly)M. This is the right answer. Assuming that Ubuntu did things "normally", results in pg_ctl complaining that the postgresql.conf file cannot be found in the "data" directory as specified by the -D option to the pg_ctl command. Perhaps that option is a bit "mis-named" since it must point to where the postgresql.conf file is located, which on Ubuntu is in the /etc/postgres directory...of course. Ugh. I hate Ubuntu. Jan 29 at 23:12
2

As Vinko said, the location is distribution-dependent. To add to his answer:

Your package management sofware will tell you where are the files installed by each package, (for example: dpkg -L postgresql).

You can also look inside the service startup script ( typically /etc/init.d/postgresql)

2

To see the configuration files from the terminal:

psql -U postgres -c 'SHOW hba_file'
psql -U postgres -c 'SHOW config_file'

To check the data directory:

echo $PGDATA 

or

psql -U postgres -c 'SHOW data_directory'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .