Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ye5sC-0000Sd-1m for pgsql-admin@arkaria.postgresql.org; Fri, 03 Apr 2015 17:59:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Ye5sB-0005XE-Bs for pgsql-admin@arkaria.postgresql.org; Fri, 03 Apr 2015 17:59:15 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Ye5s9-0005X7-GJ for pgsql-admin@postgresql.org; Fri, 03 Apr 2015 17:59:14 +0000 Received: from nm24-vm5.bullet.mail.ne1.yahoo.com ([98.138.91.246]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Ye5s4-0007QE-MT for pgsql-admin@postgresql.org; Fri, 03 Apr 2015 17:59:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s2048; t=1428083947; bh=cTkNeIV+NeQHHKQn5iK3dn8p+wix8T2LCNvOT5IAM4k=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=pIdeQa+6waHtuNaN4bP3alaWZPSf96aOJGh9lS5dKrxQe7rUdLAr1dsE2iqvd6nX6tKrP/BvNC+JTwiYbzEKD7dKx85zSE6rZTDYdLpWKmXy6tE4EswtBKQCgD54stIZy2wRlUSzbvFPZI2nkRC9XK7BWfQoofZfO5QZazckMhQRlHorXe8vfnV/j8RZu92UBKtDPytIa+XrGSTGddIU2ZaXZrRVz9yMW83/CBD7FOjltijf/XHTMuTi2TZzTPJudpz8QVBIFP5h9WjXxYCPUT3vXA8svWoQG6U6K13ZVYck+TrOylXPvmD5oVtlb6d4p9x9wrOtosb47JgIwKcKag== Received: from [98.138.101.129] by nm24.bullet.mail.ne1.yahoo.com with NNFMP; 03 Apr 2015 17:59:07 -0000 Received: from [98.138.89.160] by tm17.bullet.mail.ne1.yahoo.com with NNFMP; 03 Apr 2015 17:59:07 -0000 Received: from [127.0.0.1] by omp1016.mail.ne1.yahoo.com with NNFMP; 03 Apr 2015 17:59:07 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 5603.50510.bm@omp1016.mail.ne1.yahoo.com X-YMail-OSG: C.nHBcAVM1ncMgQKgQYr6YwHz0bVV6W.FauGW1hbuFOq483LWRKyWrrE2WtKrT2 scA30Hr0Avl1zJS9EN9Ve9vPpAOGxXj4wcWR9oGIR65QCCERR_d4tuEcTfrSIP_rNSOO6vwcK2lp MzdSXI6s.MdG8diVvO1ekenH17OteBbvKnW2NpKp_5n_TYE_lCkLHDJMvnfPCdp5uyVy_tdXj5LO vUz8ykqQspoKGSJMP9g0m2hEK0q152R7z.3WOsFA773eYcASAZj09E_vTGHZcuFaXQEOgYqDl.dv WCvChN5vwcYIdUu2AZpJjhGPVdt91EU9rD7LDLjO3677wIS9gCGKiD6vOm6UAkYOv29ooc98qvBX MpqOB6Rbr1iZIJCraNs1_LFYgTFc2BtzlPdWDwyZzIsYC_subzoJWL3OMRX.Zx0WYdHNvt.uor1w wz1wfW1EnqIlKAT116lAyHdl8IINGZfgqXMNKDiI_8otltzVDWo_un1xhCPUkAaGhxq2qRpGYghc sv1HAETxqJQgFpzELlGrhp0muH1nW2udDLi0mrah7aiD0FEr6VM3b6ThdEHivT8x6gsQ2mUiZiZG zIddORMGstmdfbDfadbz7XHq3icMfpq1sT8.MfXdWxG7mYGpjGDvCkTXwk38dcqYi07sjlkwKmNx FXMmopqqsjWmxV.I40lX.0V.AbcNgjzKzVQ3RzdgcpitujhXVMHZwiYipv3eYo3LftnOSbJfrg2h JW0D9N.INwpYcMKc- Received: by 98.138.105.218; Fri, 03 Apr 2015 17:59:06 +0000 Date: Fri, 3 Apr 2015 17:59:05 +0000 (UTC) From: Kevin Grittner Reply-To: Kevin Grittner To: John Scalia , "pgsql-admin@postgresql.org" Message-ID: <1905275951.4626814.1428083945794.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <551EB8D4.7050406@gmail.com> References: <551EB8D4.7050406@gmail.com> Subject: Re: vacuum and table locking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Length: 1696 X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org John Scalia wrote: > VACUUM (VACUUM ANALYZE) - shouldn't need to lock the table(?). > I'm looking at the Douglas' book "PostgreSQL" on page 804 where > it claims the operation does not require exclusive access. Without the FULL keyword, it only requires a SHARE UPDATE EXCLUSIVE lock, which does not conflict with ordinary DML. http://www.postgresql.org/docs/9.2/interactive/explicit-locking.html#LOCKING-TABLES > VACUUM FULL (VACUUM FULL ANALYZE) - will need to lock the table, Yes, in this case with an ACCESS EXCLUSIVE lock, which conflicts with all other locks. > but I'm thinking this may only take a couple of milliseconds as I > think this builds a temporary table from the one > being vacuumed and then when complete, drops the old table and > renames the temporary. So the lock should only be during this > move, or does it lock the table for the entirety? If it only locked while after the data was scanned, how could it deal with DML affecting portions it had already scanned? If that were the only problem it could take a SHARE lock, which would allow concurrent reads, but then we would have the issue of escalating the lock to swap in the new heap and indexes -- and lock escalation carries a risk of deadlock. > And how does it then resolve say another deletion in the table > that occurs while the VACUUM is in operation? A VACUUM FULL could not cope with that, which is why it needs the ACCESS EXCLUSIVE lock. A non-FULL VACUUM is OK because of visibility checking and/or (depending on relation type) a special form of page locking used just for cleanups. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin