Fwd: Segmentation fault on RelationGetDescr in my first extension
От | Дмитрий Цветков |
---|---|
Тема | Fwd: Segmentation fault on RelationGetDescr in my first extension |
Дата | |
Msg-id | CALS6dkRaXHV1Od5Xt1zyEUKdhHfE5WrL1sq062Pp_eMw-rZ=DA@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Segmentation fault on RelationGetDescr in my first extension
|
Список | pgsql-general |
Hi!
I'm trying to write my first extension and open a table in it.
I use check_password_hook and my function executes at the moment of changing user password.
But if I try to open a table inside this function, I get Segmentation fault on the line with "RelationGetDescr".
What am I doing wrong?
void
_PG_init(void)
{
prev_check_password_hook = check_password_hook;
check_password_hook = check_password;
}
_PG_init(void)
{
prev_check_password_hook = check_password_hook;
check_password_hook = check_password;
}
...
void check_password(const char *username, const char *shadow_pass, PasswordType password_type, Datum validuntil_time, bool validuntil_null)
{
Relation rel;
TupleDesc tupdesc;
int Natts;
Oid tbl_oid = DatumGetObjectId(DirectFunctionCall1(to_regclass, CStringGetTextDatum("my_test_table")));
if (OidIsValid(tbl_oid)) {
rel = table_open(tbl_oid, RowExclusiveLock);
tupdesc = RelationGetDescr(rel); // !!! server process (PID 70525) was terminated by signal 11: Segmentation fault
Natts = tupdesc->natts;
table_close(rel, RowExclusiveLock);
} else {
ereport(NOTICE, (errmsg("IndexRelationId (%d) is NOT valid !", tbl_oid)));
}
}
{
Relation rel;
TupleDesc tupdesc;
int Natts;
Oid tbl_oid = DatumGetObjectId(DirectFunctionCall1(to_regclass, CStringGetTextDatum("my_test_table")));
if (OidIsValid(tbl_oid)) {
rel = table_open(tbl_oid, RowExclusiveLock);
tupdesc = RelationGetDescr(rel); // !!! server process (PID 70525) was terminated by signal 11: Segmentation fault
Natts = tupdesc->natts;
table_close(rel, RowExclusiveLock);
} else {
ereport(NOTICE, (errmsg("IndexRelationId (%d) is NOT valid !", tbl_oid)));
}
}
Table is fine:
postgres=# \d my_test_table
Table "public.my_test_table"
Column | Type | Collation | Nullable | Default
--------+------+-----------+----------+---------
name | text | | |
Table "public.my_test_table"
Column | Type | Collation | Nullable | Default
--------+------+-----------+----------+---------
name | text | | |
В списке pgsql-general по дате отправления: