forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf13ea95
committed
Change pg_ctl to detect server-ready by watching status in postmaster.pid.
Traditionally, "pg_ctl start -w" has waited for the server to becomeready to accept connections by attempting a connection once per second.That has the major problem that connection issues (for instance, akernel packet filter blocking traffic) can't be reliably told apartfrom server startup issues, and the minor problem that if server startupisn't quick, we accumulate "the database system is starting up" spamin the server log. We've hacked around many of the possible connectionissues, but it resulted in ugly and complicated code in pg_ctl.c.In commitc61559e, I changed the probe rate to every tenth of a second.That prompted Jeff Janes to complain that the log-spam problem had becomemuch worse. In the ensuing discussion, Andres Freund pointed out thatwe could dispense with connection attempts altogether if the postmasterwere changed to report its status in postmaster.pid, which "pg_ctl start"already relies on being able to read. This patch implements that, teachingpostmaster.c to report a status string into the pidfile at the samestate-change points already identified as being of interest for systemdstatus reporting (cf commit7d17e68). pg_ctl no longer needs to linkwith libpq at all; all its functions now depend on reading server files.In support of this, teach AddToDataDirLockFile() to allow addition ofpostmaster.pid lines in not-necessarily-sequential order. This is neededon Windows where the SHMEM_KEY line will never be written at all. We stillhave the restriction that we don't want to truncate the pidfile; documentthe reasons for that a bit better.Also, fix the pg_ctl TAP tests so they'll notice if "start -w" modeis broken --- before, they'd just wait out the sixty seconds untilthe loop gives up, and then report success anyway. (Yes, I found thatout the hard way.)While at it, arrange for pg_ctl to not need to #include miscadmin.h;as a rather low-level backend header, requiring that to be compilableclient-side is pretty dubious. This requires moving the #define'sassociated with the pidfile into a new header file, and movingPG_BACKEND_VERSIONSTR someplace else. For lack of a clearly better"someplace else", I put it into port.h, beside the declaration offind_other_exec(), since most users of that macro are passing the value tofind_other_exec(). (initdb still depends on miscadmin.h, but at leastpg_ctl and pg_upgrade no longer do.)In passing, fix main.c so that PG_BACKEND_VERSIONSTR actually defines theoutput of "postgres -V", which remarkably it had never done before.Discussion:https://postgr.es/m/CAMkU=1xJW8e+CTotojOMBd-yzUvD0e_JZu2xHo=MnuZ4__m7Pg@mail.gmail.com1 parent8c55244 commitf13ea95
File tree
13 files changed
+203
-228
lines changed- src
- backend
- main
- port
- postmaster
- utils/init
- bin
- pg_ctl
- t
- pg_upgrade
- common
- include
- utils
- tools/msvc
13 files changed
+203
-228
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
169 | 169 |
| |
170 | 170 |
| |
171 | 171 |
| |
172 |
| - | |
| 172 | + | |
173 | 173 |
| |
174 | 174 |
| |
175 | 175 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
38 | 38 |
| |
39 | 39 |
| |
40 | 40 |
| |
| 41 | + | |
41 | 42 |
| |
42 | 43 |
| |
43 | 44 |
| |
|
Lines changed: 29 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
125 | 125 |
| |
126 | 126 |
| |
127 | 127 |
| |
| 128 | + | |
128 | 129 |
| |
129 | 130 |
| |
130 | 131 |
| |
| |||
1340 | 1341 |
| |
1341 | 1342 |
| |
1342 | 1343 |
| |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
1343 | 1350 |
| |
1344 | 1351 |
| |
1345 | 1352 |
| |
| |||
2608 | 2615 |
| |
2609 | 2616 |
| |
2610 | 2617 |
| |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
2611 | 2621 |
| |
2612 | 2622 |
| |
2613 | 2623 |
| |
| |||
2663 | 2673 |
| |
2664 | 2674 |
| |
2665 | 2675 |
| |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
2666 | 2679 |
| |
2667 | 2680 |
| |
2668 | 2681 |
| |
| |||
2727 | 2740 |
| |
2728 | 2741 |
| |
2729 | 2742 |
| |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
2730 | 2746 |
| |
2731 | 2747 |
| |
2732 | 2748 |
| |
| |||
2872 | 2888 |
| |
2873 | 2889 |
| |
2874 | 2890 |
| |
| 2891 | + | |
| 2892 | + | |
2875 | 2893 |
| |
2876 | 2894 |
| |
2877 | 2895 |
| |
| |||
5005 | 5023 |
| |
5006 | 5024 |
| |
5007 | 5025 |
| |
5008 |
| - | |
| 5026 | + | |
| 5027 | + | |
| 5028 | + | |
| 5029 | + | |
| 5030 | + | |
5009 | 5031 |
| |
| 5032 | + | |
| 5033 | + | |
| 5034 | + | |
5010 | 5035 |
| |
5011 | 5036 |
| |
| 5037 | + | |
5012 | 5038 |
| |
5013 | 5039 |
| |
5014 | 5040 |
| |
| |||
5024 | 5050 |
| |
5025 | 5051 |
| |
5026 | 5052 |
| |
| 5053 | + | |
| 5054 | + | |
5027 | 5055 |
| |
5028 | 5056 |
| |
5029 | 5057 |
| |
|
Lines changed: 19 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
47 | 47 |
| |
48 | 48 |
| |
49 | 49 |
| |
| 50 | + | |
50 | 51 |
| |
51 | 52 |
| |
52 | 53 |
| |
| |||
1149 | 1150 |
| |
1150 | 1151 |
| |
1151 | 1152 |
| |
1152 |
| - | |
1153 |
| - | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
1154 | 1156 |
| |
1155 | 1157 |
| |
1156 | 1158 |
| |
| |||
1193 | 1195 |
| |
1194 | 1196 |
| |
1195 | 1197 |
| |
1196 |
| - | |
1197 |
| - | |
1198 |
| - | |
1199 |
| - | |
1200 |
| - | |
1201 |
| - | |
1202 |
| - | |
1203 |
| - | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
1204 | 1203 |
| |
1205 | 1204 |
| |
1206 | 1205 |
| |
1207 | 1206 |
| |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
1208 | 1217 |
| |
1209 | 1218 |
| |
1210 | 1219 |
| |
|
Lines changed: 2 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
19 |
| - | |
20 |
| - | |
21 | 19 |
| |
22 | 20 |
| |
23 | 21 |
| |
24 | 22 |
| |
25 |
| - | |
26 |
| - | |
| 23 | + | |
| 24 | + | |
27 | 25 |
| |
28 | 26 |
| |
29 | 27 |
| |
|
0 commit comments
Comments
(0)