Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDe3c-0007Wb-4t for pgsql-performance@arkaria.postgresql.org; Wed, 12 Feb 2014 17:57:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WDe3b-0001qq-Kq for pgsql-performance@arkaria.postgresql.org; Wed, 12 Feb 2014 17:57:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDe3a-0001qj-Bn for pgsql-performance@postgresql.org; Wed, 12 Feb 2014 17:57:10 +0000 Received: from mail-ea0-x231.google.com ([2a00:1450:4013:c01::231]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDe3S-0005nA-IG for pgsql-performance@postgresql.org; Wed, 12 Feb 2014 17:57:10 +0000 Received: by mail-ea0-f177.google.com with SMTP id m10so1972130eaj.8 for ; Wed, 12 Feb 2014 09:57:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:from:subject:date:to; bh=8hdE/QPZ65kw9VvMW4fn7nxLkSqzdNAT3idn9Z8ePCw=; b=Zqw96f7wmvxKKwZoayjQD/qSZJrY/HrJlk6P0P2zhPIFqW2WTsgXJcI1YU1QyGQHCv xrCMCIYgIE1gro3ieefFfTpPErzPF3NQYvvj8AV+BUqvg42a8tkLd40zF8TF4MJ3hZax RQrZjmjLv9lVkGqSQE9XSsLgb2Kglc9GUz6VcLh0nOHOVqIH0yN9Qp62TWuHDYX1Ogkh j4wzcURU2Aqz34mkt1AQlHgknJbeD0hGpyXfukVGDTT6TFpiDJG+B/MGRYe3yIc7IVjS Ogv0ryI8nVlSh24EhpQRr73ATZm+LFRVS94Wig5mxXpJVAV7A2fqA/Ca5q2btl8DbgId 6Y8g== X-Received: by 10.14.149.131 with SMTP id x3mr5457466eej.7.1392227821666; Wed, 12 Feb 2014 09:57:01 -0800 (PST) Received: from [10.44.42.97] (tmo-103-90.customers.d1-online.com. [80.187.103.90]) by mx.google.com with ESMTPSA id j42sm85458481eep.21.2014.02.12.09.56.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Feb 2014 09:57:00 -0800 (PST) References: <466D72D2-68EC-4FF4-93B8-43B687E7B705@simply.name> Mime-Version: 1.0 (1.0) In-Reply-To: Content-Type: multipart/alternative; boundary=Apple-Mail-8B41FF3C-8882-49FD-BFA5-7AF13BBA3E3A Content-Transfer-Encoding: 7bit Message-Id: Cc: "pgsql-performance@postgresql.org" X-Mailer: iPhone Mail (11B554a) From: Ilya Kosmodemiansky Subject: Re: Problem with ExclusiveLock on inserts Date: Wed, 12 Feb 2014 18:56:52 +0100 To: =?koi8-r?B?4s/Sz8TJziD3zMHEyc3J0g==?= 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 --Apple-Mail-8B41FF3C-8882-49FD-BFA5-7AF13BBA3E3A Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: quoted-printable My question was actually about barrier option, by default it is enabled on R= HEL6/ext4 and could cause serious bottleneck on io before disks are actually= involved. What says mount without arguments?=20 > On Feb 12, 2014, at 18:43, =E2=CF=D2=CF=C4=C9=CE =F7=CC=C1=C4=C9=CD=C9=D2 <= root@simply.name> wrote: >=20 > root@rpopdb01e ~ # fgrep data /etc/fstab > UUID=3Df815fd3f-e4e4-43a6-a6a1-bce1203db3e0 /var/lib/pgsql/9.3/data ext4 n= oatime,nodiratime 0 1 > root@rpopdb01e ~ # >=20 > According to iostat the disks are not the bottleneck. >=20 >> 12.02.2014, =D7 21:30, Ilya Kosmodemiansky =CE=C1=D0= =C9=D3=C1=CC(=C1): >>=20 >> Hi Vladimir, >>=20 >> Just in case: how is your ext4 mount?=20 >>=20 >> Best regards,=20 >> Ilya >>=20 >>> On Feb 12, 2014, at 17:59, =E2=CF=D2=CF=C4=C9=CE =F7=CC=C1=C4=C9=CD=C9=D2= wrote: >>>=20 >>> Hi all. >>>=20 >>> Today I have started getting errors like below in logs (seems that I hav= e not changed anything for last week). When it happens the db gets lots of c= onnections in state active, eats 100% cpu and clients get errors (due to tim= eout).=20 >>>=20 >>> 2014-02-12 15:44:24.562 MSK,"rpop","rpopdb_p6",30061,"localhost:58350",5= 2fb5e53.756d,1,"SELECT waiting",2014-02-12 15:43:15 MSK,143/264877,100285056= 6,LOG,00000,"process 30061 still waiting for ExclusiveLock on extension of r= elation 26118 of database 24590 after 1000.082 ms",,,,,"SQL statement ""inse= rt into rpop.rpop_imap_uidls (folder_id, uidl) values (i_folder_id, i_uidl)"= " >>>=20 >>> I have read several topics [1, 2, 3, 4] with similar problems but haven'= t find a good solution. Below is some more diagnostics. >>>=20 >>> I am running PostgreSQL 9.3.2 installed from RPM packages on RHEL 6.4. H= ost is running with the following CPU (32 cores) and memory: >>>=20 >>> root@rpopdb01e ~ # fgrep -m1 'model name' /proc/cpuinfo >>> model name : Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz >>> root@rpopdb01e ~ # free -m >>> total used free shared buffers cache= d >>> Mem: 129028 123558 5469 0 135 11950= 4 >>> -/+ buffers/cache: 3918 125110 >>> Swap: 16378 0 16378 >>> root@rpopdb01e ~ # >>>=20 >>> PGDATA lives on RAID6 array of 8 ssd-disks with ext4, iostat and atop sa= y the disks are really free. Right now PGDATA takes only 95G. >>> The settings changed in postgresql.conf are here [5]. >>>=20 >>> When it happens the last query from here [6] shows that almost all queri= es are waiting for ExclusiveLock, but they do a simple insert. >>>=20 >>> (extend,26647,26825,,,,,,,) | 5459 | ExclusiveLock | 1 | (ex= tend,26647,26825,,,,,,,) | 8053 | ExclusiveLock | 5459,8053 >>> (extend,26647,26828,,,,,,,) | 5567 | ExclusiveLock | 1 | (ex= tend,26647,26828,,,,,,,) | 5490 | ExclusiveLock | 5567,5490 >>> (extend,24584,25626,,,,,,,) | 5611 | ExclusiveLock | 1 | (ex= tend,24584,25626,,,,,,,) | 3963 | ExclusiveLock | 5611,3963 >>>=20 >>> I have several databases running on one host with one postmaster process= and ExclusiveLock is being waited by many oids. I suppose the only common t= hing for all of them is that they are bigger than others and they almost do n= ot get updates and deletes (only inserts and reads). Some more info about on= e of such tables is here [7]. >>>=20 >>> I have tried to look at the source code (src/backend/access/heap/hio.c) t= o understand when the exclusive lock can be taken, but I could only read com= ments :) I have also examined FSM for this tables and their indexes and foun= d that for most of them there are free pages but there are, for example, suc= h cases: >>>=20 >>> rpopdb_p0=3D# select count(*) from pg_freespace('rpop.rpop_uidl') where a= vail !=3D 0; >>> count >>> -------- >>> 115953 >>> (1 row) >>>=20 >>> rpopdb_p0=3D# select count(*) from pg_freespace('rpop.pk_rpop_uidl') whe= re avail !=3D 0; >>> count >>> ------- >>> 0 >>> (1 row) >>>=20 >>> rpopdb_p0=3D# \dS+ rpop.rpop_uidl >>> Table "rpop.rpop_uidl" >>> Column | Type | Modifiers | Storage | Stats target |= Description >>> --------+------------------------+-----------+----------+--------------+= ------------- >>> popid | bigint | not null | plain | |= >>> uidl | character varying(200) | not null | extended | |= >>> Indexes: >>> "pk_rpop_uidl" PRIMARY KEY, btree (popid, uidl) >>> Has OIDs: no >>>=20 >>> rpopdb_p0=3D# >>>=20 >>>=20 >>> My questions are: >>> 1. Do we consume 100% cpu (in system) trying to get page from FSM? Or do= es it happen during exclusive lock acquiring? How can I dig it? >>> 2. How much space do we extend to the relation when we get exclusive loc= k on it? >>> 3. Why extended page is not visible for other backends? >>> 4. Is there any possibility of situation where backend A got exclusive l= ock on some relation to extend it. Then OS CPU scheduler made a context swit= ch to backend B while backend B is waiting for exclusive lock on the same re= lation. And so on for many backends. >>> 5. (and the main question) what can I do to get rid of such situations? I= t is a production cluster and I do not have any ideas what to do with this s= ituation :( Any help would be really appropriate. >>>=20 >>> [1] http://www.postgresql.org/message-id/8bca3aa10906011613l8ac2423h8153= bbd2513dc159@mail.gmail.com >>> [2] http://pgsql.performance.narkive.com/IrkPbl3f/postgresql-9-2-3-perfo= rmance-problem-caused-exclusive-locks >>> [3] http://www.postgresql.org/message-id/50A2C93E.9070607@dalibo.com >>> [4] http://www.postgresql.org/message-id/CAL_0b1sypYeOyNkYNV95nNV2d+4jXT= ug3HkKF6FahfW7Gvgb_Q@mail.gmail.com >>> [5] http://pastebin.com/raw.php?i=3DBd40Vn6h >>> [6] http://wiki.postgresql.org/wiki/Lock_dependency_information >>> [7 http://pastebin.com/raw.php?i=3DeGrtG524] >>>=20 >>> -- >>> Vladimir >=20 >=20 > -- > Vladimir >=20 >=20 >=20 >=20 --Apple-Mail-8B41FF3C-8882-49FD-BFA5-7AF13BBA3E3A Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
My question was actually about barrier= option, by default it is enabled on RHEL6/ext4 and could cause serious bott= leneck on io before disks are actually involved. What says mount without arg= uments? 

On Feb 12, 2014, at 18:43, =D0=91=D0=BE=D1=80=D0= =BE=D0=B4=D0=B8=D0=BD =D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80 <<= a href=3D"mailto:root@simply.name">root@simply.name> wrote:

root@rpopdb01e ~ # fgrep data /etc/fsta= b
UUID=3Df815fd3f-e4e4-43a6-a6a1-bce1203db3e0 /var/lib/pgsql/9.3/d= ata ext4 noatime,nodiratime 0 1
root@rpopdb01e ~ #

<= /div>
According to iostat the disks are not the bottleneck.
12.02.2014, =D0=B2 21:30, Ilya Kosmodemiansky <hydrobiont@gmail.com> =D0=BD=D0=B0=D0=BF= =D0=B8=D1=81=D0=B0=D0=BB(=D0=B0):

Hi Vladimir,

=
Just in case: how is your ext4 mount? 

<= div>Best regards, 
Ilya

On Feb 12, 2014, at 17:= 59, =D0=91=D0=BE=D1=80=D0=BE=D0=B4=D0=B8=D0=BD =D0=92=D0=BB=D0=B0=D0=B4=D0=B8= =D0=BC=D0=B8=D1=80 <root@simply.name<= /a>> wrote:

Hi all.

<= div>Today I have started getting errors like below in logs (seems that I hav= e not changed anything for last week). When it happens the db gets lots of c= onnections in state active, eats 100% cpu and clients get errors (due to tim= eout). 

I am running PostgreSQL 9.3.2 installed from RPM packages= on RHEL 6.4. Host is running with the following CPU (32 cores) and memory:<= /div>

root@rpopdb01e ~ # fgrep -m1 'model name' /pro= c/cpuinfo
model name : Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz
root@rpopdb01e ~ # free -m
          &nb= sp;  total       used       free   &= nbsp; shared    buffers     cached
Mem:  =      129028     123558       5469 &= nbsp;        0        135   &nb= sp; 119504
-/+ buffers/cache:       3918   &nb= sp; 125110
Swap:        16378     &n= bsp;    0      16378
root@rpopdb01e ~ #

PGDATA lives on RAID6 array of 8 ssd-disks wit= h ext4, iostat and atop say the disks are really free. Right now PGDATA take= s only 95G.
The settings changed in postgresql.conf are here [= 5].

When it happens the last query from here [6] sh= ows that almost all queries are waiting for ExclusiveLock, but they do a= simple insert.

 (extend,26647,26825,,,,,= ,,) |        5459 | ExclusiveLock |     1 | (e= xtend,26647,26825,,,,,,,) | 8053 | ExclusiveLock | 5459,8053
 = ;(extend,26647,26828,,,,,,,) |        5567 | ExclusiveLo= ck |     1 | (extend,26647,26828,,,,,,,) | 5490 | ExclusiveLock | 5= 567,5490
 (extend,24584,25626,,,,,,,) |       &= nbsp;5611 | ExclusiveLock |     1 | (extend,24584,25626,,,,,,,) | 3= 963 | ExclusiveLock | 5611,3963

I have severa= l databases running on one host with one postmaster process and Exclusi= veLock is being waited by many oids. I suppose the only common thing for all= of them is that they are bigger than others and they almost do not get upda= tes and deletes (only inserts and reads). Some more info about one of such t= ables is here [7].

I have tried to look at the sour= ce code (src/backend/access/heap/hio.c) to understand when the exclusive loc= k can be taken, but I could only read comments :) I have also examined FSM f= or this tables and their indexes and found that for most of them there are f= ree pages but there are, for example, such cases:

<= div>rpopdb_p0=3D# select count(*) from pg_freespace('rpop.rpop_uidl') where a= vail !=3D 0;
 count
--------
 115953=
(1 row)

rpopdb_p0=3D# select count(*) fr= om pg_freespace('rpop.pk_rpop_uidl') where avail !=3D 0;
 cou= nt
-------
     0
(1 row)
=

rpopdb_p0=3D# \dS+ rpop.rpop_uidl
  &= nbsp;                     &= nbsp;      Table "rpop.rpop_uidl"
 Column | &n= bsp;        Type          | Mod= ifiers | Storage  | Stats target | Description
--------+-----= -------------------+-----------+----------+--------------+-------------
 popid  | bigint             &= nbsp;   | not null  | plain    |       &n= bsp;      |
 uidl   | character varying(2= 00) | not null  | extended |             &= nbsp;|
Indexes:
    "pk_rpop_uidl" PRIMARY KEY= , btree (popid, uidl)
Has OIDs: no

rpopdb= _p0=3D#


My questions are= :
1. Do we consume 100% cpu (in system) trying to get page from FS= M? Or does it happen during exclusive lock acquiring? How can I dig it?
2. How much space do we extend to the relation when we get exclusive l= ock on it?
3. Why extended page is not visible for other backends?=
4. Is there any possibility of situation where backend A got excl= usive lock on some relation to extend it. Then OS CPU scheduler made a conte= xt switch to backend B while backend B is waiting for exclusive lock on the s= ame relation. And so on for many backends.
5. (and the main questi= on) what can I do to get rid of such situations? It is a production cluster a= nd I do not have any ideas what to do with this situation :( Any help would b= e really appropriate.

[3] h= ttp://www.postgresql.org/message-id/50A2C93E.9070607@dalibo.com
[4] http://www.postgresql.org= /message-id/CAL_0b1sypYeOyNkYNV95nNV2d+4jXTug3HkKF6FahfW7Gvgb_Q@mail.gmail.c= om
--
Vladimir






--
Vladi= mir




= --Apple-Mail-8B41FF3C-8882-49FD-BFA5-7AF13BBA3E3A--