Sub topic 5
Where Configuration and Data Live
Assume you are comfortable with the Linux command line, sudo, basic SQL, package managers, and systemd. Paths vary between distributions and installation methods, so discover them instead of guessing.
Configuration and data are different
A database server uses:
- Configuration files to define listening addresses, ports, memory limits, authentication rules, and logging.
- The data directory to store tables, indexes, transaction logs, and internal metadata.
- Runtime state such as sockets, process IDs, and temporary files.
The data directory is not a collection of files that you should edit manually. Database processes maintain its file formats and permissions.
Find PostgreSQL paths
On Debian or Ubuntu, PostgreSQL configuration commonly lives below /etc/postgresql/, while data commonly lives below /var/lib/postgresql/. The version number is part of the path.
Ask the running server for its authoritative locations:
sudo -u postgres psql -Atc "SHOW config_file; SHOW hba_file; SHOW data_directory;"The output identifies:
postgresql.conf, the main PostgreSQL configuration file.pg_hba.conf, which controls client authentication.- The active data directory.
PostgreSQL can include additional files. For example, postgresql.auto.conf is written by ALTER SYSTEM. Check the effective value from SQL rather than assuming that the first matching line in a file is active.
Find MySQL paths
MySQL commonly reads configuration from files such as /etc/my.cnf, /etc/mysql/my.cnf, and files in /etc/mysql/mysql.conf.d/. The exact search order depends on the package and startup command.
The server can report important runtime paths:
mysql -NBe "SELECT @@GLOBAL.datadir, @@GLOBAL.log_error;"To inspect the configuration files that the client tools know about, use:
mysqld --verbose --help 2>/dev/null | sed -n '/Default options are read from the following files in the given order:/,/Variables and options/p'The datadir value is the important result. MySQL usually stores table data, InnoDB files, and metadata below that directory.
Edit safely
First make a backup of a configuration file. Preserve ownership and permissions after editing. Use the database's documented configuration syntax, then validate by restarting or reloading the service and checking its logs.
Configuration changes may require a reload, while some settings require a full restart. Check the effective value after the change.
Exercise
Why should you discover the active data directory with SQL instead of assuming it is /var/lib/postgresql or /var/lib/mysql?
Show answer
Package layouts, versions, containers, and custom installations can use different paths. The running server reports the directory it actually uses.