1
1
/*
2
- * $PostgreSQL: pgsql/contrib/pg_standby/pg_standby.c,v 1.17 2009/01/06 17:27:06 tgl Exp $
2
+ * $PostgreSQL: pgsql/contrib/pg_standby/pg_standby.c,v 1.18 2009/02/27 09:30:21 petere Exp $
3
3
*
4
4
*
5
5
* pg_standby.c
@@ -42,6 +42,8 @@ int getopt(int argc, char *const argv[], const char *optstring);
42
42
extern char * optarg ;
43
43
extern int optind ;
44
44
45
+ const char * progname ;
46
+
45
47
/* Options and defaults */
46
48
int sleeptime = 5 ; /* amount of time to sleep between file checks */
47
49
int waittime = -1 ; /* how long we have been waiting, -1 no wait
@@ -146,7 +148,7 @@ CustomizableInitialize(void)
146
148
*/
147
149
if (stat (archiveLocation , & stat_buf ) != 0 )
148
150
{
149
- fprintf (stderr , "pg_standby : archiveLocation \"%s\" does not exist\n" , archiveLocation );
151
+ fprintf (stderr , "%s : archiveLocation \"%s\" does not exist\n" , progname , archiveLocation );
150
152
fflush (stderr );
151
153
exit (2 );
152
154
}
@@ -261,8 +263,8 @@ CustomizableCleanupPriorWALFiles(void)
261
263
rc = unlink (WALFilePath );
262
264
if (rc != 0 )
263
265
{
264
- fprintf (stderr , "\npg_standby : ERROR failed to remove \"%s\": %s" ,
265
- WALFilePath , strerror (errno ));
266
+ fprintf (stderr , "\n%s : ERROR failed to remove \"%s\": %s" ,
267
+ progname , WALFilePath , strerror (errno ));
266
268
break ;
267
269
}
268
270
}
@@ -271,7 +273,7 @@ CustomizableCleanupPriorWALFiles(void)
271
273
fprintf (stderr , "\n" );
272
274
}
273
275
else
274
- fprintf (stderr , "pg_standby : archiveLocation \"%s\" open error\n" , archiveLocation );
276
+ fprintf (stderr , "%s : archiveLocation \"%s\" open error\n" , progname , archiveLocation );
275
277
276
278
closedir (xldir );
277
279
fflush (stderr );
@@ -430,23 +432,29 @@ RestoreWALFileForRecovery(void)
430
432
static void
431
433
usage (void )
432
434
{
433
- fprintf (stderr , "\npg_standby allows Warm Standby servers to be configured\n" );
434
- fprintf (stderr , "Usage:\n" );
435
- fprintf (stderr , " pg_standby [OPTION]... ARCHIVELOCATION NEXTWALFILE XLOGFILEPATH [RESTARTWALFILE]\n" );
436
- fprintf (stderr , " note space between ARCHIVELOCATION and NEXTWALFILE\n" );
437
- fprintf (stderr , "with main intended use as a restore_command in the recovery.conf\n" );
438
- fprintf (stderr , " restore_command = 'pg_standby [OPTION]... ARCHIVELOCATION %%f %%p %%r'\n" );
439
- fprintf (stderr , "e.g. restore_command = 'pg_standby -l /mnt/server/archiverdir %%f %%p %%r'\n" );
440
- fprintf (stderr , "\nOptions:\n" );
441
- fprintf (stderr , " -c copies file from archive (default)\n" );
442
- fprintf (stderr , " -d generate lots of debugging output (testing only)\n" );
443
- fprintf (stderr , " -k NUMFILESTOKEEP if RESTARTWALFILE not used, removes files prior to limit (0 keeps all)\n" );
444
- fprintf (stderr , " -l links into archive (leaves file in archive)\n" );
445
- fprintf (stderr , " -r MAXRETRIES max number of times to retry, with progressive wait (default=3)\n" );
446
- fprintf (stderr , " -s SLEEPTIME seconds to wait between file checks (min=1, max=60, default=5)\n" );
447
- fprintf (stderr , " -t TRIGGERFILE defines a trigger file to initiate failover (no default)\n" );
448
- fprintf (stderr , " -w MAXWAITTIME max seconds to wait for a file (0=no limit)(default=0)\n" );
449
- fflush (stderr );
435
+ printf ("%s allows PostgreSQL warm standby servers to be configured.\n\n" , progname );
436
+ printf ("Usage:\n" );
437
+ printf (" %s [OPTION]... ARCHIVELOCATION NEXTWALFILE XLOGFILEPATH [RESTARTWALFILE]\n" , progname );
438
+ printf ("\n"
439
+ "with main intended use as a restore_command in the recovery.conf:\n"
440
+ " restore_command = 'pg_standby [OPTION]... ARCHIVELOCATION %%f %%p %%r'\n"
441
+ "e.g.\n"
442
+ " restore_command = 'pg_standby -l /mnt/server/archiverdir %%f %%p %%r'\n" );
443
+ printf ("\nOptions:\n" );
444
+ printf (" -c copies file from archive (default)\n" );
445
+ printf (" -d generate lots of debugging output (testing only)\n" );
446
+ printf (" -k NUMFILESTOKEEP if RESTARTWALFILE not used, removes files prior to limit\n"
447
+ " (0 keeps all)\n" );
448
+ printf (" -l links into archive (leaves file in archive)\n" );
449
+ printf (" -r MAXRETRIES max number of times to retry, with progressive wait\n"
450
+ " (default=3)\n" );
451
+ printf (" -s SLEEPTIME seconds to wait between file checks (min=1, max=60,\n"
452
+ " default=5)\n" );
453
+ printf (" -t TRIGGERFILE defines a trigger file to initiate failover (no default)\n" );
454
+ printf (" -w MAXWAITTIME max seconds to wait for a file (0=no limit) (default=0)\n" );
455
+ printf (" --help show this help, then exit\n" );
456
+ printf (" --version output version information, then exit\n" );
457
+ printf ("\nReport bugs to <pgsql-bugs@postgresql.org>.\n" );
450
458
}
451
459
452
460
static void
@@ -461,6 +469,22 @@ main(int argc, char **argv)
461
469
{
462
470
int c ;
463
471
472
+ progname = get_progname (argv [0 ]);
473
+
474
+ if (argc > 1 )
475
+ {
476
+ if (strcmp (argv [1 ], "--help" ) == 0 || strcmp (argv [1 ], "-?" ) == 0 )
477
+ {
478
+ usage ();
479
+ exit (0 );
480
+ }
481
+ if (strcmp (argv [1 ], "--version" ) == 0 || strcmp (argv [1 ], "-V" ) == 0 )
482
+ {
483
+ puts ("pg_standby (PostgreSQL) " PG_VERSION );
484
+ exit (0 );
485
+ }
486
+ }
487
+
464
488
(void ) signal (SIGINT , sighandler );
465
489
(void ) signal (SIGQUIT , sighandler );
466
490
@@ -478,8 +502,7 @@ main(int argc, char **argv)
478
502
keepfiles = atoi (optarg );
479
503
if (keepfiles < 0 )
480
504
{
481
- fprintf (stderr , "usage: pg_standby -k keepfiles must be >= 0\n" );
482
- usage ();
505
+ fprintf (stderr , "%s: -k keepfiles must be >= 0\n" , progname );
483
506
exit (2 );
484
507
}
485
508
break ;
@@ -490,17 +513,15 @@ main(int argc, char **argv)
490
513
maxretries = atoi (optarg );
491
514
if (maxretries < 0 )
492
515
{
493
- fprintf (stderr , "usage: pg_standby -r maxretries must be >= 0\n" );
494
- usage ();
516
+ fprintf (stderr , "%s: -r maxretries must be >= 0\n" , progname );
495
517
exit (2 );
496
518
}
497
519
break ;
498
520
case 's' : /* Sleep time */
499
521
sleeptime = atoi (optarg );
500
522
if (sleeptime <= 0 || sleeptime > 60 )
501
523
{
502
- fprintf (stderr , "usage: pg_standby -s sleeptime incorrectly set\n" );
503
- usage ();
524
+ fprintf (stderr , "%s: -s sleeptime incorrectly set\n" , progname );
504
525
exit (2 );
505
526
}
506
527
break ;
@@ -513,13 +534,12 @@ main(int argc, char **argv)
513
534
maxwaittime = atoi (optarg );
514
535
if (maxwaittime < 0 )
515
536
{
516
- fprintf (stderr , "usage: pg_standby -w maxwaittime incorrectly set\n" );
517
- usage ();
537
+ fprintf (stderr , "%s: -w maxwaittime incorrectly set\n" , progname );
518
538
exit (2 );
519
539
}
520
540
break ;
521
541
default :
522
- usage ( );
542
+ fprintf ( stderr , "Try \"%s --help\" for more information.\n" , progname );
523
543
exit (2 );
524
544
break ;
525
545
}
@@ -530,7 +550,7 @@ main(int argc, char **argv)
530
550
*/
531
551
if (argc == 1 )
532
552
{
533
- usage ( );
553
+ fprintf ( stderr , "%s: not enough command-line arguments\n" , progname );
534
554
exit (2 );
535
555
}
536
556
@@ -547,8 +567,8 @@ main(int argc, char **argv)
547
567
}
548
568
else
549
569
{
550
- fprintf (stderr , "pg_standby : must specify archiveLocation \n" );
551
- usage ( );
570
+ fprintf (stderr , "%s : must specify archive location \n" , progname );
571
+ fprintf ( stderr , "Try \"%s --help\" for more information.\n" , progname );
552
572
exit (2 );
553
573
}
554
574
@@ -559,8 +579,8 @@ main(int argc, char **argv)
559
579
}
560
580
else
561
581
{
562
- fprintf (stderr , "pg_standby : use %%f to specify nextWALFileName\n" );
563
- usage ( );
582
+ fprintf (stderr , "%s : use %%f to specify nextWALFileName\n" , progname );
583
+ fprintf ( stderr , "Try \"%s --help\" for more information.\n" , progname );
564
584
exit (2 );
565
585
}
566
586
@@ -571,8 +591,8 @@ main(int argc, char **argv)
571
591
}
572
592
else
573
593
{
574
- fprintf (stderr , "pg_standby : use %%p to specify xlogFilePath\n" );
575
- usage ( );
594
+ fprintf (stderr , "%s : use %%p to specify xlogFilePath\n" , progname );
595
+ fprintf ( stderr , "Try \"%s --help\" for more information.\n" , progname );
576
596
exit (2 );
577
597
}
578
598
0 commit comments