Thread: postmaster process and multithreading

postmaster process and multithreading

From
andrew klassen
Date:
 
I compiled postgres with threading enabled because I wanted
multithreading in the client process that I was writing. I don't
necessarily care if all server processes are multithreaded but
it does look like it affects the postmaster process in some way.
 
The reason I am asking is because sometimes the postmaster
will create a core dump and it will show two threads but the
backtrace on both threads does not show any helpful information.
I am wondering if I can disable multithreading in the postmaster/server
file compiles and by doing so make the gdb output a little more helpful.
 
I have include gdb backtraces. Any ideas are welcome.
BTW I am running postgres 8.2.5 and Freebsd 4.10.
 
Here is what I get:
# gdb postgres -c /cores/postgres-0-474dcec7
GNU gdb 4.18 (FreeBSD)
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
Core was generated by `postgres'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/lib/libcrypt.so.2...done.
Reading symbols from /usr/lib/libm.so.2...done.
Reading symbols from /usr/lib/libc_r.so.4...done.
Reading symbols from /usr/libexec/ld-elf.so.1...done.
#0  0x8837bc94 in thread_sigframe_add (thread=0x0, sig=0, has_args=0)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_sig.c:1093
1093    /usr/bsd/src/lib/libc_r/uthread/uthread_sig.c: No such file or directory.
(gdb) bt
#0  0x8837bc94 in thread_sigframe_add (thread=0x0, sig=0, has_args=0)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_sig.c:1093
(gdb) info threads
  2 process 264745  _thread_kern_scheduler ()
    at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:602
* 1 process 133673  0x8837bc94 in thread_sigframe_add (thread=0x0, sig=0,
    has_args=0) at /usr/bsd/src/lib/libc_r/uthread/uthread_sig.c:1093
(gdb) thread 2
[Switching to thread 2 (process 264745)]
#0  _thread_kern_scheduler ()
    at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:602
602     /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c: No such file or directory.
(gdb) bt
#0  _thread_kern_scheduler ()
    at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:602
#1  0x0 in ?? ()
(gdb) bt full
#0  _thread_kern_scheduler ()
    at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:602
        ts = {tv_sec = 102, tv_nsec = 799262000}
        tv = {tv_sec = 102, tv_usec = 799262}
        curthread = (struct pthread *) 0x8327000
        pthread = 0x883c5090
        pthread_h = 0x8327000
        current_tick = 0
        add_to_prioq = 1
#1  0x0 in ?? ()
No symbol table info available.
(gdb) thread 1
[Switching to thread 1 (process 133673)]
#0  0x8837bc94 in thread_sigframe_add (thread=0x0, sig=0, has_args=0)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_sig.c:1093
1093    /usr/bsd/src/lib/libc_r/uthread/uthread_sig.c: No such file or directory.
(gdb) bt full
#0  0x8837bc94 in thread_sigframe_add (thread=0x0, sig=0, has_args=0)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_sig.c:1093
        has_args = -2009207968
        psf = (struct pthread_signal_frame *) 0x0
        stackp = 0
(gdb) l main
55      main.c: No such file or directory.
(gdb) l PostmasterMain
373     postmaster.c: No such file or directory.
(gdb) print IsPostmasterEnvironment
$1 = 1 '\001'
(gdb) print MyProcPid
$2 = 2601
(gdb) print IsUnderPostmaster
$3 = 0 '\000'
(gdb) print StartupPID
$4 = 0
(gdb) print BgWriterPID
$5 = 2652
(gdb) print PgStatPID
$6 = 2653
(gdb) quit
 
If I attach gdb to a health postmaster thread #1 bt still does not look correct:
 
0x8838094c in __sys_poll () from /usr/lib/libc_r.so.4
(gdb) info threads
  2 process 36551, thread 2  0x8837f1bb in _thread_kern_sched (ucp=0x0)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:123
* 1 process 36551, thread 1  0x8838094c in __sys_poll () from /usr/lib/libc_r.so.4
(gdb) bt full
#0  0x8838094c in __sys_poll () from /usr/lib/libc_r.so.4
No symbol table info available.
#1  0x8837fe74 in thread_kern_poll (wait_reqd=1)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:829
        count = 0
        i = -2009313020
        found = -1077937916
        kern_pipe_added = 1
        nfds = 3
        timeout_ms = 60000
        pthread = (struct pthread *) 0x0
        ts = {tv_sec = 6593, tv_nsec = 729608000}
        tv = {tv_sec = 6593, tv_usec = 729608}
#2  0x8837f81e in _thread_kern_scheduler ()
    at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:504
        ts = {tv_sec = 6593, tv_nsec = 729608000}
        tv = {tv_sec = 6593, tv_usec = 729608}
        curthread = (struct pthread *) 0x883dc9a0
        pthread = 0x883c5090
        pthread_h = 0x0
        current_tick = 2285764128
        add_to_prioq = 0
#3  0x0 in ?? ()
No symbol table info available.
(gdb) thread 2
[Switching to thread 2 (process 36551, thread 2)]
#0  0x8837f1bb in _thread_kern_sched (ucp=0x0)
    at /usrbsd/src/lib/libc_r/uthread/uthread_kern.c:123
123     /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c: No such file or di
rectory.
(gdb) bt full
#0  0x8837f1bb in _thread_kern_sched (ucp=0x0)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:123
        curthread = (struct pthread *) 0x8327000
#1  0x8837f9f9 in _thread_kern_sched_state (state=PS_SELECT_WAIT,
    fname=0x883be360 "/usr/bsd/src/lib/libc_r/uthread/uthread_select.c",
    lineno=149) at /usr/bsd/src/lib/libc_r/uthread/uthread_kern.c:637
        state = PS_SELECT_WAIT
        fname = 0x883be360 "/usr/bsd/src/lib/libc_r/uthread/uthread_select
.c"
        curthread = (struct pthread *) 0xbfbff904
#2  0x8837c94f in _select (numfds=7, readfds=0xbfbff9d4, writefds=0x0,
    exceptfds=0x0, timeout=0xbfbff9c4)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_select.c:149
        timeout = (struct timeval *) 0xbfbff904
        curthread = (struct pthread *) 0x8327000
        ts = {tv_sec = 60, tv_nsec = 0}
        i = 4
        ret = 0
        f_wait = 1
        pfd_index = -1077937916
        got_events = -1077937900
        fd_count = 2
        data = {nfds = 2, fds = 0x8327c00}
#3  0x8837cb66 in select (numfds=7, readfds=0xbfbff9d4, writefds=0x0,
    exceptfds=0x0, timeout=0xbfbff9c4)
    at /usr/bsd/src/lib/libc_r/uthread/uthread_select.c:271
        exceptfds = (fd_set *) 0x0
        timeout = (struct timeval *) 0xbfbff9c4
        ret = -1077937724
#4  0x817c80b in ServerLoop () at postmaster.c:1162
        port = (Port *) 0xbfbff9c4
        rmask = {fds_bits = {96, 0 <repeats 31 times>}}
        timeout = {tv_sec = 60, tv_usec = 0}
        selres = -1077937724
        i = -1077937452
        readmask = {fds_bits = {96, 0 <repeats 31 times>}}
        nSockets = 7
        now = -1077937724
        last_touch_time = 1196288034
        earlier = {tv_sec = 1196288034, tv_usec = 365978}
        later = {tv_sec = -2009303956, tv_usec = 2}
#5  0x817c42a in PostmasterMain (argc=11, argv=0xbfbffbac) at postmaster.c:966
        opt = 137671169
        status = 209
        userDoption = 0x834b200 "\220\002"
        i = 60000
#6  0x8142974 in main (argc=11, argv=0xbfbffbac) at main.c:188
        argv = (char **) 0xbfbffbac
(gdb)
 


Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now.

Re: postmaster process and multithreading

From
Tom Lane
Date:
andrew klassen <aptklassen@yahoo.com> writes:
> The reason I am asking is because sometimes the postmaster
> will create a core dump and it will show two threads but the
> backtrace on both threads does not show any helpful information.

Are you using plperl or pltcl?  The backend shouldn't go multithreaded,
but we've seen problems with those interpreters causing it to happen.
(I suppose other language interpreters like python might be risks as
well, but those two are the only ones trouble has been reported with.)
        regards, tom lane


Re: postmaster process and multithreading

From
andrew klassen
Date:
<div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div style="FONT-SIZE: 12pt;
FONT-FAMILY:times new roman, new york, times, serif">I am only using a "C" based client with libpq. But, I did not
explicitlyturn</div><div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">anything off
likeperl or tcl. Are these off by default? <br />Is there some way to check in the gdb or compile log? </div><div
style="FONT-SIZE:12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div><div style="FONT-SIZE: 12pt;
FONT-FAMILY:times new roman, new york, times, serif">thanks.<br /></div><div style="FONT-SIZE: 12pt; FONT-FAMILY: times
newroman, new york, times, serif">----- Original Message ----<br />From: Tom Lane <tgl@sss.pgh.pa.us><br />To:
andrewklassen <aptklassen@yahoo.com><br />Cc: pgsql-interfaces <pgsql-interfaces@postgresql.org><br />Sent:
Wednesday,November 28, 2007 5:08:12 PM<br />Subject: Re: [INTERFACES] postmaster process and multithreading<br /><br
/>andrewklassen <<a href="mailto:aptklassen@yahoo.com"
ymailto="mailto:aptklassen@yahoo.com">aptklassen@yahoo.com</a>>writes:<br />> The reason I am asking is because
sometimesthe postmaster<br />> will create a core dump and it will show two threads but the<br />> backtrace on
boththreads does not show any helpful information.<br /><br />Are you using plperl or pltcl?  The backend shouldn't go
multithreaded,<br/>but we've seen problems with those interpreters causing it to happen.<br />(I suppose other language
interpreterslike python might be risks as<br />well, but those two are the only ones trouble has been reported
with.)<br/><br />            regards, tom lane<br /></div><div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman,
newyork, times, serif"><br /></div></div><br /><hr size="1" />Get easy, one-click access to your favorites. <a
href="http://us.rd.yahoo.com/evt=51443/*http://www.yahoo.com/r/hs">Make Yahoo! your homepage.</a>