
How to Find Slow Queries From the Command Line the Right Way
Find slow queries from the command line: pg_stat_statements and the log in PostgreSQL, the slow query log and mysqldumpslow in MySQL, then EXPLAIN.
Tag
18 posts

Find slow queries from the command line: pg_stat_statements and the log in PostgreSQL, the slow query log and mysqldumpslow in MySQL, then EXPLAIN.

Share files between users on Linux with groups, the setgid directory and ACLs: default ACLs for new files, the mask, getfacl and common pitfalls.

Analyze logs with SQLite from the shell: parse lines into a table, import, add indexes, run top-N and time bucket queries, and know when awk is enough.

Cap runaway jobs with cgroups through systemd-run and unit settings: memory and CPU limits, task limits, MemoryHigh throttling and how to see results.

Use redis-cli for quick checks and scripts: connect safely, inspect keys with scan, read INFO and slowlog and avoid KEYS and MONITOR in production.

Keep a server responsive during heavy jobs with nice, ionice and idle scheduling: when ionice works, systemd settings, and where cgroup weights do better.

Run a script as another user with sudo -u, su -c or runuser, pass arguments without quoting bugs, keep the environment clean, and set up narrow sudoers rules.

Dump and restore a database in Docker: pg_dump and mysqldump via docker exec, volume backups, consistency, restoring into a new container and speed.

Measure the memory a command uses on Linux: peak RSS with GNU time, /proc status, PSS with smem, sampling a process and cgroup peak.

Measure time and memory of a command with GNU time: wall clock, CPU, peak memory, page faults, custom formats, logging runs and macOS differences.

Detect performance regressions with hyperfine: benchmark runs, warmups, comparing two versions, JSON export and a CI threshold check for scripts and tools.

Reduce the attack surface of a Linux server: list listening ports, remove unused packages and services, close the firewall and keep patches current.