|
85 | 85 | #include "nodes/makefuncs.h"
|
86 | 86 | #include "pgstat.h"
|
87 | 87 | #include "postmaster/autovacuum.h"
|
88 |
| -#include "postmaster/fork_process.h" |
89 | 88 | #include "postmaster/interrupt.h"
|
90 | 89 | #include "postmaster/postmaster.h"
|
91 | 90 | #include "storage/bufmgr.h"
|
@@ -311,13 +310,6 @@ static WorkerInfo MyWorkerInfo = NULL;
|
311 | 310 | /* PID of launcher, valid only in worker while shutting down */
|
312 | 311 | int AutovacuumLauncherPid = 0;
|
313 | 312 |
|
314 |
| -#ifdef EXEC_BACKEND |
315 |
| -static pid_t avlauncher_forkexec(void); |
316 |
| -static pid_t avworker_forkexec(void); |
317 |
| -#endif |
318 |
| -NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn(); |
319 |
| -NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn(); |
320 |
| - |
321 | 313 | static Oid do_start_worker(void);
|
322 | 314 | static void HandleAutoVacLauncherInterrupts(void);
|
323 | 315 | static void AutoVacLauncherShutdown(void) pg_attribute_noreturn();
|
@@ -361,76 +353,23 @@ static void avl_sigusr2_handler(SIGNAL_ARGS);
|
361 | 353 | * AUTOVACUUM LAUNCHER CODE
|
362 | 354 | ********************************************************************/
|
363 | 355 |
|
364 |
| -#ifdef EXEC_BACKEND |
365 | 356 | /*
|
366 |
| - * forkexec routine for the autovacuum launcher process. |
367 |
| - * |
368 |
| - * Format up the arglist, then fork and exec. |
| 357 | + * Main entry point for the autovacuum launcher process. |
369 | 358 | */
|
370 |
| -static pid_t |
371 |
| -avlauncher_forkexec(void) |
| 359 | +void |
| 360 | +AutoVacLauncherMain(char *startup_data, size_t startup_data_len) |
372 | 361 | {
|
373 |
| - char *av[10]; |
374 |
| - int ac = 0; |
375 |
| - |
376 |
| - av[ac++] = "postgres"; |
377 |
| - av[ac++] = "--forkavlauncher"; |
378 |
| - av[ac++] = NULL; /* filled in by postmaster_forkexec */ |
379 |
| - av[ac] = NULL; |
380 |
| - |
381 |
| - Assert(ac < lengthof(av)); |
382 |
| - |
383 |
| - return postmaster_forkexec(ac, av); |
384 |
| -} |
385 |
| -#endif |
| 362 | + sigjmp_buf local_sigjmp_buf; |
386 | 363 |
|
387 |
| -/* |
388 |
| - * Main entry point for autovacuum launcher process, to be called from the |
389 |
| - * postmaster. |
390 |
| - */ |
391 |
| -int |
392 |
| -StartAutoVacLauncher(void) |
393 |
| -{ |
394 |
| - pid_t AutoVacPID; |
| 364 | + Assert(startup_data_len == 0); |
395 | 365 |
|
396 |
| -#ifdef EXEC_BACKEND |
397 |
| - switch ((AutoVacPID = avlauncher_forkexec())) |
398 |
| -#else |
399 |
| - switch ((AutoVacPID = fork_process())) |
400 |
| -#endif |
| 366 | + /* Release postmaster's working memory context */ |
| 367 | + if (PostmasterContext) |
401 | 368 | {
|
402 |
| - case -1: |
403 |
| - ereport(LOG, |
404 |
| - (errmsg("could not fork autovacuum launcher process: %m"))); |
405 |
| - return 0; |
406 |
| - |
407 |
| -#ifndef EXEC_BACKEND |
408 |
| - case 0: |
409 |
| - /* in postmaster child ... */ |
410 |
| - InitPostmasterChild(); |
411 |
| - |
412 |
| - /* Close the postmaster's sockets */ |
413 |
| - ClosePostmasterPorts(false); |
414 |
| - |
415 |
| - AutoVacLauncherMain(0, NULL); |
416 |
| - break; |
417 |
| -#endif |
418 |
| - default: |
419 |
| - return (int) AutoVacPID; |
| 369 | + MemoryContextDelete(PostmasterContext); |
| 370 | + PostmasterContext = NULL; |
420 | 371 | }
|
421 | 372 |
|
422 |
| - /* shouldn't get here */ |
423 |
| - return 0; |
424 |
| -} |
425 |
| - |
426 |
| -/* |
427 |
| - * Main loop for the autovacuum launcher process. |
428 |
| - */ |
429 |
| -NON_EXEC_STATIC void |
430 |
| -AutoVacLauncherMain(int argc, char *argv[]) |
431 |
| -{ |
432 |
| - sigjmp_buf local_sigjmp_buf; |
433 |
| - |
434 | 373 | MyBackendType = B_AUTOVAC_LAUNCHER;
|
435 | 374 | init_ps_display(NULL);
|
436 | 375 |
|
@@ -1412,78 +1351,24 @@ avl_sigusr2_handler(SIGNAL_ARGS)
|
1412 | 1351 | * AUTOVACUUM WORKER CODE
|
1413 | 1352 | ********************************************************************/
|
1414 | 1353 |
|
1415 |
| -#ifdef EXEC_BACKEND |
1416 | 1354 | /*
|
1417 |
| - * forkexec routines for the autovacuum worker. |
1418 |
| - * |
1419 |
| - * Format up the arglist, then fork and exec. |
| 1355 | + * Main entry point for autovacuum worker processes. |
1420 | 1356 | */
|
1421 |
| -static pid_t |
1422 |
| -avworker_forkexec(void) |
| 1357 | +void |
| 1358 | +AutoVacWorkerMain(char *startup_data, size_t startup_data_len) |
1423 | 1359 | {
|
1424 |
| - char *av[10]; |
1425 |
| - int ac = 0; |
1426 |
| - |
1427 |
| - av[ac++] = "postgres"; |
1428 |
| - av[ac++] = "--forkavworker"; |
1429 |
| - av[ac++] = NULL; /* filled in by postmaster_forkexec */ |
1430 |
| - av[ac] = NULL; |
1431 |
| - |
1432 |
| - Assert(ac < lengthof(av)); |
1433 |
| - |
1434 |
| - return postmaster_forkexec(ac, av); |
1435 |
| -} |
1436 |
| -#endif |
| 1360 | + sigjmp_buf local_sigjmp_buf; |
| 1361 | + Oid dbid; |
1437 | 1362 |
|
1438 |
| -/* |
1439 |
| - * Main entry point for autovacuum worker process. |
1440 |
| - * |
1441 |
| - * This code is heavily based on pgarch.c, q.v. |
1442 |
| - */ |
1443 |
| -int |
1444 |
| -StartAutoVacWorker(void) |
1445 |
| -{ |
1446 |
| - pid_t worker_pid; |
| 1363 | + Assert(startup_data_len == 0); |
1447 | 1364 |
|
1448 |
| -#ifdef EXEC_BACKEND |
1449 |
| - switch ((worker_pid = avworker_forkexec())) |
1450 |
| -#else |
1451 |
| - switch ((worker_pid = fork_process())) |
1452 |
| -#endif |
| 1365 | + /* Release postmaster's working memory context */ |
| 1366 | + if (PostmasterContext) |
1453 | 1367 | {
|
1454 |
| - case -1: |
1455 |
| - ereport(LOG, |
1456 |
| - (errmsg("could not fork autovacuum worker process: %m"))); |
1457 |
| - return 0; |
1458 |
| - |
1459 |
| -#ifndef EXEC_BACKEND |
1460 |
| - case 0: |
1461 |
| - /* in postmaster child ... */ |
1462 |
| - InitPostmasterChild(); |
1463 |
| - |
1464 |
| - /* Close the postmaster's sockets */ |
1465 |
| - ClosePostmasterPorts(false); |
1466 |
| - |
1467 |
| - AutoVacWorkerMain(0, NULL); |
1468 |
| - break; |
1469 |
| -#endif |
1470 |
| - default: |
1471 |
| - return (int) worker_pid; |
| 1368 | + MemoryContextDelete(PostmasterContext); |
| 1369 | + PostmasterContext = NULL; |
1472 | 1370 | }
|
1473 | 1371 |
|
1474 |
| - /* shouldn't get here */ |
1475 |
| - return 0; |
1476 |
| -} |
1477 |
| - |
1478 |
| -/* |
1479 |
| - * AutoVacWorkerMain |
1480 |
| - */ |
1481 |
| -NON_EXEC_STATIC void |
1482 |
| -AutoVacWorkerMain(int argc, char *argv[]) |
1483 |
| -{ |
1484 |
| - sigjmp_buf local_sigjmp_buf; |
1485 |
| - Oid dbid; |
1486 |
| - |
1487 | 1372 | MyBackendType = B_AUTOVAC_WORKER;
|
1488 | 1373 | init_ps_display(NULL);
|
1489 | 1374 |
|
|
0 commit comments