Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XQHag-0004jm-RM for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Sep 2014 15:07:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XQHaf-0003nI-Hp for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Sep 2014 15:07:49 +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 1XQHad-0003n9-Aj for pgsql-bugs@postgresql.org; Sat, 06 Sep 2014 15:07:47 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XQHaa-0008KH-9g for pgsql-bugs@postgresql.org; Sat, 06 Sep 2014 15:07:45 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1XQHaZ-0005v0-9l; Sat, 06 Sep 2014 11:07:43 -0400 Date: Sat, 6 Sep 2014 11:07:43 -0400 From: Bruce Momjian To: David G Johnston Cc: pgsql-bugs@postgresql.org Subject: Re: Re: BUG #10329: Could not read block 0 in file "base/56100265/57047884": read only 0 of 8192 bytes Message-ID: <20140906150743.GC20146@momjian.us> References: <26235.1400166587@sss.pgh.pa.us> <4EE3A338-8C14-4E1B-9F2B-479354765138@wingo.ch> <20140515190235.GH25053@momjian.us> <31390.1400180834@sss.pgh.pa.us> <4FB93C6A-2790-4167-931A-E53E6694F73E@wingo.ch> <31813.1400181933@sss.pgh.pa.us> <1361.1400247902@sss.pgh.pa.us> <20140516144825.GL25053@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="JP+T4n/bALQSJXh8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -3.6 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --JP+T4n/bALQSJXh8 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Fri, May 16, 2014 at 08:27:33AM -0700, David G Johnston wrote: > Well, at this point we are decade into having crash-unsafe hash indexes, > and rather than getting better, the issue has gotten worse with > streaming replication.  If we can't find the best way to warn people, > let's find _a_ way, at least. > > I feel we are waiting for the calvary to come over the hill (and fix > hash indexes), except the calvary never arrives.  At some point we have > to take ownership of the situation we are in and actively do something. > > If someone today tried to add a crash-unsafe, replication-impotent > index, it would never be accepted, but because hash indexes came from > Berkeley, we go with a warning in the CREATE INDEX manual page and do > nothing more.  I can't think of any other foot-gun feature that is > allowed to remain with so little user warning. > > Unless there is a convincing argument to be made why doing it at CREATE INDEX > is FRIGGIN' EVIL then who really cares if its not perfect. > > NOTICE: This index IS NOT WAL LOGGED and cannot be used on SLAVE servers or > AFTER RECOVERY.  See Documentation for Details! > > The goal should be to communicate FUD to the uninformed. > > I'm all for additional and improved warnings in other places but this one at > least seems to have the benefit of being relatively simple to implement and > non-obnoxious since it only is issued once per index creation. > > As devil's advocate it isn't like anyone is likely to intentionally use hash > indexes without reading the documentation first - if only to know they exist, > how they work, and what syntax to use.  If an application is installing such > indexes for the user then a warning at CREATE INDEX is only a little better > than a warning in the documentation - though both are likely to never be seen. >   > > But that argument doesn't hold any sway for me. If someone knows they are using > a hash index intentionally then the notice/warning will be understood and > ignored while if someone is seeing the notice/warning and are not aware of the > limitations of hash indexes - like the OP - this live/logged notice will > hopefully cause them to become better informed and able to evaluate their > specific situation.  If the application doesn't point out it is using hash > indexes then the typical user will not be checking PostgreSQL documentation for > the same; but just maybe the notice that is raised will end up visible to the > end-user or cause the application developers to further re-examine their usage > and/or documentation of hash indexes. Here is a patch which implements the warning during CREATE INDEX ... HASH. If WAL-logging of hash indexes is ever implemented, we can remove this warning. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --JP+T4n/bALQSJXh8 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="hash.diff" diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c new file mode 100644 index fdfa6ca..4f31678 *** a/src/backend/commands/indexcmds.c --- b/src/backend/commands/indexcmds.c *************** DefineIndex(Oid relationId, *** 489,494 **** --- 489,498 ---- accessMethodId = HeapTupleGetOid(tuple); accessMethodForm = (Form_pg_am) GETSTRUCT(tuple); + if (strcmp(accessMethodName, "hash") == 0) + ereport(WARNING, + (errmsg("hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves"))); + if (stmt->unique && !accessMethodForm->amcanunique) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out new file mode 100644 index f6f5516..7a0185a *** a/src/test/regress/expected/create_index.out --- b/src/test/regress/expected/create_index.out *************** DROP TABLE array_gin_test; *** 2238,2246 **** --- 2238,2250 ---- -- HASH -- CREATE INDEX hash_i4_index ON hash_i4_heap USING hash (random int4_ops); + WARNING: hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves CREATE INDEX hash_name_index ON hash_name_heap USING hash (random name_ops); + WARNING: hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves CREATE INDEX hash_txt_index ON hash_txt_heap USING hash (random text_ops); + WARNING: hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves CREATE INDEX hash_f8_index ON hash_f8_heap USING hash (random float8_ops); + WARNING: hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves -- CREATE INDEX hash_ovfl_index ON hash_ovfl_heap USING hash (x int4_ops); -- -- Test functional index diff --git a/src/test/regress/expected/enum.out b/src/test/regress/expected/enum.out new file mode 100644 index 3682642..774f6fc *** a/src/test/regress/expected/enum.out --- b/src/test/regress/expected/enum.out *************** DROP INDEX enumtest_btree; *** 383,388 **** --- 383,389 ---- -- Hash index / opclass with the = operator -- CREATE INDEX enumtest_hash ON enumtest USING hash (col); + WARNING: hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves SELECT * FROM enumtest WHERE col = 'orange'; col -------- diff --git a/src/test/regress/expected/macaddr.out b/src/test/regress/expected/macaddr.out new file mode 100644 index 50d0369..0657df1 *** a/src/test/regress/expected/macaddr.out --- b/src/test/regress/expected/macaddr.out *************** SELECT * FROM macaddr_data; *** 39,44 **** --- 39,45 ---- CREATE INDEX macaddr_data_btree ON macaddr_data USING btree (b); CREATE INDEX macaddr_data_hash ON macaddr_data USING hash (b); + WARNING: hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves SELECT a, b, trunc(b) FROM macaddr_data ORDER BY 2, 1; a | b | trunc ----+-------------------+------------------- diff --git a/src/test/regress/expected/replica_identity.out b/src/test/regress/expected/replica_identity.out new file mode 100644 index 96dc98b..62c1f95 *** a/src/test/regress/expected/replica_identity.out --- b/src/test/regress/expected/replica_identity.out *************** CREATE INDEX test_replica_identity_keyab *** 11,16 **** --- 11,17 ---- CREATE UNIQUE INDEX test_replica_identity_keyab_key ON test_replica_identity (keya, keyb); CREATE UNIQUE INDEX test_replica_identity_nonkey ON test_replica_identity (keya, nonkey); CREATE INDEX test_replica_identity_hash ON test_replica_identity USING hash (nonkey); + WARNING: hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves CREATE UNIQUE INDEX test_replica_identity_expr ON test_replica_identity (keya, keyb, (3)); CREATE UNIQUE INDEX test_replica_identity_partial ON test_replica_identity (keya, keyb) WHERE keyb != '3'; -- default is 'd'/DEFAULT for user created tables diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out new file mode 100644 index d907519..e388ca2 *** a/src/test/regress/expected/uuid.out --- b/src/test/regress/expected/uuid.out *************** SELECT COUNT(*) FROM guid1 WHERE guid_fi *** 114,119 **** --- 114,120 ---- -- btree and hash index creation test CREATE INDEX guid1_btree ON guid1 USING BTREE (guid_field); CREATE INDEX guid1_hash ON guid1 USING HASH (guid_field); + WARNING: hash indexes are not WAL-logged so they are not crash-safe and cannot be used on streaming slaves -- unique index test CREATE UNIQUE INDEX guid1_unique_BTREE ON guid1 USING BTREE (guid_field); -- should fail --JP+T4n/bALQSJXh8 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --JP+T4n/bALQSJXh8--