PostgreSQL 8.0.1 Documentation | ||||
---|---|---|---|---|
Prev | Fast Backward | Fast Forward | Next |
Chapter 23. Monitoring Database Activity
- Table of Contents
- 23.1. Standard Unix Tools
- 23.2. The Statistics Collector
- 23.2.1. Statistics Collection Configuration
- 23.2.2. Viewing Collected Statistics
- 23.3. Viewing Locks
A database administrator frequently wonders, "What is the system doing right now?" This chapter discusses how to find that out.
Several tools are available for monitoring database activity and analyzing performance. Most of this chapter is devoted to describing PostgreSQL's statistics collector, but one should not neglect regular Unix monitoring programs such as ps, top, iostat, and vmstat. Also, once one has identified a poorly-performing query, further investigation may be needed using PostgreSQL's EXPLAIN command. Section 13.1 discusses EXPLAIN and other methods for understanding the behavior of an individual query.
23.1. Standard Unix Tools
On most platforms, PostgreSQL modifies its command title as reported by ps, so that individual server processes can readily be identified. A sample display is
(The appropriate invocation of ps varies across different platforms, as do the details of what is shown. This example is from a recent Linux system.) The first process listed here is the postmaster, the master server process. The command arguments shown for it are the same ones given when it was launched. The next two processes implement the statistics collector, which will be described in detail in the next section. (These will not be present if you have set the system not to start the statistics collector.) Each of the remaining processes is a server process handling one client connection. Each such process sets its command line display in the form
The user, database, and connection source host items remain the same for the life of the client connection, but the activity indicator changes. The activity may be idle (i.e., waiting for a client command), idle in transaction (waiting for client inside a BEGIN block), or a command type name such as SELECT. Also, waiting is attached if the server process is presently waiting on a lock held by another server process. In the above example we can infer that process 1003 is waiting for process 1016 to complete its transaction and thereby release some lock or other.
Tip: Solaris requires special handling. You must use /usr/ucb/ps, rather than /bin/ps. You also must use two w flags, not just one. In addition, your original invocation of the postmaster command must have a shorter ps status display than that provided by each server process. If you fail to do all three things, the ps output for each server process will be the original postmaster command line.