question about relation_open

Started by Giampaolo Capelliover 1 year ago5 messageshackers
Jump to latest
#1Giampaolo Capelli
giampow@gmail.com

Hi there,
I'm trying to write an extension to study the internals of Postgresql, and
I face a server crash after calling the function relation_open.

I want to call the function ReadBufferExtended
to get the raw data of a given buffer
and I've read in some examples that I need to call relation_open
first, in order to get a Relation variable and also lock the relation.

The function relation_open returns a non NULL pointer in my extension, but
then the last line in the following snippet crashes postgres.

Relation rel;
rel = relation_open(relid, AccessShareLock);

Assert(rel != NULL);
Assert(rel->rd_rel != NULL);
Assert(rel->rd_id != NULL);
elog(INFO, "rel->rd_id not null");
Oid rd_id = rel->rd_id;

Could somebody please help me understand what I'm doing wrong?
(Sorry if this is not the correct mailing list)

#2Rahila Syed
rahilasyed90@gmail.com
In reply to: Giampaolo Capelli (#1)
Re: question about relation_open

Hi,

I want to call the function ReadBufferExtended
to get the raw data of a given buffer
and I've read in some examples that I need to call relation_open
first, in order to get a Relation variable and also lock the relation.

The function relation_open returns a non NULL pointer in my extension, but
then the last line in the following snippet crashes postgres.

You mentioned that the postgres crashes. Did you mean it caused a
Segmentation fault or something else like PANIC?
If possible, can you share a core dump in that case?

Also, can you share any errors that you see in logs when postgres crashes?

Thank you,
Rahila Syed

#3Giampaolo Capelli
giampow@gmail.com
In reply to: Rahila Syed (#2)
Re: question about relation_open

hi Rahila, thank you for your response,
I mean Segmentation fault, this is what I see in psql

SSL SYSCALL error: EOF detected
The connection to the server was lost. Attempting reset: Failed.
!?>

this is the content of
in /var/log/postgresql/postgresql-14-main.log when a segmentation fault
happens

2025-01-14 12:30:12.092 CET [1538] LOG: server process (PID 34594) was
terminated by signal 11: Erreur de segmentation
2025-01-14 12:30:12.092 CET [1538] DETAIL: Failed process was running:
select visualize_buffers(90);
2025-01-14 12:30:12.092 CET [1538] LOG: terminating any other active
server processes
2025-01-14 12:30:12.097 CET [1538] LOG: all server processes terminated;
reinitializing
2025-01-14 12:30:12.115 CET [34608] LOG: database system was interrupted;
last known up at 2025-01-14 10:36:29 CET
2025-01-14 12:30:12.175 CET [34610] postgres@postgres FATAL: the database
system is in recovery mode
2025-01-14 12:30:12.279 CET [34608] LOG: database system was not properly
shut down; automatic recovery in progress
2025-01-14 12:30:12.281 CET [34608] LOG: redo starts at 0/1CCF820
2025-01-14 12:30:12.281 CET [34608] LOG: invalid record length at
0/1CCF858: wanted 24, got 0
2025-01-14 12:30:12.281 CET [34608] LOG: redo done at 0/1CCF820 system
usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2025-01-14 12:30:12.379 CET [1538] LOG: database system is ready to accept
connections

I don't know how to collect a core dump of postgres, I tried with gdb, but
It doesn't seem to log anything interesting

Le mar. 14 janv. 2025 à 12:27, Rahila Syed <rahilasyed90@gmail.com> a
écrit :

Show quoted text

Hi,

I want to call the function ReadBufferExtended
to get the raw data of a given buffer
and I've read in some examples that I need to call relation_open
first, in order to get a Relation variable and also lock the relation.

The function relation_open returns a non NULL pointer in my extension,
but then the last line in the following snippet crashes postgres.

You mentioned that the postgres crashes. Did you mean it caused a
Segmentation fault or something else like PANIC?
If possible, can you share a core dump in that case?

Also, can you share any errors that you see in logs when postgres crashes?

Thank you,
Rahila Syed

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Giampaolo Capelli (#1)
Re: question about relation_open

Giampaolo Capelli <giampow@gmail.com> writes:

The function relation_open returns a non NULL pointer in my extension, but
then the last line in the following snippet crashes postgres.

Relation rel;
rel = relation_open(relid, AccessShareLock);

Assert(rel != NULL);
Assert(rel->rd_rel != NULL);
Assert(rel->rd_id != NULL);
elog(INFO, "rel->rd_id not null");
Oid rd_id = rel->rd_id;

Hmm, I'm a little bit doubting your statement that relation_open
succeeded. I wonder if maybe you built your extension without asserts
enabled ...

regards, tom lane

#5Giampaolo Capelli
giampow@gmail.com
In reply to: Tom Lane (#4)
Re: question about relation_open

It seems the issue was related to some misconfiguration of my postgresql
server,
I've migrated from pg 14 to 17 and now the issue has disappeared.

Also, I replaced relation_open with table_open

Le mar. 14 janv. 2025 à 15:40, Tom Lane <tgl@sss.pgh.pa.us> a écrit :

Giampaolo Capelli <giampow@gmail.com> writes:

The function relation_open returns a non NULL pointer in my extension,

but

then the last line in the following snippet crashes postgres.

Relation rel;
rel = relation_open(relid, AccessShareLock);

Assert(rel != NULL);
Assert(rel->rd_rel != NULL);
Assert(rel->rd_id != NULL);
elog(INFO, "rel->rd_id not null");
Oid rd_id = rel->rd_id;

Hmm, I'm a little bit doubting your statement that relation_open
succeeded. I wonder if maybe you built your extension without asserts
enabled ...

regards, tom lane

--
Giampaolo Capelli