MySQL
Processlist
Database Customization
SQL Commands
Database Management

how to customize show processlist in mysql?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

SHOW PROCESSLIST is useful for a quick look at what MySQL is doing, but it is not a customizable report writer. If you want filtering, sorting, extra columns, or reusable output, the practical answer is to query the underlying process information tables and views instead of trying to change the SHOW PROCESSLIST statement itself.

What SHOW PROCESSLIST Can and Cannot Do

SHOW PROCESSLIST and SHOW FULL PROCESSLIST give you a snapshot of current sessions. That is enough for quick triage, but the format is fixed.

sql
SHOW FULL PROCESSLIST;

You cannot tell that statement to hide sleeping sessions, sort by runtime, or add CPU and lock latency columns. Current MySQL documentation also recommends the Performance Schema implementation rather than relying on the older INFORMATION_SCHEMA.PROCESSLIST path, which is deprecated in modern MySQL releases.

So the real customization path is:

  • use sys.processlist for a cleaner high-level view
  • use performance_schema tables when you need more detail
  • create your own query or view for the exact output you want

Using sys.processlist for Better Filtering

If the sys schema is installed, sys.processlist is usually the best starting point. The MySQL 8.4 reference manual describes it as more complete than SHOW PROCESSLIST and nonblocking.

Here is a practical replacement that hides idle sleepers and sorts the longest-running active sessions first:

sql
1SELECT
2    conn_id,
3    user,
4    db,
5    command,
6    time,
7    state,
8    current_statement,
9    rows_examined,
10    rows_sent,
11    lock_latency
12FROM sys.processlist
13WHERE command <> 'Sleep'
14ORDER BY time DESC, lock_latency DESC;

That gives you a custom process list without changing MySQL itself. You can keep adding filters for host, user, database, or statement type as needed.

Building a Reusable Custom View

If you run the same filtered query often, turn it into a view in an admin schema:

sql
1CREATE OR REPLACE VIEW admin_active_sessions AS
2SELECT
3    conn_id,
4    user,
5    db,
6    command,
7    time,
8    state,
9    current_statement,
10    rows_examined,
11    rows_sent
12FROM sys.processlist
13WHERE command <> 'Sleep';
14
15SELECT *
16FROM admin_active_sessions
17ORDER BY time DESC;

This pattern is much more maintainable than teaching everyone on the team a different long SELECT statement.

If you need lower-level details, query performance_schema.threads or related statement tables directly. That is where you can correlate a connection with waits, instrumentation, and other performance counters.

Privileges and Operational Notes

To see all sessions, you typically need the PROCESS privilege. Without it, MySQL limits what you can see to your own threads.

Also remember that process lists are snapshots, not long-term history. If you are troubleshooting intermittent spikes, combine process list queries with slow query logs, Performance Schema history tables, or external monitoring. SHOW PROCESSLIST and its replacements tell you what is happening now, not what happened five minutes ago.

Common Pitfalls

  • Trying to change the output columns of SHOW PROCESSLIST directly. The command format is fixed.
  • Building automation on top of INFORMATION_SCHEMA.PROCESSLIST alone even though that implementation is deprecated in current MySQL documentation.
  • Forgetting the PROCESS privilege and then wondering why only your own sessions appear.
  • Looking only at Sleep time and ignoring statement latency, rows examined, or lock waits.
  • Using a one-off query every time instead of creating a reusable admin view for recurring investigations.

Summary

  • You do not really customize SHOW PROCESSLIST; you replace it with custom queries against better process information sources.
  • In modern MySQL, sys.processlist and Performance Schema are the preferred foundations.
  • Filtering out sleepers and sorting by time or lock latency makes active issues much easier to spot.
  • Create a view if your team needs the same custom process list repeatedly.
  • Use process lists for live inspection, and combine them with longer-term monitoring for historical analysis.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.