Debug postgresql

As with disk iotop, use pg_top for postgresql

Debian install package pgtop

pg_top

^L
Redraw the screen.
A
Display the actual query plan (EXPLAIN ANALYZE) of the currently running SQL statement by re-running the SQL statement (prompt for process id.)
C
Toggle the use of color in the display.
c
Toggle the display of the full command line.
d
Change the number of displays to show (prompt for new number). Remember that the next display counts as one, so typing d1 will make pg_top show one final display and then immediately exit.
h or ?
Display a summary of the commands (help screen). Version information is included in this display.
E
Display re-determined execution plan (EXPLAIN) of the SQL statement by a backend process (prompt for process id.)
e
Display a list of system errors (if any) generated by the last kill or renice command.
i
(or I) Toggle the display of idle processes.
k
Send a signal ("kill" by default) to a list of processes. This acts similarly to the command kill(1)).
L
Display the currently held locks by a backend process (prompt for process id.)
M
Order by memory utilization.
N
Sort by process id.
n or #
Change the number of processes to display (prompt for new number).
o
Change the order in which the display is sorted. This command is not available on all systems. The sort key names when viewing processes vary fron system to system but usually include: "cpu", "res", "size", "time". The default is cpu. When viewing user table statistics: "seq_scan", "seq_tup_read", "idx_scan", "idx_tup_fetch", "n_tup_ins", "n_tup_upd", "n_tup_del". The default is seq_scan. When viewing user index statistics: "idx_scan", "idx_tup_fetch", "idx_tup_read". The default is idx_scan.
P
Sort by processor utilization.
Q
Display the currently running query of a backend process (prompt for process id.)
q
Quit pg_top.
R
Display user table statistics.
r
Change the priority (the "nice") of a list of processes. This acts similarly to the command renice(8)).
s
Change the number of seconds to delay between displays (prompt for new number).
T
Order by time.
t
Toggle between cumulative or differential statistics when viewing user table or user index statistics.
u
Display only processes owned by a specific username (prompt for username). If the username specified is simply "+", then processes belonging to all users will be displayed.
X
Display user index statistics.