How to Locate Configuration Files in PostgreSQL on Ubuntu

David Mbochi Njonge Feb 02, 2024
  1. Use the SHOW Command to Locate Configuration Files in PostgreSQL on Ubuntu
  2. Use the locate Command to Locate Configuration Files in PostgreSQL on Ubuntu
  3. Use the Running Service of PostgreSQL to Locate Configuration Files in PostgreSQL on Ubuntu
How to Locate Configuration Files in PostgreSQL on Ubuntu

A conf file adds custom configuration parameters for the database. These configuration files change how the database normally works to achieve the desired functionality.

In this tutorial, we will learn how to find the location of these files on our computer to ensure we make changes when we need to perform some customization.

Use the SHOW Command to Locate Configuration Files in PostgreSQL on Ubuntu

When logging in to the database, we can execute the following command, which returns the absolute path where the configuration file is stored.

Copy and paste the below command to the terminal and press the Enter button on your keyboard. Enter your password in the prompt that returns and press Enter again.

david@david-HP-ProBook-6470b:~$ psql -U postgres -c 'SHOW config_file'
Password for user postgres:

The following is the result of executing the above command.

               config_file
-----------------------------------------
 /etc/postgresql/14/main/postgresql.conf
(1 row)

Navigate to the returned path and find a postgresql.conf file. Edit the file as you want and ensure that you save it to make the changes persistent.

Use the locate Command to Locate Configuration Files in PostgreSQL on Ubuntu

The locate command is used to search for files in a file system. Use the following command to generate a database of files that can be searched by the locate command.

david@david-HP-ProBook-6470b:~$ sudo updatedb

To search for a configuration file named postgresql.conf in the database files generated above, copy and paste the following command to your terminal and press the Enter button on your keyboard.

david@david-HP-ProBook-6470b:~$ locate postgresql.conf

The result of the above command returns the path to the configuration file. The following is the path returned by the locate command.

/etc/postgresql/14/main/postgresql.conf
/usr/share/postgresql/14/postgresql.conf.sample

Navigate to the path returned and find a file named postgresql.conf. Edit the file and make the desired changes.

Use the Running Service of PostgreSQL to Locate Configuration Files in PostgreSQL on Ubuntu

Execute the following command to the details of the PostgreSQL service running. The details of the PostgreSQL contain information such as process id and the location of the configuration file in which we are interested.

david@david-HP-ProBook-6470b:~$ ps aux | grep 'postgres *-D'

The following is the result of executing the above command.

postgres  1165  0.0  0.2 322432 27900 ?        Ss   17:43   0:00 /usr/lib/postgresql/14/bin/postgres -D /var/lib/postgresql/14/main -c config_file=/etc/postgresql/14/main/postgresql.conf

The last value of the data returned provides the absolute path for the configuration file. Edit the file as required, and ensure you save the file to ensure the changes are persistent.

David Mbochi Njonge avatar David Mbochi Njonge avatar

David is a back end developer with a major in computer science. He loves to solve problems using technology, learning new things, and making new friends. David is currently a technical writer who enjoys making hard concepts easier for other developers to understand and his work has been published on multiple sites.

LinkedIn GitHub

Related Article - PostgreSQL Configuration