|
37 | 37 | *
|
38 | 38 | *
|
39 | 39 | * IDENTIFICATION
|
40 |
| - * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.53 2008/10/14 08:06:39 heikki Exp $ |
| 40 | + * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.54 2008/11/23 01:40:19 tgl Exp $ |
41 | 41 | *
|
42 | 42 | *-------------------------------------------------------------------------
|
43 | 43 | */
|
@@ -864,6 +864,7 @@ RequestCheckpoint(int flags)
|
864 | 864 | {
|
865 | 865 | /* use volatile pointer to prevent code rearrangement */
|
866 | 866 | volatile BgWriterShmemStruct *bgs = BgWriterShmem;
|
| 867 | + int ntries; |
867 | 868 | int old_failed,
|
868 | 869 | old_started;
|
869 | 870 |
|
@@ -905,15 +906,38 @@ RequestCheckpoint(int flags)
|
905 | 906 | SpinLockRelease(&bgs->ckpt_lck);
|
906 | 907 |
|
907 | 908 | /*
|
908 |
| - * Send signal to request checkpoint. When not waiting, we consider |
909 |
| - * failure to send the signal to be nonfatal. |
| 909 | + * Send signal to request checkpoint. It's possible that the bgwriter |
| 910 | + * hasn't started yet, or is in process of restarting, so we will retry |
| 911 | + * a few times if needed. Also, if not told to wait for the checkpoint |
| 912 | + * to occur, we consider failure to send the signal to be nonfatal and |
| 913 | + * merely LOG it. |
910 | 914 | */
|
911 |
| - if (BgWriterShmem->bgwriter_pid == 0) |
912 |
| - elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG, |
913 |
| - "could not request checkpoint because bgwriter not running"); |
914 |
| - if (kill(BgWriterShmem->bgwriter_pid, SIGINT) != 0) |
915 |
| - elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG, |
916 |
| - "could not signal for checkpoint: %m"); |
| 915 | + for (ntries = 0; ; ntries++) |
| 916 | + { |
| 917 | + if (BgWriterShmem->bgwriter_pid == 0) |
| 918 | + { |
| 919 | + if (ntries >= 20) /* max wait 2.0 sec */ |
| 920 | + { |
| 921 | + elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG, |
| 922 | + "could not request checkpoint because bgwriter not running"); |
| 923 | + break; |
| 924 | + } |
| 925 | + } |
| 926 | + else if (kill(BgWriterShmem->bgwriter_pid, SIGINT) != 0) |
| 927 | + { |
| 928 | + if (ntries >= 20) /* max wait 2.0 sec */ |
| 929 | + { |
| 930 | + elog((flags & CHECKPOINT_WAIT) ? ERROR : LOG, |
| 931 | + "could not signal for checkpoint: %m"); |
| 932 | + break; |
| 933 | + } |
| 934 | + } |
| 935 | + else |
| 936 | + break; /* signal sent successfully */ |
| 937 | + |
| 938 | + CHECK_FOR_INTERRUPTS(); |
| 939 | + pg_usleep(100000L); /* wait 0.1 sec, then retry */ |
| 940 | + } |
917 | 941 |
|
918 | 942 | /*
|
919 | 943 | * If requested, wait for completion. We detect completion according to
|
|
0 commit comments