|
73 | 73 | #define SUBOPT_FAILOVER 0x00002000 |
74 | 74 | #define SUBOPT_RETAIN_DEAD_TUPLES 0x00004000 |
75 | 75 | #define SUBOPT_MAX_RETENTION_DURATION 0x00008000 |
76 | | -#define SUBOPT_LSN 0x00010000 |
77 | | -#define SUBOPT_ORIGIN 0x00020000 |
| 76 | +#define SUBOPT_WAL_RECEIVER_TIMEOUT 0x00010000 |
| 77 | +#define SUBOPT_LSN 0x00020000 |
| 78 | +#define SUBOPT_ORIGIN 0x00040000 |
78 | 79 |
|
79 | 80 | /* check if the 'val' has 'bits' set */ |
80 | 81 | #define IsSet(val, bits) (((val) & (bits)) == (bits)) |
@@ -104,6 +105,7 @@ typedef struct SubOpts |
104 | 105 | int32 maxretention; |
105 | 106 | char *origin; |
106 | 107 | XLogRecPtr lsn; |
| 108 | + char *wal_receiver_timeout; |
107 | 109 | } SubOpts; |
108 | 110 |
|
109 | 111 | /* |
@@ -402,6 +404,30 @@ parse_subscription_options(ParseState *pstate, List *stmt_options, |
402 | 404 | opts->specified_opts |= SUBOPT_LSN; |
403 | 405 | opts->lsn = lsn; |
404 | 406 | } |
| 407 | + else if (IsSet(supported_opts, SUBOPT_WAL_RECEIVER_TIMEOUT) && |
| 408 | + strcmp(defel->defname, "wal_receiver_timeout") == 0) |
| 409 | + { |
| 410 | + bool parsed; |
| 411 | + int val; |
| 412 | + |
| 413 | + if (IsSet(opts->specified_opts, SUBOPT_WAL_RECEIVER_TIMEOUT)) |
| 414 | + errorConflictingDefElem(defel, pstate); |
| 415 | + |
| 416 | + opts->specified_opts |= SUBOPT_WAL_RECEIVER_TIMEOUT; |
| 417 | + opts->wal_receiver_timeout = defGetString(defel); |
| 418 | + |
| 419 | + /* |
| 420 | + * Test if the given value is valid for wal_receiver_timeeout GUC. |
| 421 | + * Skip this test if the value is -1, since -1 is allowed for the |
| 422 | + * wal_receiver_timeout subscription option, but not for the GUC |
| 423 | + * itself. |
| 424 | + */ |
| 425 | + parsed = parse_int(opts->wal_receiver_timeout, &val, 0, NULL); |
| 426 | + if (!parsed || val != -1) |
| 427 | + (void) set_config_option("wal_receiver_timeout", opts->wal_receiver_timeout, |
| 428 | + PGC_BACKEND, PGC_S_TEST, GUC_ACTION_SET, |
| 429 | + false, 0, false); |
| 430 | + } |
405 | 431 | else |
406 | 432 | ereport(ERROR, |
407 | 433 | (errcode(ERRCODE_SYNTAX_ERROR), |
@@ -610,7 +636,8 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt, |
610 | 636 | SUBOPT_DISABLE_ON_ERR | SUBOPT_PASSWORD_REQUIRED | |
611 | 637 | SUBOPT_RUN_AS_OWNER | SUBOPT_FAILOVER | |
612 | 638 | SUBOPT_RETAIN_DEAD_TUPLES | |
613 | | - SUBOPT_MAX_RETENTION_DURATION | SUBOPT_ORIGIN); |
| 639 | + SUBOPT_MAX_RETENTION_DURATION | |
| 640 | + SUBOPT_WAL_RECEIVER_TIMEOUT | SUBOPT_ORIGIN); |
614 | 641 | parse_subscription_options(pstate, stmt->options, supported_opts, &opts); |
615 | 642 |
|
616 | 643 | /* |
@@ -693,6 +720,14 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt, |
693 | 720 | if (opts.synchronous_commit == NULL) |
694 | 721 | opts.synchronous_commit = "off"; |
695 | 722 |
|
| 723 | + /* |
| 724 | + * The default for wal_receiver_timeout of subscriptions is -1, which |
| 725 | + * means the value is inherited from the server configuration, command |
| 726 | + * line, or role/database settings. |
| 727 | + */ |
| 728 | + if (opts.wal_receiver_timeout == NULL) |
| 729 | + opts.wal_receiver_timeout = "-1"; |
| 730 | + |
696 | 731 | conninfo = stmt->conninfo; |
697 | 732 | publications = stmt->publication; |
698 | 733 |
|
@@ -740,6 +775,8 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt, |
740 | 775 | nulls[Anum_pg_subscription_subslotname - 1] = true; |
741 | 776 | values[Anum_pg_subscription_subsynccommit - 1] = |
742 | 777 | CStringGetTextDatum(opts.synchronous_commit); |
| 778 | + values[Anum_pg_subscription_subwalrcvtimeout - 1] = |
| 779 | + CStringGetTextDatum(opts.wal_receiver_timeout); |
743 | 780 | values[Anum_pg_subscription_subpublications - 1] = |
744 | 781 | publicationListToArray(publications); |
745 | 782 | values[Anum_pg_subscription_suborigin - 1] = |
@@ -1408,6 +1445,7 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt, |
1408 | 1445 | SUBOPT_RUN_AS_OWNER | SUBOPT_FAILOVER | |
1409 | 1446 | SUBOPT_RETAIN_DEAD_TUPLES | |
1410 | 1447 | SUBOPT_MAX_RETENTION_DURATION | |
| 1448 | + SUBOPT_WAL_RECEIVER_TIMEOUT | |
1411 | 1449 | SUBOPT_ORIGIN); |
1412 | 1450 |
|
1413 | 1451 | parse_subscription_options(pstate, stmt->options, |
@@ -1663,6 +1701,13 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt, |
1663 | 1701 | origin = opts.origin; |
1664 | 1702 | } |
1665 | 1703 |
|
| 1704 | + if (IsSet(opts.specified_opts, SUBOPT_WAL_RECEIVER_TIMEOUT)) |
| 1705 | + { |
| 1706 | + values[Anum_pg_subscription_subwalrcvtimeout - 1] = |
| 1707 | + CStringGetTextDatum(opts.wal_receiver_timeout); |
| 1708 | + replaces[Anum_pg_subscription_subwalrcvtimeout - 1] = true; |
| 1709 | + } |
| 1710 | + |
1666 | 1711 | update_tuple = true; |
1667 | 1712 | break; |
1668 | 1713 | } |
|
0 commit comments