Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TTkri-0002dU-C9 for pgsql-admin@postgresql.org; Thu, 01 Nov 2012 02:50:42 +0000 Received: from mail-da0-f46.google.com ([209.85.210.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TTkre-0000sN-OO for pgsql-admin@postgresql.org; Thu, 01 Nov 2012 02:50:40 +0000 Received: by mail-da0-f46.google.com with SMTP id n41so937608dak.19 for ; Wed, 31 Oct 2012 19:50:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=iVEjm4mQHiDwznWsYUYSFl+k6xIvfK1Cpzsk2OhrXwE=; b=mFVEGLIYAm3uyEgk/Md3ScLv9HMZB+lCbKYClLFdTEpx1RquKIvx5oQ1gFMVOq6e0m tyd5wHvUHnJoupa3BCfzFaD9dgI0OPHD4tpBcAOxGXDYjUZHnj327TpnangJgtO0VO2n lBf8hHJugY9xT+2hEY6OU9iFH1k/D/BjR9Tv4Rf0udEmtX+yqd9qbgNeNhQnregSyOqV NgdlCLFTcddh+NdCzyvZuUSTXvQOKm2laNcIzo6Rc6T7OXeZz9ye7L3p26Kml5aWpihq 5cEcNdL4dhM19P4CS6CCcWXB8My74YDYpenrPgUVe/0UIZzvhthx85rQWHAp6hIrg9tO ya6w== Received: by 10.66.73.225 with SMTP id o1mr56052916pav.70.1351738236581; Wed, 31 Oct 2012 19:50:36 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id c7sm3159080pay.10.2012.10.31.19.50.33 (version=SSLv3 cipher=OTHER); Wed, 31 Oct 2012 19:50:35 -0700 (PDT) Message-ID: <5091E377.2030505@ringerc.id.au> Date: Thu, 01 Nov 2012 10:50:31 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1 MIME-Version: 1.0 To: Raj Gandhi CC: pgsql-admin@postgresql.org Subject: Re: Detecting DB corruption References: In-Reply-To: X-Enigmail-Version: 1.4.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQl/CWDVe086/psJ7+JKHiPrtCs3zliz5Xdl7rer5WnUwtMpAf6/OmM52oi9qX5DDhSBtIbE X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201211/2 X-Sequence-Number: 40247 On 11/01/2012 08:01 AM, Raj Gandhi wrote: > > I'm looking for ways to detect DB index and any other type of corruption > in DB. It looks like there is no tool to verify if Postgres DB is > corrupted or not. There is no database verifier tool. One would be quite nice to have for testing and development purposes, though I question whether corruption should be a concern in production. If you face the realistic risk of database corruption, you need to urgently address the problems in your setup that make that possible. I wrote a bit about that a while ago: http://blog.ringerc.id.au/2012/10/avoiding-postgresql-database-corruption.html Seriously, if you're facing DB corruption then something is already horribly wrong with your setup. PostgreSQL isn't like MySQL with MyISAM; corruption is not routine and part of life. It's a sign of a very bad problem, one you should diagnose and fix not paper over. Do you expect ext3 file system corruption routinely? No? PostgreSQL should be the same. > I would like to detect some of the following DB corruptions: > - corruption in DB indexes A query that scans the whole index (say, to sort on it) should generally find damaged pages in indexes. "Corruption" can cover many different things, though, and some damage would not be detected by simply using the index. > - detect duplicate primary keys in a table (noticed in couple of > instances where duplciates keys were found becuase of corrupted indexes) A REINDEX will find that. Alternately, you might be able to formulate queries that ignore the indexes and do duplicate searches by grouping by the primary key with `enable_indexscan = off`, `enable_indexonlyscan = off`, etc etc. > - any page or block is corrupted I'd want to use the `pageinspect' extension to scan the table manually. Create some artificially damaged blocks in a just-for-testing table and make sure that doing so actually finds them. > Using Postgres 8.3.18 on Linux. Database has around 100 tables with > average rows in a table are 500. Well, you're on an old version, but not one with any known serious issues AFAIK. -- Craig Ringer