@@ -428,8 +428,8 @@ static void process_pm_reload_request(void);
428
428
static void process_pm_shutdown_request (void );
429
429
static void dummy_handler (SIGNAL_ARGS );
430
430
static void CleanupBackend (PMChild * bp , int exitstatus );
431
- static void HandleChildCrash (int pid , int exitstatus , const char * procname );
432
- static void LogChildExit (int lev , const char * procname ,
431
+ static void HandleChildCrash (int pid , int exitstatus , BackendType proctype , const char * addtype );
432
+ static void LogChildExit (int lev , BackendType proctype , const char * addtype ,
433
433
int pid , int exitstatus );
434
434
static void PostmasterStateMachine (void );
435
435
static void UpdatePMState (PMState newState );
@@ -2285,8 +2285,7 @@ process_pm_child_exit(void)
2285
2285
StartupStatus != STARTUP_SIGNALED &&
2286
2286
!EXIT_STATUS_0 (exitstatus ))
2287
2287
{
2288
- LogChildExit (LOG , _ ("startup process" ),
2289
- pid , exitstatus );
2288
+ LogChildExit (LOG , B_STARTUP , NULL , pid , exitstatus );
2290
2289
ereport (LOG ,
2291
2290
(errmsg ("aborting startup due to startup process failure" )));
2292
2291
ExitPostmaster (1 );
@@ -2320,8 +2319,7 @@ process_pm_child_exit(void)
2320
2319
}
2321
2320
else
2322
2321
StartupStatus = STARTUP_CRASHED ;
2323
- HandleChildCrash (pid , exitstatus ,
2324
- _ ("startup process" ));
2322
+ HandleChildCrash (pid , exitstatus , B_STARTUP , NULL );
2325
2323
continue ;
2326
2324
}
2327
2325
@@ -2365,8 +2363,7 @@ process_pm_child_exit(void)
2365
2363
ReleasePostmasterChildSlot (BgWriterPMChild );
2366
2364
BgWriterPMChild = NULL ;
2367
2365
if (!EXIT_STATUS_0 (exitstatus ))
2368
- HandleChildCrash (pid , exitstatus ,
2369
- _ ("background writer process" ));
2366
+ HandleChildCrash (pid , exitstatus , B_BG_WRITER , NULL );
2370
2367
continue ;
2371
2368
}
2372
2369
@@ -2398,8 +2395,7 @@ process_pm_child_exit(void)
2398
2395
* Any unexpected exit of the checkpointer (including FATAL
2399
2396
* exit) is treated as a crash.
2400
2397
*/
2401
- HandleChildCrash (pid , exitstatus ,
2402
- _ ("checkpointer process" ));
2398
+ HandleChildCrash (pid , exitstatus , B_CHECKPOINTER , NULL );
2403
2399
}
2404
2400
2405
2401
continue ;
@@ -2415,8 +2411,7 @@ process_pm_child_exit(void)
2415
2411
ReleasePostmasterChildSlot (WalWriterPMChild );
2416
2412
WalWriterPMChild = NULL ;
2417
2413
if (!EXIT_STATUS_0 (exitstatus ))
2418
- HandleChildCrash (pid , exitstatus ,
2419
- _ ("WAL writer process" ));
2414
+ HandleChildCrash (pid , exitstatus , B_WAL_WRITER , NULL );
2420
2415
continue ;
2421
2416
}
2422
2417
@@ -2431,8 +2426,7 @@ process_pm_child_exit(void)
2431
2426
ReleasePostmasterChildSlot (WalReceiverPMChild );
2432
2427
WalReceiverPMChild = NULL ;
2433
2428
if (!EXIT_STATUS_0 (exitstatus ) && !EXIT_STATUS_1 (exitstatus ))
2434
- HandleChildCrash (pid , exitstatus ,
2435
- _ ("WAL receiver process" ));
2429
+ HandleChildCrash (pid , exitstatus , B_WAL_RECEIVER , NULL );
2436
2430
continue ;
2437
2431
}
2438
2432
@@ -2446,8 +2440,7 @@ process_pm_child_exit(void)
2446
2440
ReleasePostmasterChildSlot (WalSummarizerPMChild );
2447
2441
WalSummarizerPMChild = NULL ;
2448
2442
if (!EXIT_STATUS_0 (exitstatus ))
2449
- HandleChildCrash (pid , exitstatus ,
2450
- _ ("WAL summarizer process" ));
2443
+ HandleChildCrash (pid , exitstatus , B_WAL_SUMMARIZER , NULL );
2451
2444
continue ;
2452
2445
}
2453
2446
@@ -2462,8 +2455,7 @@ process_pm_child_exit(void)
2462
2455
ReleasePostmasterChildSlot (AutoVacLauncherPMChild );
2463
2456
AutoVacLauncherPMChild = NULL ;
2464
2457
if (!EXIT_STATUS_0 (exitstatus ))
2465
- HandleChildCrash (pid , exitstatus ,
2466
- _ ("autovacuum launcher process" ));
2458
+ HandleChildCrash (pid , exitstatus , B_AUTOVAC_LAUNCHER , NULL );
2467
2459
continue ;
2468
2460
}
2469
2461
@@ -2478,8 +2470,7 @@ process_pm_child_exit(void)
2478
2470
ReleasePostmasterChildSlot (PgArchPMChild );
2479
2471
PgArchPMChild = NULL ;
2480
2472
if (!EXIT_STATUS_0 (exitstatus ) && !EXIT_STATUS_1 (exitstatus ))
2481
- HandleChildCrash (pid , exitstatus ,
2482
- _ ("archiver process" ));
2473
+ HandleChildCrash (pid , exitstatus , B_ARCHIVER , NULL );
2483
2474
continue ;
2484
2475
}
2485
2476
@@ -2494,8 +2485,7 @@ process_pm_child_exit(void)
2494
2485
StartSysLogger ();
2495
2486
2496
2487
if (!EXIT_STATUS_0 (exitstatus ))
2497
- LogChildExit (LOG , _ ("system logger process" ),
2498
- pid , exitstatus );
2488
+ LogChildExit (LOG , B_LOGGER , NULL , pid , exitstatus );
2499
2489
continue ;
2500
2490
}
2501
2491
@@ -2511,16 +2501,15 @@ process_pm_child_exit(void)
2511
2501
ReleasePostmasterChildSlot (SlotSyncWorkerPMChild );
2512
2502
SlotSyncWorkerPMChild = NULL ;
2513
2503
if (!EXIT_STATUS_0 (exitstatus ) && !EXIT_STATUS_1 (exitstatus ))
2514
- HandleChildCrash (pid , exitstatus ,
2515
- _ ("slot sync worker process" ));
2504
+ HandleChildCrash (pid , exitstatus , B_SLOTSYNC_WORKER , NULL );
2516
2505
continue ;
2517
2506
}
2518
2507
2519
2508
/* Was it an IO worker? */
2520
2509
if (maybe_reap_io_worker (pid ))
2521
2510
{
2522
2511
if (!EXIT_STATUS_0 (exitstatus ) && !EXIT_STATUS_1 (exitstatus ))
2523
- HandleChildCrash (pid , exitstatus , _ ( "io worker" ) );
2512
+ HandleChildCrash (pid , exitstatus , B_IO_WORKER , NULL );
2524
2513
2525
2514
maybe_adjust_io_workers ();
2526
2515
continue ;
@@ -2542,9 +2531,9 @@ process_pm_child_exit(void)
2542
2531
else
2543
2532
{
2544
2533
if (!EXIT_STATUS_0 (exitstatus ) && !EXIT_STATUS_1 (exitstatus ))
2545
- HandleChildCrash (pid , exitstatus , _ ( "untracked child process" ) );
2534
+ HandleChildCrash (pid , exitstatus , B_INVALID , NULL );
2546
2535
else
2547
- LogChildExit (LOG , _ ( "untracked child process" ) , pid , exitstatus );
2536
+ LogChildExit (LOG , B_INVALID , NULL , pid , exitstatus );
2548
2537
}
2549
2538
} /* loop over pending child-death reports */
2550
2539
@@ -2565,8 +2554,8 @@ static void
2565
2554
CleanupBackend (PMChild * bp ,
2566
2555
int exitstatus ) /* child's exit status. */
2567
2556
{
2568
- char namebuf [MAXPGPATH ];
2569
- const char * procname ;
2557
+ char namebuf [MAXPGPATH ];
2558
+ char * procname ;
2570
2559
bool crashed = false;
2571
2560
bool logged = false;
2572
2561
pid_t bp_pid ;
@@ -2575,14 +2564,13 @@ CleanupBackend(PMChild *bp,
2575
2564
RegisteredBgWorker * rw ;
2576
2565
2577
2566
/* Construct a process name for the log message */
2578
- if (bp -> bkend_type == B_BG_WORKER )
2567
+ if (bp && bp -> bkend_type == B_BG_WORKER && bp -> rw )
2579
2568
{
2580
- snprintf (namebuf , MAXPGPATH , _ ("background worker \"%s\"" ),
2581
- bp -> rw -> rw_worker .bgw_type );
2569
+ strlcpy (namebuf , bp -> rw -> rw_worker .bgw_type , MAXPGPATH );
2582
2570
procname = namebuf ;
2583
2571
}
2584
2572
else
2585
- procname = _ ( GetBackendTypeDesc ( bp -> bkend_type )) ;
2573
+ procname = NULL ;
2586
2574
2587
2575
/*
2588
2576
* If a backend dies in an ugly way then we must signal all other backends
@@ -2604,7 +2592,7 @@ CleanupBackend(PMChild *bp,
2604
2592
*/
2605
2593
if (exitstatus == ERROR_WAIT_NO_CHILDREN )
2606
2594
{
2607
- LogChildExit (LOG , procname , bp -> pid , exitstatus );
2595
+ LogChildExit (LOG , bp -> bkend_type , procname , bp -> pid , exitstatus );
2608
2596
logged = true;
2609
2597
crashed = false;
2610
2598
}
@@ -2639,7 +2627,7 @@ CleanupBackend(PMChild *bp,
2639
2627
*/
2640
2628
if (crashed )
2641
2629
{
2642
- HandleChildCrash (bp_pid , exitstatus , procname );
2630
+ HandleChildCrash (bp_pid , exitstatus , bp_bkend_type , procname );
2643
2631
return ;
2644
2632
}
2645
2633
@@ -2677,7 +2665,7 @@ CleanupBackend(PMChild *bp,
2677
2665
if (!logged )
2678
2666
{
2679
2667
LogChildExit (EXIT_STATUS_0 (exitstatus ) ? DEBUG1 : LOG ,
2680
- procname , bp_pid , exitstatus );
2668
+ bp_bkend_type , procname , bp_pid , exitstatus );
2681
2669
logged = true;
2682
2670
}
2683
2671
@@ -2686,7 +2674,7 @@ CleanupBackend(PMChild *bp,
2686
2674
}
2687
2675
2688
2676
if (!logged )
2689
- LogChildExit (DEBUG2 , procname , bp_pid , exitstatus );
2677
+ LogChildExit (DEBUG2 , bp_bkend_type , procname , bp_pid , exitstatus );
2690
2678
}
2691
2679
2692
2680
/*
@@ -2778,16 +2766,16 @@ HandleFatalError(QuitSignalReason reason, bool consider_sigabrt)
2778
2766
}
2779
2767
2780
2768
/*
2781
- * HandleChildCrash -- cleanup after failed backend, bgwriter, checkpointer,
2782
- * walwriter, autovacuum, archiver, slot sync worker, or background worker .
2769
+ * HandleChildCrash -- cleanup after failed backend or certain auxiliary
2770
+ * processes .
2783
2771
*
2784
2772
* The objectives here are to clean up our local state about the child
2785
2773
* process, and to signal all other remaining children to quickdie.
2786
2774
*
2787
2775
* The caller has already released its PMChild slot.
2788
2776
*/
2789
2777
static void
2790
- HandleChildCrash (int pid , int exitstatus , const char * procname )
2778
+ HandleChildCrash (int pid , int exitstatus , BackendType proctype , const char * addtype )
2791
2779
{
2792
2780
/*
2793
2781
* We only log messages and send signals if this is the first process
@@ -2799,7 +2787,7 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
2799
2787
if (FatalError || Shutdown == ImmediateShutdown )
2800
2788
return ;
2801
2789
2802
- LogChildExit (LOG , procname , pid , exitstatus );
2790
+ LogChildExit (LOG , proctype , addtype , pid , exitstatus );
2803
2791
ereport (LOG ,
2804
2792
(errmsg ("terminating any other active server processes" )));
2805
2793
@@ -2812,9 +2800,13 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
2812
2800
2813
2801
/*
2814
2802
* Log the death of a child process.
2803
+ *
2804
+ * 'addtype' is an additional word or short phrase that describes the process,
2805
+ * such as a background worker 'type'.
2815
2806
*/
2816
2807
static void
2817
- LogChildExit (int lev , const char * procname , int pid , int exitstatus )
2808
+ LogChildExit (int lev , BackendType proctype , const char * addtype , int pid ,
2809
+ int exitstatus )
2818
2810
{
2819
2811
/*
2820
2812
* size of activity_buffer is arbitrary, but set equal to default
@@ -2829,14 +2821,13 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
2829
2821
sizeof (activity_buffer ));
2830
2822
2831
2823
if (WIFEXITED (exitstatus ))
2832
- ereport (lev ,
2824
+ ereport (lev , addtype ?
2825
+ errmsg ("\"%s\" process of type \"%s\" (PID %d) exited with exit code %d" ,
2826
+ GetBackendTypeDesc (proctype ), addtype , pid , WEXITSTATUS (exitstatus )) :
2827
+ errmsg ("process of type \"%s\" (PID %d) exited with exit code %d" ,
2828
+ GetBackendTypeDesc (proctype ), pid , WEXITSTATUS (exitstatus )),
2833
2829
2834
- /*------
2835
- translator: %s is a noun phrase describing a child process, such as
2836
- "server process" */
2837
- (errmsg ("%s (PID %d) exited with exit code %d" ,
2838
- procname , pid , WEXITSTATUS (exitstatus )),
2839
- activity ? errdetail ("Failed process was running: %s" , activity ) : 0 ));
2830
+ activity ? errdetail ("Failed process was running: %s" , activity ) : 0 );
2840
2831
else if (WIFSIGNALED (exitstatus ))
2841
2832
{
2842
2833
#if defined(WIN32 )
@@ -2845,20 +2836,27 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
2845
2836
/*------
2846
2837
translator: %s is a noun phrase describing a child process, such as
2847
2838
"server process" */
2848
- (errmsg ("%s (PID %d) was terminated by exception 0x%X" ,
2849
- procname , pid , WTERMSIG (exitstatus )),
2850
- errhint ("See C include file \"ntstatus.h\" for a description of the hexadecimal value." ),
2851
- activity ? errdetail ("Failed process was running: %s" , activity ) : 0 ));
2839
+ addtype ?
2840
+ errmsg ("\"%s\" process of type \"%s\" (PID %d) was terminated by exception 0x%X" ,
2841
+ GetBackendTypeDesc (proctype ), addtype , pid , WTERMSIG (exitstatus )) :
2842
+ errmsg ("\"%s\" process (PID %d) was terminated by exception 0x%X" ,
2843
+ GetBackendTypeDesc (proctype ), addtype , pid , WTERMSIG (exitstatus )),
2844
+ errhint ("See C include file \"ntstatus.h\" for a description of the hexadecimal value." ),
2845
+ activity ? errdetail ("Failed process was running: %s" , activity ) : 0 );
2852
2846
#else
2853
2847
ereport (lev ,
2854
2848
2855
2849
/*------
2856
2850
translator: %s is a noun phrase describing a child process, such as
2857
2851
"server process" */
2858
- (errmsg ("%s (PID %d) was terminated by signal %d: %s" ,
2859
- procname , pid , WTERMSIG (exitstatus ),
2860
- pg_strsignal (WTERMSIG (exitstatus ))),
2861
- activity ? errdetail ("Failed process was running: %s" , activity ) : 0 ));
2852
+ addtype ?
2853
+ errmsg ("\"%s\" process of type \"%s\" (PID %d) was terminated by signal %d: %s" ,
2854
+ GetBackendTypeDesc (proctype ), addtype , pid , WTERMSIG (exitstatus ),
2855
+ pg_strsignal (WTERMSIG (exitstatus ))) :
2856
+ errmsg ("\"%s\" process (PID %d) was terminated by signal %d: %s" ,
2857
+ GetBackendTypeDesc (proctype ), pid , WTERMSIG (exitstatus ),
2858
+ pg_strsignal (WTERMSIG (exitstatus ))),
2859
+ activity ? errdetail ("Failed process was running: %s" , activity ) : 0 );
2862
2860
#endif
2863
2861
}
2864
2862
else
@@ -2867,9 +2865,12 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
2867
2865
/*------
2868
2866
translator: %s is a noun phrase describing a child process, such as
2869
2867
"server process" */
2870
- (errmsg ("%s (PID %d) exited with unrecognized status %d" ,
2871
- procname , pid , exitstatus ),
2872
- activity ? errdetail ("Failed process was running: %s" , activity ) : 0 ));
2868
+ addtype ?
2869
+ errmsg ("\"%s\" process of type \"%s\" (PID %d) exited with unrecognized status %d" ,
2870
+ GetBackendTypeDesc (proctype ), addtype , pid , exitstatus ) :
2871
+ errmsg ("\"%s\" process (PID %d) exited with unrecognized status %d" ,
2872
+ GetBackendTypeDesc (proctype ), pid , exitstatus ),
2873
+ activity ? errdetail ("Failed process was running: %s" , activity ) : 0 );
2873
2874
}
2874
2875
2875
2876
/*
0 commit comments