Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2OHH-0003u5-IK for pgsql-performance@arkaria.postgresql.org; Wed, 11 Oct 2017 21:10:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e2OHH-0008P0-4O for pgsql-performance@arkaria.postgresql.org; Wed, 11 Oct 2017 21:10:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e2OFU-0003y6-Ev for pgsql-performance@postgresql.org; Wed, 11 Oct 2017 21:09:04 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e2OFR-0007u8-A0 for pgsql-performance@postgresql.org; Wed, 11 Oct 2017 21:09:03 +0000 Received: by mail-wm0-x22d.google.com with SMTP id l68so8306593wmd.5 for ; Wed, 11 Oct 2017 14:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=XdPdHssYstG0roZ2cN6Beup478z1TuIjDGZ5x3+LmRY=; b=HoPn1yIyYqE1/gzJ/lGR0zvJbaXXKbnOmszRJLFDqFHMtO7LCpoOqr++vVp9hUTEqQ wZMtwyOFhU5F0wMmfqhIriYSgZRyE2vr/OMwjLz3XMiUg4GhQPT2irrNAY1xNUkixPlY o2uYD9Qsmy9YHMMYI8OsjdFiT9H9X7Q5qogBkltwFxaYCvdQlBeO4K6D0LfMPZodZPSL cOYZ1YiflnE9zAri+/QReOBG+oAETLBY6E/pw7hFk7SUHxR/P2CWTC//OMSBCUZ5qTcT BK4OgHAKu7MkP3/Xa6z2UAtG+RiwMpWngLnpHK5qmlNJzJUfb1lJUMRO3ZUgFSxJLZ9q r24w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=XdPdHssYstG0roZ2cN6Beup478z1TuIjDGZ5x3+LmRY=; b=FtAZ/gUgRASAo1Fep2505e4FGvgBtazKwJSH96ZxON1awvpHzfQm3qtYSa8x45RhuC LZv00161d92bB2OSqvumVD80yFDD+jNsvsHHcLl3GiHn5LXWreLTeGIlCsn1PSxkyksX vzixn/vSUqFHCl+MV19TD44fraU3+lh/RIpiK78+ZbBHJ8zVH1Jn9ncoR0klA8TSJOXB MgS0LqEP+gmnYSojmfpdO3KWZk2M9fhVp5z6/iTbzE5X6NBaBFGq4mRpVDqcCr3jrmmP adGdGVdoYhP3kvxGPvipGNY228FouYIAKtJ8n+YC3rur6RQ5FOY4HAbdMR4aX+rrWKZH +mZg== X-Gm-Message-State: AMCzsaV+alxTZw9wl02UXGsl0h3ci4g1fW99y2k0NsUEMBNKOPCi1r1t ljwuMXU8Yk4z85i6XWd4rbds/uWfBbCzNo2ZYhsee82sTLjATWUnGw2+lL3PD02HmFWSKBpnX57 7DinJ+C8L5ZNi5+DcCFPsvPZDrn4f7BPMOPu4ZVCgd1RgHeGDahPpxLAZCb3ibhLVnf5OKxVbQM p2yE3Dh7QT16xkyQ== X-Google-Smtp-Source: AOwi7QD2ccxB/yjBgJp+I8bhif+K0s+I9oHNCx7WY+cArjYVHa3Sg5ccacaIq0eNyfDCZI+NRDmJsQ== X-Received: by 10.28.218.209 with SMTP id r200mr131037wmg.97.1507756139018; Wed, 11 Oct 2017 14:08:59 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id b11sm29563147wrd.91.2017.10.11.14.08.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 14:08:58 -0700 (PDT) Subject: Re: blocking index creation To: Neto pr , Laurenz Albe , postgres performance list References: <1507729579.2627.13.camel@cybertec.at> From: Tomas Vondra Message-ID: Date: Wed, 11 Oct 2017 23:08:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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 On 10/11/2017 04:11 PM, Neto pr wrote: > > 2017-10-11 10:46 GMT-03:00 Laurenz Albe >: > > Neto pr wrote: > > When creating index on table of approximately 10GB of data, the DBMS hangs (I think), > > because even after waiting 10 hours there was no return of the command. > > It happened by creating Hash indexes and B + tree indexes. > > However, for some columns, it was successfully (L_RETURNFLAG, L_PARTKEY). > > > If someone has a hint how to speed up index creation so that it completes successfully. > > Look if CREATE INDEX is running or waiting for a lock (check the > "pg_locks" table, see if the backend consumes CPU time). > > > In this moment now, there is an index being created in the Lineitem > table (+ - 10 Gb), and apparently it is locked, since it started 7 hours > ago. > I've looked at the pg_locks table and look at the result, it's with > "ShareLock" lock mode. > Is this blocking correct? or should it be another type? > Yes, CREATE INDEX acquire SHARE lock, see https://www.postgresql.org/docs/9.1/static/explicit-locking.html > Before creating the index, should I set the type of transaction lock? What? Eeee? Not sure I understand. The command acquires all necessary locks automatically. > ------------------------------------------------------------------------------------------- > SELECT >       L.mode, c.relname, locktype,  l.GRANTED, l.transactionid, > virtualtransaction > FROM   pg_locks l, pg_class   c > where  c.oid = l.relation > > -------------- RESULT > -------------------------------------------------------------- > AccessShareLock pg_class_tblspc_relfilenode_index relation TRUE > (null) 3/71 > AccessShareLock pg_class_relname_nsp_index relation TRUE (null) 3/71 > AccessShareLock pg_class_oid_index relation TRUE (null) 3/71 > AccessShareLock pg_class relation TRUE (null) 3/71 > AccessShareLock pg_locks relation TRUE (null) 3/71 > ShareLock lineitem relation TRUE (null) 21/3769 > >   Well, we see something is holding a SHARE lock on the "lineitem" table, but we don't really know what the session is doing. There's a PID in the pg_locks table, you can use it to lookup the session in pg_stat_activity which includes the query (and also "state" column that will tell you if it's active or waiting for a lock. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance