The Linux commands a working engineer reaches for: every one our lessons ask you to type, and the important ones no lesson teaches yet. Each card gives the forms worth knowing, who is allowed to run it, and how to get the same answer on a Mac — with a line for Windows. Open a command for the details, and follow a link to the lesson that explains it.
Every one of these is an ordinary program running in user mode, or a builtin the shell runs itself; none runs inside the kernel. When a command needs the kernel it asks through a system call, and the kernel checks whether the caller may. Who can run it says how that check goes: any user, only root (the administrator account, user id 0) or a process holding the one Linux capability that grants that power, or root only for some of its forms.
Processes and scheduling
List, signal, prioritise and pin the programs running on a machine.
Any userShell builtinLinux: Built inmacOS: Built inWindows: No equivalent
bg — background
Lets a stopped job carry on running in the background.
Forms, platforms and lessons
Common forms
bg
Continue the most recent stopped job in the background.
Who can run it · Any user
The shell sends SIGCONT to its own child process group, which needs no privilege.
Needs rootLinux: Built inmacOS: No equivalentWindows: Different tool
chrt
Runs a program, or changes a running one, under a real-time scheduling policy such as SCHED_FIFO, which runs ahead of every ordinary process.
Forms, platforms and lessons
Common forms
chrt -f 50 program
Run under SCHED_FIFO at real-time priority 50.
chrt -p PID
Show a process’s policy and priority.
Who can run it · Needs root
Real-time policies can starve the rest of the machine, so the kernel asks for root or CAP_SYS_NICE (or a raised RLIMIT_RTPRIO limit) before granting one. Showing a policy needs nothing.
On each platform
Linux Built in
From util-linux.
macOS No equivalent
No equivalent. taskpolicy moves a process between Apple’s quality-of-service tiers, which is not real-time scheduling.
Windows Different tool
start /realtime program starts a program in the real-time priority class.
Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool
nice
Starts a program with a lower (or higher) scheduling priority, expressed as a nice value from −20, most favoured, to 19, least.
Forms, platforms and lessons
Common forms
nice -n 10 make
Run make ten steps “nicer”, so other work gets the CPU first.
Who can run it · Some forms need root
Anyone may make their own work nicer. A negative value, which takes CPU from others, needs root or the CAP_SYS_NICE capability.
On each platform
Linux Built in
From coreutils.
macOS Built in
The same command and range.
Windows Different tool
start /belownormal program starts a program at a lower priority class. Windows has six classes (low, below normal, normal, above normal, high, realtime) rather than nice values.
Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool
pgrep — process grep
Also covers pkill
Finds processes by name or other attributes and prints their IDs; pkill signals them instead.
Forms, platforms and lessons
Common forms
pgrep -a nginx
IDs and command lines of processes named nginx.
pkill -HUP nginx
Send SIGHUP to them, often a “reload your configuration” request.
Who can run it · Some forms need root
Finding is open to anyone; pkill follows kill’s rules, so another user’s processes need root.
On each platform
Linux Built in
From procps-ng.
macOS Built in
The same commands.
Windows Different tool
tasklist /fi "imagename eq x.exe" and taskkill /im x.exe.
Taught in
Not yet taught in a lesson.
Any userLinux: Built inmacOS: Built inWindows: Different tool
ps — process status
A snapshot of the processes running now: their IDs, owners, states and the commands that started them.
Forms, platforms and lessons
Common forms
ps
Your own processes in this terminal.
ps -e
Every process on the machine (-e, every).
ps -ef
Every process, in full format: owner, parent ID, start time and whole command line.
ps -e | wc -l
Count them.
Who can run it · Any user
The kernel publishes every process under /proc for any user to read, so anyone can list everything; only a few details of other users’ processes, such as their environment, are withheld.
On each platform
Linux Built in
From procps-ng, in every distribution.
macOS Built in
The BSD ps; -e and -f work, though the columns differ from Linux’s.
Windows Different tool
tasklist lists processes, and PowerShell’s Get-Process returns them as objects you can sort and filter.
Any userLinux: Built inmacOS: Built inWindows: Different tool
top — the processes at the top of CPU use
A live, refreshing table of the busiest processes, with the CPU split into time in user programs and time in the kernel.
Forms, platforms and lessons
Common forms
top
The live view; press q to quit.
top (us, sy)
The us share is CPU time in user mode, sy time in the kernel on programs’ behalf.
Who can run it · Any user
It only reads what the kernel publishes under /proc, which any user may read. Killing or renicing from inside it follows the same rules as kill and renice.
On each platform
Linux Built in
From procps-ng. htop is a friendlier alternative to install.
macOS Built in
Apple’s own top: the same idea with different keys and columns; top -o cpu sorts by CPU. Activity Monitor is the graphical version.
Windows Different tool
Task Manager is the graphical view. In PowerShell, Get-Process | Sort-Object CPU -Descending gives a one-off ranking.
Needs rootLinux: Install itmacOS: Built inWindows: Different tool
iotop
A top for disk I/O: which processes are reading and writing, and how fast.
Forms, platforms and lessons
Common forms
iotop -o
Only processes doing I/O now.
Who can run it · Needs root
It reads per-task I/O accounting through a kernel interface that needs root, or the CAP_NET_ADMIN capability granted to its binary.
On each platform
Linux Install it
The iotop package.
macOS Built in
A DTrace script of the same name, runnable only as root.
Windows Different tool
Resource Monitor’s Disk tab.
Taught in
Not yet taught in a lesson.
Some forms need rootLinux: Install itmacOS: Different toolWindows: No equivalent
ltrace — library call trace
Like strace one level up: prints the shared-library calls a program makes, such as malloc and strlen.
Forms, platforms and lessons
Common forms
ltrace ./prog
Every library call with its arguments and result.
Who can run it · Some forms need root
It uses ptrace, under the same rules as strace.
On each platform
Linux Install it
The ltrace package; not available on every architecture.
macOS Different tool
dtrace’s pid provider traces function calls, as root.
Windows No equivalent
No equivalent.
Taught in
Not yet taught in a lesson.
Any userLinux: Install itmacOS: No equivalentWindows: Different tool
mpstat
Per-CPU utilisation at an interval: user, system, I/O wait, interrupts and idle for each core, so one saturated core stands out.
Forms, platforms and lessons
Common forms
mpstat -P ALL 1
Every CPU, every second.
Who can run it · Any user
It reads what the kernel publishes under /proc, which any user may read.
On each platform
Linux Install it
The sysstat package.
macOS No equivalent
No equivalent; Activity Monitor’s CPU History window shows per-core load.
Windows Different tool
typeperf with the per-processor counters.
Taught in
Not yet taught in a lesson.
Some forms need rootLinux: Install itmacOS: Different toolWindows: Different tool
perf — performance
Linux’s performance tool: counts hardware events such as cache misses, samples where CPU time goes, and records traces, all through the kernel’s performance-counter interface.
Forms, platforms and lessons
Common forms
perf stat ./prog
Run a program and print its event counts: cycles, instructions, branch misses.
perf stat -e cache-references,cache-misses ./prog
Count only the events you name.
perf top
A live ranking of the functions using the CPU, across programs and the kernel.
perf record -g ./prog
Sample with call stacks; perf report reads the result.
Who can run it · Some forms need root
Measuring your own programs is allowed by default. Watching the whole system or the kernel needs root, the CAP_PERFMON capability, or a lowered kernel.perf_event_paranoid setting.
On each platform
Linux Install it
Ships with the kernel source; distributions package it as perf or linux-tools matched to the running kernel.
macOS Different tool
sample profiles one process from the command line; Instruments (and its command-line form xctrace) comes with Xcode.
Windows Different tool
Windows Performance Recorder captures CPU samples and events, and Windows Performance Analyzer reads them.
Some forms need rootLinux: Built inmacOS: Different toolWindows: Different tool
pmap — process map
Prints a process’s memory map: each region’s address, size, permissions and the file it maps.
Forms, platforms and lessons
Common forms
pmap -x PID
Extended: resident and dirty sizes per region.
Who can run it · Some forms need root
Your own processes are open to you; another user’s map needs root, like reading their /proc/PID/maps.
On each platform
Linux Built in
From procps-ng.
macOS Different tool
vmmap PID.
Windows Different tool
VMMap (Sysinternals).
Taught in
Not yet taught in a lesson.
Any userLinux: Install itmacOS: No equivalentWindows: Different tool
sar — system activity reporter
The system activity reporter: records CPU, memory, disk and network statistics all day, so you can look back at what happened at 3 a.m.
Forms, platforms and lessons
Common forms
sar -u 1 5
CPU use, five one-second samples.
sar -n DEV
Network interface statistics from today’s history.
Who can run it · Any user
It reads what the kernel publishes under /proc, which any user may read.
On each platform
Linux Install it
The sysstat package, with its collection service enabled.
macOS No equivalent
No equivalent.
Windows Different tool
Performance Monitor data collector sets (logman).
Taught in
Not yet taught in a lesson.
Some forms need rootLinux: Install itmacOS: Different toolWindows: Different tool
strace — system-call trace
Prints every system call a program makes, with its arguments and result: the most direct view of a program’s conversation with the kernel.
Forms, platforms and lessons
Common forms
strace ls
Trace one command from start to finish.
strace -f bash -c 'ls; true'
Follow child processes too (-f, follow forks).
strace -c ls
Count calls and time per call instead of printing each one.
strace -p PID
Attach to a running process.
Who can run it · Some forms need root
Tracing a program you start is always allowed. Attaching to a running process uses ptrace, which most distributions limit (through the Yama ptrace_scope setting) to your own descendants unless you have root or CAP_SYS_PTRACE.
On each platform
Linux Install it
The strace package; often preinstalled.
macOS Different tool
dtruss prints system calls using DTrace; it needs root, and System Integrity Protection stops it tracing Apple’s own programs. fs_usage shows file-system calls.
Windows Different tool
Process Monitor (Sysinternals) records file, registry, network and process activity.
Any userLinux: Install itmacOS: No equivalentWindows: No equivalent
valgrind
Runs a program on a simulated CPU that checks every memory access: finds leaks, use after free and reads of uninitialised memory; its other tools profile caches and calls.
Forms, platforms and lessons
Common forms
valgrind --leak-check=full ./prog
Report each leaked allocation with the stack that made it.
Who can run it · Any user
It runs your program as an ordinary user process, only much slower.
On each platform
Linux Install it
The valgrind package.
macOS No equivalent
Not supported on current macOS (Valgrind lists Intel Macs up to macOS 11); leaks finds leaks, and the compilers’ AddressSanitizer finds bad accesses.
Windows No equivalent
No equivalent; compilers’ AddressSanitizer covers much of it.
Taught in
Not yet taught in a lesson.
Any userLinux: Built inmacOS: Different toolWindows: Different tool
vmstat — virtual memory statistics
One line per interval summarising the whole machine: runnable processes, memory, swapping, block I/O, interrupts, context switches and the CPU split.
Forms, platforms and lessons
Common forms
vmstat 1
Print a new line every second; the first line is the average since boot.
Who can run it · Any user
It reads system-wide counters from /proc, open to any user.
On each platform
Linux Built in
From procps-ng.
macOS Different tool
vm_stat shows memory and paging only; top and Activity Monitor give the rest.
Windows Different tool
typeperf prints chosen performance counters at an interval, and PowerShell’s Get-Counter returns them.
Needs rootLinux: Built inmacOS: Built inWindows: Different tool
chown — change owner
Changes which user (and group) owns a file.
Forms, platforms and lessons
Common forms
chown alice file
Make alice the owner.
chown :staff file
Change only the group.
Who can run it · Needs root
Giving a file to another user needs root or CAP_CHOWN; otherwise anyone could hand files to others. An owner may change only the group, and only to a group they belong to.
On each platform
Linux Built in
From coreutils.
macOS Built in
The same command.
Windows Different tool
icacls file /setowner user, or takeown to take ownership yourself; both need an administrator.
Any userLinux: Built inmacOS: Built inWindows: Different tool
cp — copy
Copies files, or with -a whole trees with their permissions, owners and times kept.
Forms, platforms and lessons
Common forms
cp report.txt /dev/null
Copy into the null device: the bytes are read and thrown away.
cp -a /lower /upper
Archive copy: recursive, keeping metadata, as an overlay file system’s copy-up does.
Who can run it · Any user
The kernel checks ordinary file permissions: you need write and search permission on the directory being changed. Keeping another user as owner (-a run by an ordinary user) silently falls back to you.
On each platform
Linux Built in
From coreutils.
macOS Built in
The BSD cp; -a works.
Windows Different tool
cmd’s copy and robocopy, or PowerShell’s Copy-Item, which also answers to cp on Windows.
Any userLinux: Built inmacOS: Built inWindows: Different tool
ln — link
Makes a second name for a file: a hard link (another directory entry for the same inode), or with -s a symbolic link holding a path.
Forms, platforms and lessons
Common forms
ln target name
A hard link: both names reach the same inode.
ln -s target name
A symbolic link: a small file containing the path target.
Who can run it · Any user
The kernel checks ordinary file permissions: you need write and search permission on the directory being changed. Many distributions also refuse a hard link to a file you neither own nor can read and write (fs.protected_hardlinks).
On each platform
Linux Built in
From coreutils.
macOS Built in
The same command.
Windows Different tool
cmd’s mklink (/h for a hard link), or PowerShell’s New-Item -ItemType HardLink or SymbolicLink. PowerShell’s documentation notes that a symbolic link needs an administrator.
Any userLinux: Built inmacOS: Built inWindows: Different tool
readlink — read link
Prints where a symbolic link points; with -f, the fully resolved absolute path.
Forms, platforms and lessons
Common forms
readlink -f /usr/bin/python3
Follow every link to the real file.
readlink /proc/PID/exe
Which program a process is running.
Who can run it · Any user
It reads the link itself, which needs only search permission on the path.
On each platform
Linux Built in
From coreutils.
macOS Built in
The same command, including -f.
Windows Different tool
(Get-Item link).Target in PowerShell.
Taught in
Not yet taught in a lesson.
Any userLinux: Built inmacOS: Built inWindows: Different tool
rm — remove
Removes a name from a directory. The file itself is freed only when its last name is gone and no process still has it open.
Forms, platforms and lessons
Common forms
rm big.log
Unlink the name; a process holding the file open keeps the space in use.
Who can run it · Any user
The kernel checks ordinary file permissions: you need write and search permission on the directory being changed. In a sticky directory such as /tmp you may remove only your own files.
On each platform
Linux Built in
From coreutils.
macOS Built in
The same command.
Windows Different tool
cmd’s del, or PowerShell’s Remove-Item, which also answers to rm on Windows.
Any userLinux: Install itmacOS: Install itWindows: Install it
fio — flexible I/O tester
A flexible I/O benchmark: describes a workload (random or sequential, block size, queue depth, direct or buffered) and measures throughput and latency.
Needs rootLinux: Built inmacOS: Built inWindows: Different tool
mount
Attaches a file system to a directory in the tree; with no arguments, lists what is mounted.
Forms, platforms and lessons
Common forms
mount -t ext4 /dev/sdb1 /mnt/usb
Mount a device’s ext4 file system at /mnt/usb.
mount --bind a b
Make the subtree at a appear at b too.
mount -t overlay …
Stack layers into one view, as container runtimes do.
Who can run it · Needs root
Mounting changes what every process sees, so the kernel requires root or CAP_SYS_ADMIN, except inside your own mount namespace or for entries marked user in /etc/fstab.
On each platform
Linux Built in
From util-linux.
macOS Built in
The BSD mount; diskutil mount is the usual way to mount a disk.
Windows Different tool
Windows mounts volumes at drive letters or empty folders: mountvol, or Disk Management.
List the files each commit of the last year touched, one name per line, with no commit headers: the raw material for counting how often each file changes.
git commit
Record a snapshot.
Who can run it · Any user
Reading and writing a repository's files and its history is ordinary file access; the kernel asks nothing more.
On each platform
Linux Install it
The git package.
macOS Install it
Installed with the Xcode Command Line Tools (xcode-select --install).
Any userLinux: Built inmacOS: Different toolWindows: No equivalent
ld.so
The dynamic linker: the program the kernel starts first for a dynamically linked executable, which loads its libraries and binds its symbols before main runs.
Forms, platforms and lessons
Common forms
LD_PRELOAD=lib.so prog
Ask the dynamic linker to load lib.so first, so its symbols win.
Who can run it · Any user
It runs inside your own process. For setuid programs it switches to secure-execution mode, ignoring LD_LIBRARY_PATH and restricting LD_PRELOAD, so they cannot be hijacked.
On each platform
Linux Built in
Part of glibc, usually as /lib64/ld-linux-x86-64.so.2.
macOS Different tool
dyld, controlled by DYLD_* variables.
Windows No equivalent
No command: the Windows loader is part of the system.
Needs rootLinux: Built inmacOS: Different toolWindows: Different tool
nft — netfilter tables
The nftables front end: the current Linux firewall, which replaces iptables with one rule language for every protocol.
Forms, platforms and lessons
Common forms
nft list ruleset
Print every table, chain and rule.
Who can run it · Needs root
Root or CAP_NET_ADMIN, as for iptables.
On each platform
Linux Built in
The nftables package, standard on current distributions.
macOS Different tool
pfctl.
Windows Different tool
Windows Defender Firewall.
Taught in
Not yet taught in a lesson.
Any userLinux: Built inmacOS: Built inWindows: Install it
openssl
A toolkit for keys, certificates and TLS: inspect a server’s certificate chain, make keys, compute hashes.
Forms, platforms and lessons
Common forms
openssl s_client -connect host:443
Open a TLS connection and print the certificate chain.
openssl x509 -in cert.pem -noout -text
Decode a certificate.
Who can run it · Any user
Ordinary files and sockets.
On each platform
Linux Built in
OpenSSL, present on most distributions.
macOS Built in
/usr/bin/openssl is LibreSSL, a fork; OpenSSL itself is in Homebrew.
Windows Install it
Third-party builds; Git for Windows includes one.
Taught in
Not yet taught in a lesson.
Any userLinux: Built inmacOS: Built inWindows: Built in
ping
Sends ICMP echo requests and reports each reply’s round-trip time, to test whether a host is reachable.
Forms, platforms and lessons
Common forms
ping -c 4 example.com
Four probes, then a summary.
Who can run it · Any user
Modern Linux lets ordinary users send pings through ICMP sockets (net.ipv4.ping_group_range); older systems gave the binary the CAP_NET_RAW capability.
Needs rootLinux: Install itmacOS: Install itWindows: Install it
docker
Builds and runs containers: processes in their own namespaces and cgroups, on a layered file system, managed by the Docker daemon.
Forms, platforms and lessons
Common forms
docker run --rm -it ubuntu bash
Start a shell in a fresh container.
docker run --cpus=2 --memory=1g img
Run with cgroup limits.
docker run -v "$PWD":/app img
Bind-mount the current directory into the container.
Who can run it · Needs root
The command talks to the Docker daemon, which runs as root unless set up in rootless mode, so Docker warns that only trusted users should control it: whoever does can mount any host directory into a container.
On each platform
Linux Install it
Docker Engine from Docker or the distribution.
macOS Install it
Docker Desktop runs a small Linux virtual machine, because containers need a Linux kernel.
Windows Install it
Docker Desktop, running Linux containers in WSL 2.
Any userLinux: Built inmacOS: Built inWindows: No equivalent
sh — shell
The POSIX shell: reads commands, starts a process for each, and wires up pipes and redirections.
Forms, platforms and lessons
Common forms
sh script.sh
Run a script.
sh comfile >output
The shell opens output for the command before running it.
Who can run it · Any user
A shell is an ordinary program that starts other programs.
On each platform
Linux Built in
Usually dash (Debian, Ubuntu) or bash.
macOS Built in
/bin/sh re-executes as bash, dash or zsh, chosen by a system link.
Windows No equivalent
No equivalent: cmd and PowerShell are different languages. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.
Any userLinux: Built inmacOS: Built inWindows: Different tool
sudo
Runs one command as root (or another user), if the system’s sudoers policy lets you.
Forms, platforms and lessons
Common forms
sudo perf top
Run perf top with root’s powers.
sudo -l
What you are allowed to run.
Who can run it · Any user
Any user may run it, but it grants anything only to users the sudoers file names. It works because it is a setuid-root program that checks the policy first.
On each platform
Linux Built in
From sudo.
macOS Built in
The same program; administrators may use it.
Windows Different tool
“Run as administrator”; recent Windows 11 builds also offer a sudo command.
The programs that ship with PostgreSQL: the server, its client, and backup, upgrade and repair tools.
Any userLinux: Install itmacOS: Install itWindows: Install it
initdb
Creates a new database cluster: the data directory, its system catalogs and the template databases. Settings such as data checksums, encoding and default collation are fixed here.
Forms, platforms and lessons
Common forms
initdb -D datadir
Create a cluster.
initdb -D datadir --data-checksums
With page checksums, which detect corruption.
Who can run it · Any user
It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Any userLinux: Install itmacOS: Install itWindows: Install it
pg_amcheck
Checks tables and B-tree indexes for corruption, using the amcheck extension, across a whole database.
Forms, platforms and lessons
Common forms
pg_amcheck -d db --heapallindexed
Also check that every heap tuple has its index entries.
Who can run it · Any user
A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as. Its checks run as the connected role, which needs permission to use amcheck.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Any userLinux: Install itmacOS: Install itWindows: Install it
pg_basebackup
Takes a physical copy of a running cluster over the replication protocol: the starting point for a standby or a point-in-time recovery.
Forms, platforms and lessons
Common forms
pg_basebackup -D backup -X stream -P
A full copy, streaming the WAL it needs, with progress.
pg_basebackup --incremental=manifest -D inc
Only blocks changed since an earlier backup.
Who can run it · Any user
A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as. The role needs the REPLICATION attribute.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Any userLinux: Install itmacOS: Install itWindows: Install it
pg_checksums
Enables, disables or verifies data-page checksums on a cluster that has been shut down cleanly.
Forms, platforms and lessons
Common forms
pg_checksums --enable -D datadir
Turn checksums on (rewrites every page).
Who can run it · Any user
It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Any userLinux: Install itmacOS: Install itWindows: Install it
pg_controldata
Prints the cluster’s control file: its state, the latest checkpoint’s position, the next transaction ID, and whether checksums are on.
Forms, platforms and lessons
Common forms
pg_controldata -D datadir
Everything in the control file.
Who can run it · Any user
It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Windows Install it
Installed with PostgreSQL’s Windows installer.
Taught in
Not yet taught in a lesson.
Any userLinux: Install itmacOS: Install itWindows: Install it
pg_ctl — PostgreSQL control
Starts, stops, reloads and promotes a server running on a data directory.
Forms, platforms and lessons
Common forms
pg_ctl -D datadir start
Start the server in the background.
pg_ctl -D datadir stop -m fast
Stop, disconnecting clients and rolling back their transactions.
pg_ctl promote -D datadir
Turn a standby into a primary.
Who can run it · Any user
It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Any userLinux: Install itmacOS: Install itWindows: Install it
pg_dump
Exports one database as SQL or an archive, taking a consistent snapshot while the database stays in use.
Forms, platforms and lessons
Common forms
pg_dump -Fc db > db.dump
Custom-format archive, for pg_restore.
pg_dump -s db
Schema only.
Who can run it · Any user
A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as. It needs read access to everything it dumps.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Any userLinux: Install itmacOS: Install itWindows: Install it
pg_isready
Checks whether a server is accepting connections, for scripts and health checks.
Forms, platforms and lessons
Common forms
pg_isready -h host
Exit status 0 when accepting connections.
Who can run it · Any user
A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Windows Install it
Installed with PostgreSQL’s Windows installer.
Taught in
Not yet taught in a lesson.
Any userLinux: Install itmacOS: Install itWindows: Install it
pg_receivewal
Streams the write-ahead log from a server to local files as it is written, for continuous archiving.
Forms, platforms and lessons
Common forms
pg_receivewal -D walarchive --slot=archiver
Stream into a directory, holding a replication slot.
Who can run it · Any user
A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as. The role needs REPLICATION.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Rewind this stopped cluster to match the new primary.
Who can run it · Any user
It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb. The target needs wal_log_hints or data checksums.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Hard-link data files instead of copying: fast, but the old cluster cannot be used afterwards.
Who can run it · Any user
It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Any userLinux: Install itmacOS: Install itWindows: Install it
pgbench — PostgreSQL benchmark
Runs a benchmark against PostgreSQL: a built-in TPC-B-like workload or your own scripts, with many clients, reporting transactions per second and latency.
Forms, platforms and lessons
Common forms
pgbench -i -s 50 db
Create the test tables at scale factor 50.
pgbench -c 32 -j 8 -T 60 db
Thirty-two clients for a minute.
Who can run it · Any user
A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
Windows Install it
Installed with PostgreSQL’s Windows installer.
Taught in
Not yet taught in a lesson.
Any userLinux: Install itmacOS: Install itWindows: Install it
postgres
The database server itself. Normally started for you by a service manager or pg_ctl; run by hand mainly in single-user mode for emergency repair.
Forms, platforms and lessons
Common forms
postgres --single -D datadir db
Single-user mode, the last resort when the server refuses connections to prevent transaction-ID wraparound.
Who can run it · Any user
It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.
On each platform
Linux Install it
Installed with PostgreSQL’s packages.
macOS Install it
Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.