5. See it on your server
Your server is running. In section 2 you saw its parts on a diagram. Now find each one on your own server: the processes, the memory and the files. First, meet psql, the tool you use to ask the server questions.
5.1 The postgres user and psql
Section titled “5.1 The postgres user and psql”Definition: psql is PostgreSQL's command-line client. A role is a database user. The install creates one superuser role called postgres, matching the Linux user postgres.
Peer authentication asks Linux "who is this?" and lets you in as the role with the same name. That is why the postgres Linux user needs no password to connect locally.
On suta-linux-lab-1, as student:
# Switch to the postgres user (type exit to come back)sudo su - postgressu -switches to another user with that user's full login settings.- Your prompt changes, and
whoaminow printspostgres.
Now as postgres on suta-linux-lab-1:
# Open an interactive psql session as the postgres rolepsqlExpected output:
psql (18.7)Type "help" for help.
postgres=#The prompt postgres=# means: connected to database postgres, and # means you are a superuser.
Leave psql, but stay the postgres user for the rest of this section. \q is a psql
command (it starts with a backslash) that quits psql:
-- Quit psql\q5.2 Processes
Section titled “5.2 Processes”Back to the theory: 2.1 Processes.
Still as postgres on suta-linux-lab-1:
# Ask PostgreSQL which processes are running, by typepsql -c 'SELECT pid, backend_type FROM pg_stat_activity ORDER BY backend_type;'psql -cruns one SQL command and exits.pg_stat_activityis a built-in view with one row per server process.
Expected output (your pid numbers will differ):
pid | backend_type------+------------------------------ 939 | autovacuum launcher 936 | background writer 935 | checkpointer 1207 | client backend 933 | io worker 934 | io worker 932 | io worker 940 | logical replication launcher 938 | walwriter(9 rows)The client backend row is you: the psql you just ran. The postmaster and the logger are not in
this view, so while your psql runs the server has 11 processes: these 9, plus the postmaster and the
logger. When no client is connected, it has 10.
5.3 Memory
Section titled “5.3 Memory”Back to the theory: 2.2 Memory.
Still as postgres on suta-linux-lab-1:
# Show the size of the shared data cachepsql -c 'SHOW shared_buffers;'Expected output:
shared_buffers---------------- 128MB(1 row)5.4 Storage
Section titled “5.4 Storage”Back to the theory: 2.3 Storage.
On disk, each database is a folder under base, named by a number: its OID (object identifier),
the number PostgreSQL gives every database. Still as
postgres on suta-linux-lab-1:
# Match each database to its folder numberpsql -c 'SELECT oid, datname FROM pg_database ORDER BY oid;'Expected output:
oid | datname-----+----------- 1 | template1 4 | template0 5 | postgres(3 rows)$PGDATA is a shell variable: a name that holds a value, here the path of the data directory.
A $ in front of a name means "use its value". The postgres login sets PGDATA for you. Check it:
# Print the value of the PGDATA variableecho $PGDATAExpected output:
/var/lib/pgsql/18/data# One folder per database, named by its oidls $PGDATA/baseExpected output:
1 4 5When you are done, return to student:
# 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.