Обсуждение: Kill Process ERROR !!!
Dear master How to kill a process in postgresql. I use ps auxw | grep postgres to see status.... it-linux:/usr/local/pgsql/data# ps auxw | grep postgres postgres 197 0.0 7.1 318528 64244 ? S 08:07 0:00 /usr/local/pgsql/bin/postmaster postgres 206 0.0 0.1 319484 1244 ? S 08:07 0:00 postgres: stats buffer process postgres 207 0.0 6.1 318516 55580 ? S 08:07 0:00 postgres: stats collector process yudha 571 0.0 0.1 2448 1068 pts/0 S 09:56 0:00 psql -Upostgres csa postgres 572 0.0 8.8 319940 79208 ? S 09:56 0:00 postgres: postgres csa [local] idle postgres 582 0.5 9.6 320284 86968 ? S 10:02 0:00 postgres: it csa 192.168.0.234 idle postgres 587 1.1 10.4 320972 93636 ? S 10:04 0:00 postgres: postgres csa 192.168.0.111 idle postgres 588 14.6 10.0 320536 90448 ? S 10:04 0:01 postgres: postgres csa 192.168.0.100 idle postgres 589 2.0 7.3 318844 66232 ? S 10:05 0:00 postgres: checkpoint subprocess postgres 590 0.0 7.9 320020 71592 ? R 10:05 0:00 postgres: postgres csa 192.168.0.222 SELECT root 592 0.0 0.0 1332 424 pts/1 S 10:05 0:00 grep postgres I want to kill process no 582, I use kill -9 582 but all user become disconnect look at below it-linux:/usr/local/pgsql/data# ps auxw | grep postgres postgres 197 0.0 7.1 318564 64264 ? S 08:07 0:00 /usr/local/pgsql/bin/postmaster postgres 206 0.0 0.1 319484 1244 ? S 08:07 0:00 postgres: stats buffer process postgres 207 0.0 6.1 318516 55580 ? S 08:07 0:00 postgres: stats collector process yudha 571 0.0 0.1 2448 1068 pts/0 S 09:56 0:00 psql -Upostgres csa root 599 0.0 0.0 1332 424 pts/1 S 10:06 0:00 grep postgres how to kill only one process ? TIA Best Regards Aris Wendy
On Wed, Jul 09, 2003 at 09:52:38AM +0000, aris wendy wrote: > > I want to kill process no 582, I use kill -9 582 but all user become > disconnect look at below Try kill -2. A -- ---- Andrew Sullivan 204-4141 Yonge Street Liberty RMS Toronto, Ontario Canada <andrew@libertyrms.info> M2P 2A8 +1 416 646 3304 x110
Aris, aris wendy wrote: > Dear master [snip] > > I want to kill process no 582, I use kill -9 582 but all user become disconnect look at below [snip] > > how to kill only one process ? > > TIA try with kill -15 <pid> it works with postgresql ver 7.2.4 Andrea
Andrew Sullivan wrote: > On Wed, Jul 09, 2003 at 09:52:38AM +0000, aris wendy wrote: > >>I want to kill process no 582, I use kill -9 582 but all user become >>disconnect look at below > > > Try kill -2. > > A > The " kill -2 " is much better advice. Might I suggest to all - AVOID the " classic " kill -9 ! Never use it, unless nothing else works. It's curious why " kill -9 " is such a part of " common " UNIX practice. Yes it works, but it's messy and often leads to problems as Andrew experienced. The "9" signal is too brute force, and should only be used as a LAST resort. Your first command to kill a process is simple: kill <pid> Notice - NO signal value. By default UNIX sends a signal 15 with the kill command. Signal 15 is the default because it is the normal termination signal. ( I don't have a manual in handy to give you the exact name of the signal ). Signal 15 should ALWAYS be used first since it tells the process to terminate as if the process was terminating on its own. This means, the process will more likely clean up after itself, regarding file descriptors, child processes, etc. Speaking of child processes, ALWAYS kill any child processe first - and more specifically from high to low PID value. Basically, the higher the PID value, the newer or younger the child. Why kill child processes first ? - UNIX processes are very signal driven. The parent of any processes looks for signals from its children, and acts accordingly. Processes always have a parent. Child processes that are orphaned, are sometimes " adopted " by another process - and that is always process 1 Usually, this is the story behind " zombies " - those processes you can't kill or will go away. Next time you see a <zombie>, notice its parent PID is 1. If simple kill <pid> doesn't work try: kill -HUP <pid> All signal values also have a 3 char abreviation of it's role. " HUP " is short for " hang up ", which is signal 1 ( not to be confused with process 1 ) I have found that simple kill <pid> works 95% of the time. kill -HUP <pid> most always gets those processes that are more persistent, for some reason. I truly don't remember that last time I used kill -9 Lastly - please learn all the signal values and what they do. As I remember, there are 19 signals - each with a unique degree of " strength " and purpose. No - the higher value is not a more powerfull kill. To more smoothly manage a UNIX system, use the appropriate kill signal value. You'll avoid problems like those Andrew found. Again - don't use kill -9 thanks, Terry Hampton
On Wed, 9 Jul 2003, Terry Hampton wrote: > Andrew Sullivan wrote: > > On Wed, Jul 09, 2003 at 09:52:38AM +0000, aris wendy wrote: > > > >>I want to kill process no 582, I use kill -9 582 but all user become > >>disconnect look at below > > > > > > Try kill -2. > > > > The " kill -2 " is much better advice. > > Might I suggest to all - AVOID the " classic " kill -9 ! > Never use it, unless nothing else works. It's curious why > " kill -9 " is such a part of " common " UNIX practice. > > Yes it works, but it's messy and often leads to problems as > Andrew experienced. The "9" signal is too brute force, > and should only be used as a LAST resort. > > Your first command to kill a process is simple: kill <pid> > > Notice - NO signal value. By default UNIX sends a signal 15 > with the kill command. Signal 15 is the default because > it is the normal termination signal. ( I don't have a manual in > handy to give you the exact name of the signal ). Signal 15 > should ALWAYS be used first since it tells the process to > terminate as if the process was terminating on its own. This > means, the process will more likely clean up after itself, > regarding file descriptors, child processes, etc. What amazes me is how many people don't try 'kill pid' first. > Speaking of child processes, ALWAYS kill any child processe > first - and more specifically from high to low PID value. Basically, > the higher the PID value, the newer or younger the child. Why > kill child processes first ? - UNIX processes are very signal > driven. The parent of any processes looks for signals from its > children, and acts accordingly. Processes always have a parent. > Child processes that are orphaned, are sometimes " adopted " by > another process - and that is always process 1 Usually, > this is the story behind " zombies " - those processes you can't > kill or will go away. Next time you see a <zombie>, notice its > parent PID is 1. Please note that this is not necessarily true. If my server has been up a while and I stop/restart the postmaster, it may have a fairly high id number and it is quite possible that in x number of days time, the children will be created with a wrapped pid which is lower than the postmasters. Just look for the - switches that make it obvious. In fact, this IS currently the case right now on my server: 13081 ? S 2:30 /usr/local/pgsql/bin/postmaster 13082 ? S 0:19 postgres: stats buffer process 13083 ? S 0:28 postgres: stats collector process 5600 ? S 0:00 postgres: marlowe phone [local] idle In this case 13081 is my postmaster. Notice that kill -9 to any postgresql backend results in all backend connections flushing their buffers. kill -9 to the postmaster results in a dirty shutdown and the database server has to go through the WAL and clean things up. It's not the same as hitting the Big Red Switch, but it's close.
scott.marlowe wrote: > > Please note that this is not necessarily true. If my server has been up a > while and I stop/restart the postmaster, it may have a fairly high id > number and it is quite possible that in x number of days time, the > children will be created with a wrapped pid which is lower than the > postmasters. Just look for the - switches that make it obvious. In fact, > this IS currently the case right now on my server: > > 13081 ? S 2:30 /usr/local/pgsql/bin/postmaster > 13082 ? S 0:19 postgres: stats buffer process > 13083 ? S 0:28 postgres: stats collector process > 5600 ? S 0:00 postgres: marlowe phone [local] idle > > In this case 13081 is my postmaster. > Hey Scott, Thanks for your input ! Of course you're correct here with the possibility of PID's rolling over - and I considered describing exactley what you have here in my original email. My original was getting longer than I anticipated, so I simply thought to myself "yeah it happens, but don't add a bunch more explanation, since the scenario is kinda uncommon". I should have known better ! This group is too sharp to let anything slip through :-) Terry
Aris, aris wendy wrote: > Dear master > [snip] > > I want to kill process no 582, I use kill -9 582 but all user become > disconnect look at below [snip] > > how to kill only one process ? > > TIA try with kill -15 582 it works with postgresql ver 7.2.4 Andrea