diff --git a/pgxn/neon/pagestore_client.h b/pgxn/neon/pagestore_client.h index 806cef08b1..749e9a584f 100644 --- a/pgxn/neon/pagestore_client.h +++ b/pgxn/neon/pagestore_client.h @@ -322,7 +322,11 @@ typedef enum RELKIND_UNLOGGED_BUILD } RelKind; -/* entry type stored in relkind_hash */ +/* + * Entry type stored in relkind_hash. We have just one entry for the whole relation, i.e. we don't have separate entries for the individual forks. + * It gets a little complicated with unlogged relations. The main fork of an unlogged relation is considered UNLOGGED, but its init-fork is + * treated as PERMANENT. It is specially checked in neon_write. + */ typedef struct { NRelFileInfo rel; diff --git a/pgxn/neon/pagestore_smgr.c b/pgxn/neon/pagestore_smgr.c index b152c98f5e..ca4cd4b549 100644 --- a/pgxn/neon/pagestore_smgr.c +++ b/pgxn/neon/pagestore_smgr.c @@ -1610,6 +1610,10 @@ neon_write(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const vo switch (reln->smgr_relpersistence) { case 0: + if (forknum == INIT_FORKNUM) + { + break; /* init fork is always permanent */ + } relkind = get_cached_relkind(rinfo); if (relkind == RELKIND_UNKNOWN) { @@ -1715,6 +1719,10 @@ neon_writev(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, switch (reln->smgr_relpersistence) { case 0: + if (forknum == INIT_FORKNUM) + { + break; /* init fork is always permanent */ + } relkind = get_cached_relkind(rinfo); if (relkind == RELKIND_UNKNOWN) { diff --git a/pgxn/neon/relkind_cache.c b/pgxn/neon/relkind_cache.c index 4d47b0b7ef..a5838bc0cc 100644 --- a/pgxn/neon/relkind_cache.c +++ b/pgxn/neon/relkind_cache.c @@ -91,9 +91,9 @@ relkind_cache_startup(void) /* * In the worst case, the hash needs to be large enough for the case that all backends are performing an unlogged index build at the same time. * Or actually twice that, because while performing an unlogged index build, each backend can also be trying to write out a page for another - * relation and hence hold one more entry in the cache pinned. + * relation and hence hold one more entry in the cache pinned. Use MaxConnections instead of MaxBackends because only normal backends can perform unlogged build. */ - size_t hash_size = Max(2 * MaxBackends, relkind_hash_size); + size_t hash_size = Max(2 * MaxConnections, relkind_hash_size); relkind_hash_lock = (LWLockId) GetNamedLWLockTranche("neon_relkind"); finish_unlogged_build_lock = (LWLockId)(GetNamedLWLockTranche("neon_relkind") + 1); info.keysize = sizeof(NRelFileInfo);