public inbox for [email protected]help / color / mirror / Atom feed
[PATCH] Fix misuses of RelationNeedsWAL 23+ messages / 2 participants [nested] [flat]
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH] Fix misuses of RelationNeedsWAL @ 2021-01-13 06:52 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Kyotaro Horiguchi @ 2021-01-13 06:52 UTC (permalink / raw) The definition of the macro RelationNeedsWAL has been changed by c6b92041d3 to include conditions related to the WAL-skip optimization but some uses of the macro are not relevant to the optimization. That misuses are harmless for now as they are only executed while wal_level >= replica or WAL-skipping is inactive. However, this should be corrected to prevent future hazard. --- src/backend/catalog/pg_publication.c | 2 +- src/backend/optimizer/util/plancat.c | 2 +- src/include/utils/rel.h | 15 +++++++++++---- src/include/utils/snapmgr.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 5f8e1c64e1..f3060a4cf1 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -67,7 +67,7 @@ check_publication_add_relation(Relation targetrel) errdetail("System tables cannot be added to publications."))); /* UNLOGGED and TEMP relations cannot be part of publication. */ - if (!RelationNeedsWAL(targetrel)) + if (!RelationIsWalLogged(targetrel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("table \"%s\" cannot be replicated", diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index da322b453e..0500efcdb9 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -126,7 +126,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, relation = table_open(relationObjectId, NoLock); /* Temporary and unlogged relations are inaccessible during recovery. */ - if (!RelationNeedsWAL(relation) && RecoveryInProgress()) + if (!RelationIsWalLogged(relation) && RecoveryInProgress()) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot access temporary or unlogged relations during recovery"))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0..810806a542 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -552,16 +552,23 @@ typedef struct ViewOptions (relation)->rd_smgr->smgr_targblock = (targblock); \ } while (0) +/* + * RelationIsPermanent + * True if relation is WAL-logged. + */ +#define RelationIsWalLogged(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + /* * RelationNeedsWAL - * True if relation needs WAL. + * True if relation needs WAL at the time. * * Returns false if wal_level = minimal and this relation is created or * truncated in the current transaction. See "Skipping WAL for New * RelFileNode" in src/backend/access/transam/README. */ #define RelationNeedsWAL(relation) \ - ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ + (RelationIsWalLogged(relation) && \ (XLogIsNeeded() || \ (relation->rd_createSubid == InvalidSubTransactionId && \ relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId))) @@ -619,7 +626,7 @@ typedef struct ViewOptions */ #define RelationIsAccessibleInLogicalDecoding(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* @@ -635,7 +642,7 @@ typedef struct ViewOptions */ #define RelationIsLogicallyLogged(relation) \ (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + RelationIsWalLogged(relation) && \ !IsCatalogRelation(relation)) /* routines in utils/cache/relcache.c */ diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 579be352c5..7be922a9f1 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -37,7 +37,7 @@ */ #define RelationAllowsEarlyPruning(rel) \ ( \ - RelationNeedsWAL(rel) \ + RelationIsWalLogged(rel) \ && !IsCatalogRelation(rel) \ && !RelationIsAccessibleInLogicalDecoding(rel) \ ) -- 2.27.0 ----Next_Part(Wed_Jan_13_16_07_05_2021_621)---- ^ permalink raw reply [nested|flat] 23+ messages in thread
* Re: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly @ 2024-10-31 10:32 Vitaly Davydov <[email protected]> 0 siblings, 1 reply; 23+ messages in thread From: Vitaly Davydov @ 2024-10-31 10:32 UTC (permalink / raw) To: pgsql-hackers Sorry, attached the missed patch. On Thursday, October 31, 2024 13:18 MSK, "Vitaly Davydov" <[email protected]> wrote: Dear Hackers, I'd like to discuss a problem with replication slots's restart LSN. Physical slots are saved to disk at the beginning of checkpoint. At the end of checkpoint, old WAL segments are recycled or removed from disk, if they are not kept by slot's restart_lsn values. If an existing physical slot is advanced in the middle of checkpoint execution, WAL segments, which are related to saved on disk restart LSN may be removed. It is because the calculation of the replication slot miminal LSN is occured at the end of checkpoint, prior to old WAL segments removal. If to hard stop (pg_stl -m immediate) the postgres instance right after checkpoint and to restart it, the slot's restart_lsn may point to the removed WAL segment. I believe, such behaviour is not good. The doc [0] describes that restart_lsn may be set to the some past value after reload. There is a discussion [1] on pghackers where such behaviour is discussed. The main reason of not flushing physical slots on advancing is a performance reason. I'm ok with such behaviour, except of that the corresponding WAL segments should not be removed. I propose to keep WAL segments by saved on disk (flushed) restart_lsn of slots. Add a new field restart_lsn_flushed into ReplicationSlot structure. Copy restart_lsn to restart_lsn_flushed in SaveSlotToPath. It doesn't change the format of storing the slot contents on disk. I attached a patch. It is not yet complete, but demonstate a way to solve the problem. I reproduced the problem by the following way: * Add some delay in CheckPointBuffers (pg_usleep) to emulate long checkpoint execution. * Execute checkpoint and pg_replication_slot_advance right after starting of the checkpoint from another connection. * Hard restart the server right after checkpoint completion. * After restart slot's restart_lsn may point to removed WAL segment. The proposed patch fixes it. [0] https://www.postgresql.org/docs/current/logicaldecoding-explanation.html [1] https://www.postgresql.org/message-id/flat/059cc53a-8b14-653a-a24d-5f867503b0ee%40postgrespro.ru Attachments: [text/x-patch] 0001-Keep-WAL-segments-by-slot-s-flushed-restart-LSN.patch (2.1K, ../../1d2043-67235d00-5-2e3223c0@131762497/3-0001-Keep-WAL-segments-by-slot-s-flushed-restart-LSN.patch) download | inline diff: From acae6b55fc766d2fe1bfe85eb8af85110f55dcc8 Mon Sep 17 00:00:00 2001 From: Vitaly Davydov <[email protected]> Date: Thu, 31 Oct 2024 12:29:12 +0300 Subject: [PATCH] Keep WAL segments by slot's flushed restart LSN --- src/backend/replication/slot.c | 9 +++++++-- src/include/replication/slot.h | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 6828100cf1..ee7ab3678e 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1148,7 +1148,9 @@ ReplicationSlotsComputeRequiredLSN(void) continue; SpinLockAcquire(&s->mutex); - restart_lsn = s->data.restart_lsn; + restart_lsn = s->restart_lsn_flushed != InvalidXLogRecPtr ? + s->restart_lsn_flushed : + s->data.restart_lsn; invalidated = s->data.invalidated != RS_INVAL_NONE; SpinLockRelease(&s->mutex); @@ -1207,7 +1209,9 @@ ReplicationSlotsComputeLogicalRestartLSN(void) /* read once, it's ok if it increases while we're checking */ SpinLockAcquire(&s->mutex); - restart_lsn = s->data.restart_lsn; + restart_lsn = s->restart_lsn_flushed != InvalidXLogRecPtr ? + s->restart_lsn_flushed : + s->data.restart_lsn; invalidated = s->data.invalidated != RS_INVAL_NONE; SpinLockRelease(&s->mutex); @@ -2097,6 +2101,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) SpinLockAcquire(&slot->mutex); memcpy(&cp.slotdata, &slot->data, sizeof(ReplicationSlotPersistentData)); + slot->restart_lsn_flushed = slot->data.restart_lsn; SpinLockRelease(&slot->mutex); diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h index 45582cf9d8..ca4c3aab3b 100644 --- a/src/include/replication/slot.h +++ b/src/include/replication/slot.h @@ -207,6 +207,10 @@ typedef struct ReplicationSlot /* The time since the slot has become inactive */ TimestampTz inactive_since; + + /* Latest restart LSN that was flushed to disk */ + XLogRecPtr restart_lsn_flushed; + } ReplicationSlot; #define SlotIsPhysical(slot) ((slot)->data.database == InvalidOid) -- 2.34.1 ^ permalink raw reply [nested|flat] 23+ messages in thread
* Re: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly @ 2024-11-07 13:30 Vitaly Davydov <[email protected]> parent: Vitaly Davydov <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Vitaly Davydov @ 2024-11-07 13:30 UTC (permalink / raw) To: pgsql-hackers Dear Hackers, I'd like to introduce an improved version of my patch (see the attached file). My original idea was to take into account saved on disk restart_lsn (slot→restart_lsn_flushed) for persistent slots when removing WAL segment files. It helps tackle errors like: ERROR: requested WAL segment 000...0AA has already been removed. Improvements: * flushed_restart_lsn is used only for RS_PERSISTENT slots. * Save physical slot on disk when advancing only once - if restart_lsn_flushed is invalid. It is needed because slots with invalid restart LSN are not used when calculating oldest LSN for WAL truncation. Once restart_lsn becomes valid, it should be saved to disk immediately to update restart_lsn_flushed. Regression tests seems to be ok except: * recovery/t/001_stream_rep.pl (checkpoint is needed) * recovery/t/019_replslot_limit.pl (it seems, slot was invalidated, some adjustments are needed) * pg_basebackup/t/020_pg_receivewal.pl (not sure about it) There are some problems: * More WAL segments may be kept. It may lead to invalidations of slots in some tests (recovery/t/019_replslot_limit.pl). A couple of tests should be adjusted. With best regards, Vitaly Davydov On Thursday, October 31, 2024 13:32 MSK, "Vitaly Davydov" <[email protected]> wrote: Sorry, attached the missed patch. On Thursday, October 31, 2024 13:18 MSK, "Vitaly Davydov" <[email protected]> wrote: Dear Hackers, I'd like to discuss a problem with replication slots's restart LSN. Physical slots are saved to disk at the beginning of checkpoint. At the end of checkpoint, old WAL segments are recycled or removed from disk, if they are not kept by slot's restart_lsn values. If an existing physical slot is advanced in the middle of checkpoint execution, WAL segments, which are related to saved on disk restart LSN may be removed. It is because the calculation of the replication slot miminal LSN is occured at the end of checkpoint, prior to old WAL segments removal. If to hard stop (pg_stl -m immediate) the postgres instance right after checkpoint and to restart it, the slot's restart_lsn may point to the removed WAL segment. I believe, such behaviour is not good. The doc [0] describes that restart_lsn may be set to the some past value after reload. There is a discussion [1] on pghackers where such behaviour is discussed. The main reason of not flushing physical slots on advancing is a performance reason. I'm ok with such behaviour, except of that the corresponding WAL segments should not be removed. I propose to keep WAL segments by saved on disk (flushed) restart_lsn of slots. Add a new field restart_lsn_flushed into ReplicationSlot structure. Copy restart_lsn to restart_lsn_flushed in SaveSlotToPath. It doesn't change the format of storing the slot contents on disk. I attached a patch. It is not yet complete, but demonstate a way to solve the problem. I reproduced the problem by the following way: * Add some delay in CheckPointBuffers (pg_usleep) to emulate long checkpoint execution. * Execute checkpoint and pg_replication_slot_advance right after starting of the checkpoint from another connection. * Hard restart the server right after checkpoint completion. * After restart slot's restart_lsn may point to removed WAL segment. The proposed patch fixes it. [0] https://www.postgresql.org/docs/current/logicaldecoding-explanation.html [1] https://www.postgresql.org/message-id/flat/059cc53a-8b14-653a-a24d-5f867503b0ee%40postgrespro.ru Attachments: [text/x-patch] 0001-Keep-WAL-segments-by-slot-s-flushed-restart-LSN.patch (6.2K, ../../2802b6-672cc100-29-48025b80@131204041/3-0001-Keep-WAL-segments-by-slot-s-flushed-restart-LSN.patch) download | inline diff: From d52e254c558e665bc41389e02e026c1069b29861 Mon Sep 17 00:00:00 2001 From: Vitaly Davydov <[email protected]> Date: Thu, 31 Oct 2024 12:29:12 +0300 Subject: [PATCH] Keep WAL segments by slot's flushed restart LSN --- src/backend/replication/slot.c | 27 ++++++++++++++++++++++++++- src/backend/replication/walsender.c | 13 +++++++++++++ src/include/replication/slot.h | 4 ++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 6828100cf1..e6aef1f9a3 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -409,6 +409,7 @@ ReplicationSlotCreate(const char *name, bool db_specific, slot->candidate_restart_valid = InvalidXLogRecPtr; slot->candidate_restart_lsn = InvalidXLogRecPtr; slot->last_saved_confirmed_flush = InvalidXLogRecPtr; + slot->restart_lsn_flushed = InvalidXLogRecPtr; slot->inactive_since = 0; /* @@ -1142,20 +1143,28 @@ ReplicationSlotsComputeRequiredLSN(void) { ReplicationSlot *s = &ReplicationSlotCtl->replication_slots[i]; XLogRecPtr restart_lsn; + XLogRecPtr restart_lsn_flushed; bool invalidated; + ReplicationSlotPersistency persistency; if (!s->in_use) continue; SpinLockAcquire(&s->mutex); + persistency = s->data.persistency; restart_lsn = s->data.restart_lsn; invalidated = s->data.invalidated != RS_INVAL_NONE; + restart_lsn_flushed = s->restart_lsn_flushed; SpinLockRelease(&s->mutex); /* invalidated slots need not apply */ if (invalidated) continue; + /* truncate WAL for persistent slots by flushed restart_lsn */ + if (persistency == RS_PERSISTENT) + restart_lsn = restart_lsn_flushed; + if (restart_lsn != InvalidXLogRecPtr && (min_required == InvalidXLogRecPtr || restart_lsn < min_required)) @@ -1193,7 +1202,9 @@ ReplicationSlotsComputeLogicalRestartLSN(void) { ReplicationSlot *s; XLogRecPtr restart_lsn; + XLogRecPtr restart_lsn_flushed; bool invalidated; + ReplicationSlotPersistency persistency; s = &ReplicationSlotCtl->replication_slots[i]; @@ -1207,14 +1218,20 @@ ReplicationSlotsComputeLogicalRestartLSN(void) /* read once, it's ok if it increases while we're checking */ SpinLockAcquire(&s->mutex); - restart_lsn = s->data.restart_lsn; + persistency = s->data.persistency; + restart_lsn = s->restart_lsn_flushed; invalidated = s->data.invalidated != RS_INVAL_NONE; + restart_lsn_flushed = s->restart_lsn_flushed; SpinLockRelease(&s->mutex); /* invalidated slots need not apply */ if (invalidated) continue; + /* truncate WAL for persistent slots by flushed restart_lsn */ + if (persistency == RS_PERSISTENT) + restart_lsn = restart_lsn_flushed; + if (restart_lsn == InvalidXLogRecPtr) continue; @@ -1432,6 +1449,7 @@ ReplicationSlotReserveWal(void) Assert(slot != NULL); Assert(slot->data.restart_lsn == InvalidXLogRecPtr); + Assert(slot->restart_lsn_flushed == InvalidXLogRecPtr); /* * The replication slot mechanism is used to prevent removal of required @@ -1607,6 +1625,8 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlotInvalidationCause cause, */ SpinLockAcquire(&s->mutex); + Assert(s->data.restart_lsn >= s->restart_lsn_flushed); + restart_lsn = s->data.restart_lsn; /* we do nothing if the slot is already invalid */ @@ -1691,7 +1711,10 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlotInvalidationCause cause, * just rely on .invalidated. */ if (invalidation_cause == RS_INVAL_WAL_REMOVED) + { s->data.restart_lsn = InvalidXLogRecPtr; + s->restart_lsn_flushed = InvalidXLogRecPtr; + } /* Let caller know */ *invalidated = true; @@ -2189,6 +2212,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) if (!slot->just_dirtied) slot->dirty = false; slot->last_saved_confirmed_flush = cp.slotdata.confirmed_flush; + slot->restart_lsn_flushed = cp.slotdata.restart_lsn; SpinLockRelease(&slot->mutex); LWLockRelease(&slot->io_in_progress_lock); @@ -2386,6 +2410,7 @@ RestoreSlotFromDisk(const char *name) slot->effective_xmin = cp.slotdata.xmin; slot->effective_catalog_xmin = cp.slotdata.catalog_xmin; slot->last_saved_confirmed_flush = cp.slotdata.confirmed_flush; + slot->restart_lsn_flushed = cp.slotdata.restart_lsn; slot->candidate_catalog_xmin = InvalidTransactionId; slot->candidate_xmin_lsn = InvalidXLogRecPtr; diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 371eef3ddd..03cdce23f0 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -2329,6 +2329,7 @@ static void PhysicalConfirmReceivedLocation(XLogRecPtr lsn) { bool changed = false; + XLogRecPtr restart_lsn_flushed; ReplicationSlot *slot = MyReplicationSlot; Assert(lsn != InvalidXLogRecPtr); @@ -2336,6 +2337,7 @@ PhysicalConfirmReceivedLocation(XLogRecPtr lsn) if (slot->data.restart_lsn != lsn) { changed = true; + restart_lsn_flushed = slot->restart_lsn_flushed; slot->data.restart_lsn = lsn; } SpinLockRelease(&slot->mutex); @@ -2343,6 +2345,17 @@ PhysicalConfirmReceivedLocation(XLogRecPtr lsn) if (changed) { ReplicationSlotMarkDirty(); + + /* Save the replication slot on disk in case of its flushed restart_lsn + * is invalid. Slots with invalid restart lsn are ignored when + * calculating required LSN. Once we started to keep the WAL by flushed + * restart LSN, we should save to disk an initial valid value. + */ + if (slot->data.persistency == RS_PERSISTENT) { + if (restart_lsn_flushed == InvalidXLogRecPtr && lsn != InvalidXLogRecPtr) + ReplicationSlotSave(); + } + ReplicationSlotsComputeRequiredLSN(); PhysicalWakeupLogicalWalSnd(); } diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h index 45582cf9d8..ca4c3aab3b 100644 --- a/src/include/replication/slot.h +++ b/src/include/replication/slot.h @@ -207,6 +207,10 @@ typedef struct ReplicationSlot /* The time since the slot has become inactive */ TimestampTz inactive_since; + + /* Latest restart LSN that was flushed to disk */ + XLogRecPtr restart_lsn_flushed; + } ReplicationSlot; #define SlotIsPhysical(slot) ((slot)->data.database == InvalidOid) -- 2.34.1 ^ permalink raw reply [nested|flat] 23+ messages in thread
end of thread, other threads:[~2024-11-07 13:30 UTC | newest] Thread overview: 23+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2021-01-13 06:52 [PATCH] Fix misuses of RelationNeedsWAL Kyotaro Horiguchi <[email protected]> 2024-10-31 10:32 Re: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly Vitaly Davydov <[email protected]> 2024-11-07 13:30 ` Re: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly Vitaly Davydov <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox