Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxYM0-0003Eu-Lq for pgsql-general@arkaria.postgresql.org; Wed, 05 Sep 2018 14:00:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fxYLy-0007K6-Px for pgsql-general@arkaria.postgresql.org; Wed, 05 Sep 2018 14:00:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxYLx-0007J2-3E for pgsql-general@lists.postgresql.org; Wed, 05 Sep 2018 14:00:18 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxYLo-0003ak-Ec for pgsql-general@lists.postgresql.org; Wed, 05 Sep 2018 14:00:15 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 1B5F621FC2; Wed, 5 Sep 2018 10:00:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 05 Sep 2018 10:00:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=ZksfFfKf2/AsnVwnDPn1pDBjgYJuL 8F9D2BS9g58iF0=; b=hnPtRX5nsYxlnR1nATx5L55/6H8wQ3nJxHDvjb4Pc6eNy V9ZLTjP73B7yXaf99dqMmBrzVEOdZ/ZMncfttVyX5nhUYrdRs5VTQD9i6VJvUdbU 35SO5ESUFchN+Di1YuOmi2HdbDE+QWU7SLEKKJEcI3zIqwsmmqTFviHrU84CTytk s+dABEiKxGtQe/c/E0I4RMBP9mGKUzseQxQWjtDDw/Oemh11nd7ark8x2GZ3uK/j 7DRd12oqqAODn1xl8StOQatY7q+69KdtLoeYCto4NHJ0hb3pNLWWKdMD+i/ZtYwN 0oiguY4n6u+Gk98OaI5aOZ12gncttRJ0jExdkuszg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=ZksfFf Kf2/AsnVwnDPn1pDBjgYJuL8F9D2BS9g58iF0=; b=wTtLC8sBWhXYFuQJPe7Mtf ZBqG0mheJKB2UFaoMTEQRJG6/fKA170sW37I0LNAs4pGUnGbo58Ru2p7WYNU7yAS ips91Q2E7pzJnraHT/CQuuE8wXPc0Keb9xlbZ9EdGCd5oM9elDNxO9O1XuOaaU2I C12U6ECLRCMNm0uzrt8x8fmyZAHoqFutZFSvwy1yz9o20rRO2gXKCrQbs09N9fCE 9yqjDjDsO9JHSTSSh7SLr6Ce1lwv73j2m0aHQsmjsGxub5Ns+Q0jK3fclMXDDMhc zR3LRaMNB1ta9Qi+J0IhOd9Enb9JPvwhQ5oBILp8rNTBhG4UJfUQQ+AA8ApSX4Tg == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id F3F4BE47C2; Wed, 5 Sep 2018 10:00:05 -0400 (EDT) Subject: Re: unaccent(text) fails depending on search_path (WAS: pg_upgrade fails saying function unaccent(text) doesn't exist) To: Gunnlaugur Thor Briem Cc: Bruce Momjian , pgsql-general@lists.postgresql.org References: <20180829190635.GD25450@momjian.us> <6c73c320-95b7-c259-e309-c46300557852@aklaver.com> <6e023cde-943a-5cea-8626-f1e9b29695df@aklaver.com> From: Adrian Klaver Message-ID: <7d7fe1f7-95bc-3f5a-2dc7-18db34499773@aklaver.com> Date: Wed, 5 Sep 2018 07:00:03 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 09/05/2018 01:49 AM, Gunnlaugur Thor Briem wrote: > OK, I found the cause of the unaccent dictionary problem, and a workaround. > > It's not the vacuumdb version, not the unaccent version, and it's not > even a pg_upgrade problem: I get this error also with PG 9.4.18 running > on the old cluster, with both the 10.5 vacuumdb and the 9.4.18 vacuumdb, > and I get the same error in both. > > And it's not strictly a vacuumdb problem, though vacuumdb triggers it. > > Here's a very minimal test case, unrelated to my DB, that you ought to > be able to reproduce: > > SET search_path = "$user"; SELECT public.unaccent('fóö'); > SET > ERROR:  text search dictionary "unaccent" does not exist > > and here's a workaround: > > SET search_path = "$user"; SELECT public.unaccent(tsdict.oid, 'fóö') > FROM pg_catalog.pg_ts_dict tsdict WHERE dictname='unaccent'; > SET >  unaccent > ---------- >  foo > (1 row) > > The workaround avoids the OID lookup of the dictionary ... that lookup > (in the single-argument unaccent function) is done by unqualified name: > > https://github.com/postgres/postgres/blob/fb8697b31aaeebe6170c572739867dcaa01053c6/contrib/unaccent/unaccent.c#L377 > >         dictOid = > get_ts_dict_oid(stringToQualifiedNameList("unaccent"), false); > > and that fails if the search path doesn't include public. > > So it is indeed triggered by the security changes that Bruce mentioned; > those were backported into 9.4.17: > https://www.postgresql.org/docs/9.4/static/release-9-4-17.html ... and > so got pulled in by my Macports upgrades. So nothing to do with pg_upgrade. > > So the workaround for my vacuumdb/function-index problem is to give > unaccent the OID of the text search dictionary, so that the search path > isn't in play: > > CREATE OR REPLACE FUNCTION public.semantic_normalize(title text) > RETURNS text >  LANGUAGE sql >  IMMUTABLE STRICT > AS $function$ >   SELECT lower(public.unaccent(16603, btrim(regexp_replace($1, '\s+', ' > ', 'g'), ' "'))) > $function$; > > and that makes vacuumdb -z work in both 9.4.18 and 10.5, and makes > ./analyze_new_cluster.sh complete without problems. Nice investigation. Working off the above, I offer a suggestion: SET search_path = "$user"; SELECT public.unaccent('unaccent', 'fóö'); SET ERROR: text search dictionary "unaccent" does not exist LINE 1: SELECT public.unaccent('unaccent', 'fóö'); SET search_path = "$user"; SELECT public.unaccent('public.unaccent', 'fóö'); SET unaccent ---------- foo That eliminates hard wiring the OID. > > The proper fix is, I suppose, to make the single-argument unaccent > function explicitly look up the dictionary in the same schema as the > function itself is in. > > Cheers, > Gulli > -- Adrian Klaver adrian.klaver@aklaver.com