Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RelationIdCache is NULL when call table_open() in background worker #1728

Open
xingtanzjr opened this issue May 31, 2024 · 3 comments
Open

Comments

@xingtanzjr
Copy link

Hi there,

I am trying to open a table by Oid in a background worker. But it encountered segmentation fault when trying to open the table.

Here is my code snip

#[pg_guard]
#[no_mangle]
unsafe extern "C" fn parallel_worker_build_index(arg: pg_sys::Datum) {

	// convert Datum to dsm_handle
	let dsm_handle = arg.value() as u32;

	let dsm_segment = pg_sys::dsm_attach(dsm_handle);
	if dsm_segment.is_null() {
		log!("dsm_segment is null");
	}

	let build_state = pg_sys::dsm_segment_address(dsm_segment) as *mut BuildState;

	let heapreloid = (*build_state).heapreloid;
	let indexreloid = (*build_state).indexreloid;

	pg_sys::StartTransactionCommand();
	let heaprel = pg_sys::table_open(heapreloid, pg_sys::AccessShareLock as i32);
	log!("parallel_worker heaprel opened");

I tried to debug it and found that the error occurs here:
image

It seems that the RelationIdCache is NULL
image

Is someone met the similar issue before ? thanks for your input!

@workingjubilee
Copy link
Member

Are you testing the code against a pgrx-built database? One with assertions enabled? That should have caught this behavior.

@xingtanzjr
Copy link
Author

@workingjubilee Yes. I install this extension using cargo pgrx install and start the postgres like this

Cargo pgrx start pg15
Cargo pgrx connect pg15

@workingjubilee
Copy link
Member

At what point during Postgres execution is this function running?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants