-
Notifications
You must be signed in to change notification settings - Fork 77
Description
Hi, I am getting a segmentation fault in PLJava 1.5.5 with PostgreSQL version 12.5. The stack trace looks like this
#0 0x00007f1759389795 pljavaDbName (libpljava-so-1.5.5.so)
#1 0x00007f1759380de3 JVMOptList_addVisualVMName (libpljava-so-1.5.5.so)
#2 0x00007f175937faff initsequencer (libpljava-so-1.5.5.so)
#3 0x00007f17593802f1 _PG_init (libpljava-so-1.5.5.so)
#4 0x0000000000882d4a internal_load_library (postgres)
#5 0x00000000008835d3 load_external_function (postgres)
#6 0x0000000000883f81 fmgr_info_cxt_security (postgres)
#7 0x0000000000883dad fmgr_info_cxt_security (postgres)
#8 0x000000000060d091 ExecInitFunc (postgres)
#9 0x000000000060acdc ExecInitExprRec (postgres)
#10 0x000000000060ce2c ExecInitExpr (postgres)
#11 0x000000000060cf65 ExecPrepareExpr (postgres)
#12 0x000000000060cfb3 ExecPrepareExprList (postgres)
#13 0x000000000052a962 FormIndexDatum (postgres)
#14 0x0000000000599364 do_analyze_rel.isra.3 (postgres)
#15 0x0000000000599964 analyze_rel (postgres)
#16 0x000000000060719a vacuum (postgres)
#17 0x00000000006e1124 do_autovacuum (postgres)
#18 0x00000000006e15e8 AutoVacWorkerMain.isra.6 (postgres)
#19 0x00000000006e1e89 StartAutoVacWorker (postgres)
#20 0x00000000006f00e2 sigusr1_handler (postgres)
#21 0x00007f19781095e0 __restore_rt (libpthread.so.0)
#22 0x00007f1975eb3783 __select (libc.so.6)
#23 0x0000000000483810 ServerLoop (postgres)
#24 0x00000000006f10b3 PostmasterMain (postgres)
#25 0x0000000000485073 main (postgres)
#26 0x00007f1975de5c05 __libc_start_main (libc.so.6)
#27 0x00000000004850da _start (postgres)
I have a table with function-based index where the function is written in Java. The crash happens when the table is autovacuumed. The crashing function is pljavaDbName (in InstallHelper.c) and happens because MyProcPort is NULL.
char *pljavaDbName()
{
#ifdef BGW_HAS_NO_MYPROCPORT
char *shortlived;
static char *longlived;
if ( IsBackgroundWorker )
{
if ( NULL == longlived )
{
shortlived = get_database_name(MyDatabaseId);
if ( NULL != shortlived )
{
longlived = MemoryContextStrdup(TopMemoryContext, shortlived);
pfree(shortlived);
}
}
return longlived;
}
#endif
return MyProcPort->database_name;
}Looking at the PostgreSQL 12.5 source I can see that when an autovacuum worker is started MyProcPort is not set.
As a workaround I changed PLJava Backend.c. I commented out lines 662-666
greeting = InstallHelper_hello();
ereport(NULL != pljavaLoadPath ? NOTICE : DEBUG1, (
errmsg("PL/Java loaded"),
errdetail("versions:\n%s", greeting)));
pfree(greeting);
and at line 564 I set seenVisualVMName to true.
These two changes solved my problem.
Looking at the latest version of PLJava, 1.6.2, the function pljavaDbName has not changed since 1.5.5.
Is there anything you can do to handle this issue in the official version?
Regards and Thanks
Richard Hennessy