backend now show status in 'ps' - Mailing list pgsql-hackers

From Bruce Momjian
Subject backend now show status in 'ps'
Date
Msg-id 199806041832.OAA26108@candle.pha.pa.us
Whole thread Raw
Responses Re: [HACKERS] backend now show status in 'ps'  (Massimo Dal Zotto <dz@cs.unitn.it>)
List pgsql-hackers
I have completed a patch that shows the backend status on the 'ps' line
for each process:

24081  ./bin/postmaster -i -B 401 -d -o -F -S 1024
24089  /usr/local/postgres/./bin/postgres postgres test idle "" "" "" (postmaster)
24106  /usr/local/postgres/./bin/postgres postgres test SELECT "" "" "" (postmaster)

As you can see, the backend shows the user, database, and status, which
is either 'idle' or 'SELECT', 'UPDATE', 'VACUUM', etc.  Those "" are
there because I erased the other args.  "(postmaster)" is there because
that was the initial argv[0] value (we don't fork() anymore).

This will be useful, even if we go with further status features.  I am
interested in any other information I should be showing.  I believe
there is almost zero performance overhead in assigning/showing these
values, except that the strings should be valid during the entire time
it is assigned to argv.  We could almost display the row number as we
scan through a table.  Nifty feature.

This worked under BSDI, because if you say argv[1] = "test", and argc is
at least 2, it shows "test" in ps.  If argc is only one (they didn't use
any args), it will not show it, but I have added a nifty hack to the
postmaster to re-exec it so it is sure to have a least three args.  I
strip them off before processing.  You can see the patch in the patches
list.

BSDI uses the kvm interface for ps, which allows 'ps' to grab the args
right out of the process's address space.  This is a nifty trick,
considering that 'ps' is run inside the address space of another
process.  I did not use the sendmail wack-the-environment method of
changing 'ps'-displayed args, because it is ugly code, and will probably
cause more problems than it is worth.  Hopefully most platforms will
allow this kind of assignment to be shown in 'ps'.

I have also removed some unused args to pg_exec_query().  Again, it is
in the patch posted.

--
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)

pgsql-hackers by date:

Previous
From: dg@illustra.com (David Gould)
Date:
Subject: Re: [HACKERS] NEW POSTGRESQL LOGOS
Next
From: dg@illustra.com (David Gould)
Date:
Subject: Re: [HACKERS] NEW POSTGRESQL LOGOS