将PostgreSQL扩展安装到所有模式 [英] Installing PostgreSQL Extension to all schemas

查看:96
本文介绍了将PostgreSQL扩展安装到所有模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PostgresQL 9.1.1,试图使扩展名不懂

所以我运行了命令 CREATE EXTENSION unaccent; 。哪个有效,但仅适用于 search_path 上设置的当前模式。因此,这意味着如果更改search_path,我将无法再调用 unaccent 。如何使此扩展可用于特定数据库中的所有模式?



提前谢谢!

解决方案

可接受的答案是<强>差建议。不要将扩展安装到 pg_catalog 架构中。



创建扩展名不重音; 将扩展安装到公共模式中。要使其变得有用,只需在更改search_path时包括以下内容:

  set search_path = my_schema,public; 

或者更好地创建一个包含所有扩展名的架构,然后始终将该架构附加到search_path中。

 创建架构扩展; 

-确保每个人都可以使用扩展架构中的所有内容。
Grant会在模式扩展中的所有功能上执行,以public方式执行;

-包括将来的扩展
更改模式扩展中的默认特权
授予对公共函数执行的权限;

更改架构扩展中的默认权限
授予对公共类型的使用;

现在安装扩展名:

 创建扩展无意义的模式扩展; 

然后将其包含在搜索路径中

  set search_path = my_schema,扩展名; 






如果您不想重复以上内容对于您创建的每个新数据库,在连接到 template1 数据库的同时运行上述步骤。您甚至可以通过编辑 postgresql.conf 或使用 alter系统

I'm on PostgresQL 9.1.1 trying to have the extension unaccent available on all schemas.

So I ran the command CREATE EXTENSION unaccent;. Which works, but only for the current schema set on search_path. So this means if I change the search_path, I no longer can call unaccent. How do I make this extension available to all schemas in a particular database?

Thanks in advance!

解决方案

The accepted answer is a bad advice. Do not install extensions into the pg_catalog schema.

CREATE EXTENSION unaccent; installs the extension into the public schema. To make it usably, simply include that when changing the search_path:

set search_path = my_schema, public;

Or better create a schema to contain all extensions, then always append that schema to the search_path.

create schema extensions;

-- make sure everybody can use everything in the extensions schema
grant usage on schema extensions to public;
grant execute on all functions in schema extensions to public;

-- include future extensions
alter default privileges in schema extensions
   grant execute on functions to public;

alter default privileges in schema extensions
   grant usage on types to public;

Now install the extension:

create extension unaccent schema extensions;

Then use include that schema in the search_path

set search_path = my_schema, extensions;


If you don't want to repeat the above for every new database you create, run the above steps while being connected to the template1 database. You can even include the extensions schema in the default search_path by either editing postgresql.conf or using alter system

这篇关于将PostgreSQL扩展安装到所有模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆