如何向非超级用户提供Postgres扩展

Pau*_*lor 8 postgresql psql

我安装了Postgres扩展(unaccent)

sudo su posgres
psql create extension unaccent
Run Code Online (Sandbox Code Playgroud)

现在我可以在sql中使用unacccent,前提是我是Postgres用户.

如何向所有/另一个用户提供Postgres扩展

(我在Ubuntu上使用apt-install安装Postgres 9.3.5)

jthinksearch=# \dx;
                         List of installed extensions
   Name   | Version |   Schema   |                 Description
----------+---------+------------+---------------------------------------------
 plpgsql  | 1.0     | pg_catalog | PL/pgSQL procedural language
 unaccent | 1.0     | public     | text search dictionary that removes accents
(2 rows)

jthinksearch=#


jthinksearch=> \du;
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 ubuntu    |                                                | {}
Run Code Online (Sandbox Code Playgroud)

postgres @ ip-172-31-39-147:/ home/ubuntu/code/jthinksearch/reports/src/main/sql $ exit ubuntu @ ip-172-31-39-147:〜/ code/jthinksearch/reports/src/main/sql $ psql jthinksearch psql(9.3.5)输入"help"获取帮助.

我给了用户超级用户角色,但没有帮助,然后按照建议将模式名称放入,这对错误消息有影响,但仍然没有工作

jthinksearch=# \du;
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 ubuntu    | Superuser                                      | {}

jthinksearch=# select unaccent(name) from musicbrainz.artist where id=195660;
ERROR:  function unaccent(character varying) does not exist
LINE 1: select unaccent(name) from musicbrainz.artist where id=19566...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
jthinksearch=# ^C
jthinksearch=# select public.unaccent(name) from musicbrainz.artist where id=195660;
ERROR:  text search dictionary "unaccent" does not exist
jthinksearch=#
Run Code Online (Sandbox Code Playgroud)

Dan*_*ité 7

基于此错误消息:

错误:文本搜索词典"unaccent"不存在

并且在前一个unaccent没有找到模式前缀的情况下,这意味着publicunaccent函数所在的模式不在您的模式中search_path.

它发生unaccent在这种情况下失败,因为它是一个字典函数,基本上它需要通过它找到它的东西search_path.

PostgreSQL支持"重音不敏感"排序规则更详细的解释吗?

一旦将public模式添加到search_path需要调用它的用户(这通常是默认设置),这应该工作,他们不需要是超级用户.

或者,如果此解决方案不可接受,您还可以使用嵌入模式的中间存根函数,并添加不变性,如上面链接的答案所示.


drc*_*uck 5

这是我的解决方案。我有一个超级用户 (postgres) 和一个非超级用户 (pg4e_user_8087f) 和一个数据库 (pg4e),我想在不成为超级用户的情况下安装hstoreuuid-ossp扩展并使用它们。我正在使用 PostgreSQL 11。

超级用户窗口:

\c pg4e
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
ALTER EXTENSION "uuid-ossp" SET SCHEMA public;
CREATE EXTENSION IF NOT EXISTS "hstore";
ALTER EXTENSION "hstore" SET SCHEMA public;
GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO pg4e_user_8087f; 
Run Code Online (Sandbox Code Playgroud)

上述命令完成后的非超级用户窗口:

pg4e=> \dx
                            List of installed extensions
   Name    | Version |   Schema   |                   Description                    
-----------+---------+------------+--------------------------------------------------
 hstore    | 1.5     | public     | data type for storing sets of (key, value) pairs
 plpgsql   | 1.0     | pg_catalog | PL/pgSQL procedural language
 uuid-ossp | 1.1     | public     | generate universally unique identifiers (UUIDs)

pg4e=> select uuid_generate_v1();
           uuid_generate_v1           
--------------------------------------
 2114df5a-16bb-11ea-8000-468ce7a721ef
(1 row)

pg4e=> SELECT 'a=>1,b=>2'::hstore;
       hstore       
--------------------
 "a"=>"1", "b"=>"2"
(1 row)
Run Code Online (Sandbox Code Playgroud)

有一次,我已经弄清楚了几乎所有内容,但没有意识到超级用户必须连接到相关数据库才能创建并允许扩展。一旦我发现这是为特定数据库完成的,它很快就到位。