pgvector icon indicating copy to clipboard operation
pgvector copied to clipboard

Memory allocation failure at CREATE EXTENSION.

Open pashkinelfe opened this issue 8 months ago • 5 comments

Hi! I found the following error at trying create extension on one of the customers machine: not enough shared memory for data structure "hnsw LWLock ids" (4 bytes requested) called from the code block

/*
 * Assign a tranche ID for our LWLocks. This only needs to be done by one
 * backend, as the tranche ID is remembered in shared memory.
 *
 * This shared memory area is very small, so we just allocate it from the
 * "slop" that PostgreSQL reserves for small allocations like this. If
 * this grows bigger, we should use a shmem_request_hook and
 * RequestAddinShmemSpace() to pre-reserve space for this.
 */
void
HnswInitLockTranche(void)
{
	int		   *tranche_ids;
	bool		found;

	LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
	tranche_ids = ShmemInitStruct("hnsw LWLock ids",
								  sizeof(int) * 1,
								  &found);
	if (!found)
		tranche_ids[0] = LWLockNewTrancheId();
	hnsw_lock_tranche_id = tranche_ids[0];
	LWLockRelease(AddinShmemInitLock);

	/* Per-backend registration of the tranche ID */
	LWLockRegisterTranche(hnsw_lock_tranche_id, "HnswBuild");
}

It's a rare error that I met only once. Could we not rely that the 'slop' has enough free space to do allocation? As I think PG user has little power to check or free this memory.

pashkinelfe avatar Jun 21 '24 07:06 pashkinelfe