forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitbb24439
committed
Detach postmaster process from pg_ctl's session at server startup.
pg_ctl is supposed to daemonize the postmaster process, so that it's notaffected by signals to the launching process group. Before this patch, ifyou had a shell script that used "pg_ctl start", and you interrupted theshell script after postmaster had been launched, postmaster was alsokilled. To fix, call setsid() after forking the postmaster process.Long time ago, we had a 'silent_mode' option, which daemonized thepostmaster process by calling setsid(), but that was removed back in 2011(commitf7ea6be). We discussed bringing that back in some form, butpg_ctl is the documented way of launching postmaster to the background, soputting the setsid() call in pg_ctl itself seems appropriate.Just putting postmaster in a separate session would change the behaviorwhen you interrupt "pg_ctl -w start", e.g. with CTRL-C, while it's waitingfor postmaster to start. The historical behavior has been thatinterrupting pg_ctl aborts the server launch, which is handy if the serveris stuck in recovery, for example, and won't fully start up. To keep thatbehavior, install a signal handler in pg_ctl, to explicitly killpostmaster, if pg_ctl is interrupted while it's waiting for the server tostart up. This isn't 100% watertight, there is a small window afterforking the postmaster process, where the signal handler doesn't know thepostmaster's PID yet, but seems good enough.Arguably this is a long-standing bug, but I refrained from back-batching,out of fear of breaking someone's scripts that depended on the oldbehavior.Reviewed by Tom Lane. Report and original patch by Paul Guo, withfeedback from Michael Paquier.Discussion:https://www.postgresql.org/message-id/CAEET0ZH5Bf7dhZB3mYy8zZQttJrdZg_0Wwaj0o1PuuBny1JkEw%40mail.gmail.com1 parentd9cdb1b commitbb24439
1 file changed
+51
-1
lines changedLines changed: 51 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| 106 | + | |
| 107 | + | |
106 | 108 |
| |
107 | 109 |
| |
108 | 110 |
| |
109 | 111 |
| |
110 | 112 |
| |
111 |
| - | |
112 | 113 |
| |
113 | 114 |
| |
114 | 115 |
| |
| |||
471 | 472 |
| |
472 | 473 |
| |
473 | 474 |
| |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
474 | 489 |
| |
475 | 490 |
| |
476 | 491 |
| |
| |||
719 | 734 |
| |
720 | 735 |
| |
721 | 736 |
| |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
722 | 761 |
| |
723 | 762 |
| |
724 | 763 |
| |
| |||
827 | 866 |
| |
828 | 867 |
| |
829 | 868 |
| |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
830 | 880 |
| |
831 | 881 |
| |
832 | 882 |
| |
|
0 commit comments
Comments
(0)