// dialect comparison

SHOW PROCESSLIST and session views in every SQL dialect

The who-is-connected view, including state and the current statement, needed before you kill anything.

Filed under Sessions & admin

The verdict

Four session views with the same shape (id, user, source, state, statement) and no portable column names. pg_stat_activity is the most query-friendly; v$session and sys.dm_exec_sessions need joins for the current SQL.

Where they differ

Server engines all expose a session table; the columns and names differ. SQLite has no sessions to list because there is no server.

How each engine writes it

SQL Server

SELECT session_id, login_name, host_name, program_name, status
FROM sys.dm_exec_sessions
WHERE is_user_process = 1;

Pair with sys.dm_exec_requests for running statements, or sys.dm_exec_connections for network details. sp_who2 still works but the DMVs are the real API.

PostgreSQL

SELECT pid, usename, application_name, client_addr, state, query
FROM pg_stat_activity;

state = active means a running statement; idle in transaction is the state to hunt for. Requires pg_monitor or similar for other users' queries.

MySQL

SHOW PROCESSLIST;
-- equivalent: SELECT * FROM information_schema.processlist;

PROCESSLIST privilege shows all connections, otherwise only your own. Time and State columns point at long-running or stuck sessions.

SQLite

-- no server, no connections to list

Embedded: the process holding the file is invisible to the database. Check open file handles (lsof on the .db file) if you must.

Oracle

SELECT sid, serial#, username, status, machine, program
FROM v$session
WHERE username IS NOT NULL;

Rows with username NULL are background processes. Join v$process for OS pids; status ACTIVE means currently executing.

Questions that come up

Which sessions matter most?

idle in transaction (PostgreSQL), sleeping with open transactions (SQL Server via sys.dm_tran_session_transactions), and long Time rows in MySQL: they hold locks and block cleanup.

Can I see the running SQL too?

Yes: join sys.dm_exec_sql_text in SQL Server, read the query column of pg_stat_activity, join v$session to v$sql in Oracle, and in MySQL use SHOW FULL PROCESSLIST, since plain SHOW PROCESSLIST cuts the Info column at 100 characters.

Why fewer rows than expected in pg_stat_activity?

Non-superusers only see their own sessions plus generic details of others; grant pg_monitor for full visibility.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.