This post shows how to list the configuration files and directories that an instance of PostgreSQL uses. Sometimes we need to know these to customize PostgreSQL.
PostgreSQL Docker Container
To keep things simple, we can start up a PostgreSQL Docker container to avoid installing PostgreSQL on our machine. Therefore, we need to install Docker on our machine and use PostgreSQL 12.
Then, run the following command.
1 | docker-compose up |
The command will start up a PostgreSQL Docker container.
1 2 3 4 5 6 7 8 9 10 11 12 | C:\Users\karldev\Desktop\dev\blogs\docker\docker-compose.yml for postgresql>docker-compose up Starting docker-composeymlforpostgresql_demo-container-db_1 ... done Attaching to docker-composeymlforpostgresql_demo-container-db_1 demo-container-db_1 | demo-container-db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization demo-container-db_1 | demo-container-db_1 | 2020-11-24 13:55:12.111 UTC [1] LOG: starting PostgreSQL 12.4 (Debian 12.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit demo-container-db_1 | 2020-11-24 13:55:12.112 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 demo-container-db_1 | 2020-11-24 13:55:12.112 UTC [1] LOG: listening on IPv6 address "::", port 5432 demo-container-db_1 | 2020-11-24 13:55:12.120 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" demo-container-db_1 | 2020-11-24 13:55:12.140 UTC [25] LOG: database system was shut down at 2020-11-24 13:54:44 UTC demo-container-db_1 | 2020-11-24 13:55:12.148 UTC [1] LOG: database system is ready to accept connections |
Next, we need to connect to the server and run a SQL statement.
PostgreSQL Configuration Files
All references to the configuration files and directories are available in the pg_settings table. Then, run the following SQL statement. We can use a PgAdmin Docker container to connect to the PostgreSQL server. Alternatively, other SQL IDEs can be used like JetBrain’s DataGrip or a PgAdmin directly installed on our machine. We can also use the psql command, which is a text-based PostgreSQL client.
1 2 3 | select name, setting from pg_settings where category='File Locations'; |
We will get the following output. For this PostgreSQL version, we have four items.
The configuration file PostgreSQL.conf contains properties that directly control the PostgreSQL server’s behaviors. These behavior include functions in auditing, and authentication, among other things. Then, the data_directory points to the location where all the PostgreSQL data typically reside. Then, the hba_file refers to the host-based authentication configuration file. Lastly, the ident_file refers to the user identification configuration file with user name mapping.
For more information on these configurations, please read The Runtime Config File Location.
Alternative Commands
Aside from using the above SQL statement, we can also use the configuration name as a parameter to the SHOW command. Consider the following command to show the value of the config_file parameter.
1 | show config_file; |
The command generates the following output.
1 2 3 4 5 | +----------------------------------------+ |config_file | +----------------------------------------+ |/var/lib/postgresql/data/postgresql.conf| +----------------------------------------+ |
We can only use the following commands.
1 2 3 4 | show data_directory; show external_pid_file; show hba_file; show ident_file; |
These commands require us to know the exact name of the configuration parameters. Otherwise, the show command will not work.