| From: | Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> | 
|---|---|
| To: | pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Wrong usage of RelationNeedsWAL | 
| Date: | 2021-01-13 07:07:05 | 
| Message-ID: | 20210113.160705.2225256954956139776.horikyota.ntt@gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Hello.
Commit c6b92041d3 changed the definition of RelationNeedsWAL().
-#define RelationNeedsWAL(relation) \
-	((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
+#define RelationNeedsWAL(relation)										\
+	((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT &&	\
+	 (XLogIsNeeded() ||													\
+	  (relation->rd_createSubid == InvalidSubTransactionId &&			\
+	   relation->rd_firstRelfilenodeSubid == InvalidSubTransactionId)))
On the other hand I found this usage.
plancat.c:128 get_relation_info()
>	/* Temporary and unlogged relations are inaccessible during recovery. */
>	if (!RelationNeedsWAL(relation) && RecoveryInProgress())
>		ereport(ERROR,
>				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
>				 errmsg("cannot access temporary or unlogged relations during recovery")));
It works as expected accidentally, but the meaning is off.
WAL-skipping optmization is irrelevant to the condition for the error.
I found five misues in the tree. Please find the attached.
regards.
-- 
Kyotaro Horiguchi
NTT Open Source Software Center
| Attachment | Content-Type | Size | 
|---|---|---|
| 0001-Fix-misuses-of-RelationNeedsWAL.patch | text/x-patch | 4.1 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | japin | 2021-01-13 07:09:37 | Re: Logical Replication - behavior of ALTER PUBLICATION .. DROP TABLE and ALTER SUBSCRIPTION .. REFRESH PUBLICATION | 
| Previous Message | Peter Smith | 2021-01-13 06:33:26 | Re: Single transaction in the tablesync worker? |