6. Where everything lives
6.1 The data directory (PGDATA)
Section titled “6.1 The data directory (PGDATA)”On suta-linux-lab-1, as student:
# Switch to the postgres user (type exit to come back)sudo su - postgresNow as postgres on suta-linux-lab-1:
# The PGDG login settings set PGDATA for youecho $PGDATAExpected output:
/var/lib/pgsql/18/data# List what initdb createdls $PGDATAExpected output:
PG_VERSIONbasecurrent_logfilesgloballogpg_commit_ts...pg_walpg_xactpostgresql.auto.confpostgresql.confpostmaster.optspostmaster.pid6.2 The three configuration files
Section titled “6.2 The three configuration files”| File | Controls | Change takes effect after |
|---|---|---|
postgresql.conf |
How the server runs: memory, port, listen_addresses, logging |
Reload, or restart for some settings |
pg_hba.conf |
Who may connect, to which database, from where, and how they prove who they are | Reload |
pg_ident.conf |
Maps operating-system user names to database role names | Reload |
postgresql.auto.conf |
Settings written by ALTER SYSTEM (an SQL command that changes settings, later module). Do not edit by hand |
Reload or restart |
Every pg_hba.conf line has the same columns, in this order:
# TYPE DATABASE USER ADDRESS METHODlocal all all peerhost all all 127.0.0.1/32 scram-sha-256- TYPE:
localmeans the Unix socket on the same server.hostmeans a network (TCP/IP) connection. - DATABASE and USER: which database and which role the line applies to.
- ADDRESS: the client's IP address range. Only for
hostlines. - METHOD: how the client proves who it is.
peertrusts the Linux user name.scram-sha-256needs a password.
PostgreSQL reads the lines from top to bottom and uses the first line that matches.
Still as postgres on suta-linux-lab-1:
# Show pg_hba.conf without comments and empty linesgrep -v '^#' $PGDATA/pg_hba.conf | grep -v '^$'Expected output:
local all all peerhost all all 127.0.0.1/32 scram-sha-256host all all ::1/128 scram-sha-256local replication all peerhost replication all 127.0.0.1/32 scram-sha-256host replication all ::1/128 scram-sha-2566.3 Logs and programs
Section titled “6.3 Logs and programs”| What | Where |
|---|---|
| Server log files | /var/lib/pgsql/18/data/log/ (one file per weekday, for example postgresql-Wed.log) |
| Service messages (start, stop, failures) | journalctl -u postgresql-18 |
| initdb log | /var/lib/pgsql/18/initdb.log |
Programs (psql, pg_ctl, initdb, pg_dump and more) |
/usr/pgsql-18/bin/ |
| Home of the postgres user | /var/lib/pgsql |
Still as postgres on suta-linux-lab-1:
# Show today's log file namels $PGDATA/logExpected output (yours shows today's weekday):
postgresql-Wed.log# Return to the student userexitWas this page helpful?
Thanks. Glad it helped.
Thanks for telling us. Email the instructor what was missing, or ask in class.