Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VBxIc-00076E-DU for pgsql-performance@arkaria.postgresql.org; Wed, 21 Aug 2013 01:33:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VBxIb-00021I-RV for pgsql-performance@arkaria.postgresql.org; Wed, 21 Aug 2013 01:33:25 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VBxIa-0001zn-B1 for pgsql-performance@postgresql.org; Wed, 21 Aug 2013 01:33:24 +0000 Received: from mail-pa0-x22d.google.com ([2607:f8b0:400e:c03::22d]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VBxIX-0003xG-2W for pgsql-performance@postgresql.org; Wed, 21 Aug 2013 01:33:23 +0000 Received: by mail-pa0-f45.google.com with SMTP id bg4so175389pad.32 for ; Tue, 20 Aug 2013 18:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=NvAtKr7sAAoB+4w2XbBom18whzdl+Js4AjWAADwEhJY=; b=GN79fNLqmY+wVHZHDwyY4Apo7wDF9ApDDqmyIzNKgOEoeWBHKNKo1CvYtCgxSDzJiu DAqDzG8S/1Ss3NSI62V6D9lokTv4ErH+1PxjlwVjmqkOUVPcHYNUDDgMJf3NoJKo1i1E nLSP5AVOYJPLMAih+2w191Ux0cDT97iuZcYI/cbOfT1f7tfxvChPZ39+Z7LRIxaF14ii +Nv/itbl52zm+M+Etl+a0Qx3wxE+BIWQgqh6cS+d4Iuh8exAZY3Ny/MEaDWXbDdLbl0H 188YMSERtwzHeRbdDA6S9+h/+6nJOcqKA5JoXBB8B2Zf6PqxqkmLop6Cs1PC/bEKDJ2b 8JVw== X-Received: by 10.66.165.106 with SMTP id yx10mr6667270pab.159.1377048799562; Tue, 20 Aug 2013 18:33:19 -0700 (PDT) Received: from [192.168.1.15] ([116.226.80.181]) by mx.google.com with ESMTPSA id ar5sm4870092pbc.40.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Aug 2013 18:33:18 -0700 (PDT) Message-ID: <521418DA.6020608@gmail.com> Date: Wed, 21 Aug 2013 09:33:14 +0800 From: Rural Hunter User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Jeff Janes CC: "pgsql-performance@postgresql.org" Subject: Re: How to investiage slow insert problem References: <5212CA07.6020509@gmail.com> <5212FEEA.4090900@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi Jeff, Thanks a lot for such a detailed guide! 于 2013/8/21 8:24, Jeff Janes 写道: > > OK, that certainly does sound like network problems and not disk > contention. But what I don't see is why it would be listed as > "active" in pg_stat_activity. If it is blocked on a network > connection, I would think it would show 'idle'. > > strace and gdb are aggressive forms of monitoring, so you should talk > to your sys admins before using them (if your organization has that > type of segregation of duties) or read their documentation. > > It is best to run them on a test system if you can get the problem to > occur there. If you can't, then I would be willing to run them > against a hung backend on a production system, but I might be more > adventurous than most. > > I have occasionally seen strace cause the straced program to > seg-fault, but I've only seen this with GUI programs and never with > postgresql. > > In theory attaching gdb could make a backend pause while holding a > spinlock, and if left that way for long enough could cause a > postgresql-wide panic over a stuck spinlock. But I've never seen this > happen without intentionally causing. If the backend you attach is > truly hung and hasn't already causes a panic, then it almost surely > can't be happen, but just to be sure you should quit gdb as soon as > possible so that the backend can continue unimpeded. > > Anyway, both are fairly easy to run once you find the pid of one of a > stuck backend (either using ps, or using pg_stat_activity). Then you > give the pid to the debugging program with -p option. > > You probably have to run as the postgres user, or you won't have > permissions to attach to the backend. > > With strace, once you attach you will see a stream of system calls go > to your screen, until you hit ctrl-C to detach. But if the backend is > hung on a network connection, there should really only be one system > call, and then it just wait until you detach or the network connection > times out, like this: > > $ strace -p 21116 > Process 21116 attached - interrupt to quit > recvfrom(9, > > So it is waiting on a recvfrom call, and that call never returns until > I got sick of waiting and hit ctrl-C. Not very interesting, but it > does show it is indeed stuck on the network > > for gdb, it is similar to invoke: > > $ gdb -p 21116 > > and it then produces several screenfuls of diagnostic gibberish and > gives you an interactive command-line environment. Once attached, you > want to get a backtrace ("bt", return), and then quit promptly ("q", > return, "y"). > > That produces something like this: > > Loaded symbols for /lib64/libnss_files.so.2 > 0x00000032a80e9672 in __libc_recv (fd=, > buf=0xb33f60, n=8192, flags=0) at > ../sysdeps/unix/sysv/linux/x86_64/recv.c:30 > 30 return INLINE_SYSCALL (recvfrom, 6, fd, buf, n, flags, > NULL, NULL); > (gdb) bt > #0 0x00000032a80e9672 in __libc_recv (fd=, > buf=0xb33f60, n=8192, flags=0) at > ../sysdeps/unix/sysv/linux/x86_64/recv.c:30 > #1 0x00000000005a4846 in secure_read (port=0x22f1190, ptr=0xb33f60, > len=8192) at be-secure.c:304 > #2 0x00000000005ae33b in pq_recvbuf () at pqcomm.c:824 > #3 0x00000000005ae73b in pq_getbyte () at pqcomm.c:865 > #4 0x0000000000651c11 in SocketBackend (argc=, > argv=, dbname=0x22d2a28 "jjanes", username= optimized out>) > at postgres.c:342 > #5 ReadCommand (argc=, argv= out>, dbname=0x22d2a28 "jjanes", username=) at > postgres.c:490 > #6 PostgresMain (argc=, argv= out>, dbname=0x22d2a28 "jjanes", username=) at > postgres.c:3923 > #7 0x000000000060e861 in BackendRun () at postmaster.c:3614 > #8 BackendStartup () at postmaster.c:3304 > #9 ServerLoop () at postmaster.c:1367 > #10 0x00000000006113b1 in PostmasterMain (argc=, > argv=) at postmaster.c:1127 > #11 0x00000000005b0440 in main (argc=3, argv=0x22d1cb0) at main.c:199 > (gdb) q > A debugging session is active. > > Inferior 1 [process 21116] will be detached. > > Quit anyway? (y or n) y > Detaching from program: /usr/local/pgsql9_2/bin/postgres, process 21116 > > Cheers, > > Jeff -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance