如何在 PostgreSQL 9.1+ 中导入模块或安装扩展?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9025515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I import modules or install extensions in PostgreSQL 9.1+?
提问by Evan Carroll
Firstly, if you're not using 9.1+, please refer to this question.
首先,如果您使用的不是 9.1+,请参考这个问题。
How do I install an extension to PostgreSQL 9.1?
如何安装 PostgreSQL 9.1 的扩展?
回答by Evan Carroll
Postgrseql 9.1 provides for a new command CREATE EXTENSION
. You should use it to install modules.
Postgrseql 9.1 提供了一个新命令CREATE EXTENSION
。您应该使用它来安装模块。
Modules provided in 9.1 can be found here.. The include,
可以在此处找到 9.1 中提供的模块。. 其中包括,
adminpack , auth_delay , auto_explain , btree_gin , btree_gist
, chkpass , citext , cube , dblink , dict_int
, dict_xsyn , dummy_seclabel , earthdistance , file_fdw , fuzzystrmatch
, hstore , intagg , intarray , isn , lo
, ltree , oid2name , pageinspect , passwordcheck , pg_archivecleanup
, pgbench , pg_buffercache , pgcrypto , pg_freespacemap , pgrowlocks
, pg_standby , pg_stat_statements , pgstattuple , pg_test_fsync , pg_trgm
, pg_upgrade , seg , sepgsql , spi , sslinfo , tablefunc
, test_parser , tsearch2 , unaccent , uuid-ossp , vacuumlo
, xml2
If for instance you wanted to install earthdistance
, simply use this command:
例如,如果您想安装earthdistance
,只需使用以下命令:
CREATE EXTENSION earthdistance;
If you wanted to install an extension with a hyphen in its name, like uuid-ossp
, you need to enclose the extension name in double quotes:
如果要安装名称中带有连字符的扩展程序,例如uuid-ossp
,则需要将扩展程序名称括在双引号中:
CREATE EXTENSION "uuid-ossp";
- Read more about contrib, and the modules available in 9.1.
- Read about the new extension infrastructure, and the SQL commands to manage it hereYou can now more easily uninstall a module, see
DROP EXTENSION
. You can also get an extension list, and there is basic support for version numbers.
- 阅读有关 contrib 以及 9.1 中可用模块的更多信息。
- 在此处阅读有关新扩展基础结构以及管理它的 SQL 命令的信息现在您可以更轻松地卸载模块,请参阅
DROP EXTENSION
。您还可以获得扩展列表,并且对版本号有基本的支持。
回答by tani-rokk
While Evan Carrol's answer is correct, please note that you need to install the postgresql contrib package in order for the CREATE EXTENSION command to work.
虽然 Evan Carrol 的回答是正确的,但请注意,您需要安装 postgresql contrib 包才能使 CREATE EXTENSION 命令起作用。
In Ubuntu 12.04 it would go like this:
在 Ubuntu 12.04 中,它会是这样的:
sudo apt-get install postgresql-contrib
Restart the postgresql server:
重启 postgresql 服务器:
sudo /etc/init.d/postgresql restart
All available extension are in:
所有可用的扩展名都在:
/usr/share/postgresql/9.1/extension/
Now you can run the CREATE EXTENSION command.
现在您可以运行 CREATE EXTENSION 命令。
回答by kgrittn
In addition to the extensions which are maintained and provided by the core PostgreSQL development team, there are extensions available from third parties. Notably, there is a site dedicated to that purpose: http://www.pgxn.org/
除了核心 PostgreSQL 开发团队维护和提供的扩展外,还有第三方提供的扩展。值得注意的是,有一个专门用于此目的的网站:http: //www.pgxn.org/
回答by matson kepson
For the postgrersql10
对于 postgrsql10
I have solved it with
我已经解决了
yum install postgresql10-contrib
Don't forget to activate extensions in postgresql.conf
不要忘记在 postgresql.conf 中激活扩展
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.track = all
then of course restart
然后当然重新启动
systemctl restart postgresql-10.service
all of the needed extensions you can find here
您可以在此处找到所有需要的扩展
/usr/pgsql-10/share/extension/
回答by Marios Simou
The extensions available for each version of Postgresql vary. An easy way to check which extensions are available is, as has been already mentioned:
每个版本的 Postgresql 可用的扩展各不相同。如前所述,检查哪些扩展可用的简单方法是:
SELECT * FROM pg_available_extensions;
If the extension that you are looking for is available, you can install it using:
如果您正在寻找的扩展可用,您可以使用以下方法安装它:
CREATE EXTENSION 'extensionName';
or if you want to drop it use:
或者如果你想放弃它,请使用:
DROP EXTENSION 'extensionName';
With psql
you can additionally check if the extension has been successfully installed using \dx
, and find more details about the extension using \dx+ extensioName
. It returns additional information about the extension, like which packages are used with it.
有了psql
你还可以查看是否有延期使用已安装成功\dx
,并找到有关使用扩展更多的细节\dx+ extensioName
。它返回有关扩展的附加信息,例如与它一起使用的包。
If the extension is not available in your Postgres version, then you need to download the necessary binary files and libraries and locate it them at /usr/share/conrib
如果该扩展在您的 Postgres 版本中不可用,那么您需要下载必要的二进制文件和库并在以下位置找到它们 /usr/share/conrib
回答by André Herculano
Into psql terminal put:
进入 psql 终端输入:
\i <path to contrib files>
in ubuntu it usually is /usr/share/postgreslq/<your pg version>/contrib/<contrib file>.sql
在 ubuntu 中通常是 /usr/share/postgreslq/<your pg version>/contrib/<contrib file>.sql
回答by mountainclimber
How to download and install if you have SUSE. As an example I am downloading the tablefunc module so I can use crosstab. I have PostgreSQL 9.6.1.
如果您有 SUSE,如何下载和安装。例如,我正在下载 tablefunc 模块,以便我可以使用交叉表。我有 PostgreSQL 9.6.1。
right-click desktop, terminal, type:
右击桌面,终端,输入:
sudo zypper in postgreql-contrib
Enter credentials, continue by typing:
输入凭据,继续键入:
y
Run query (I ran mine from pgAdminIII):
运行查询(我从 pgAdminIII 运行我的):
CREATE EXTENSION tablefunc;
You should now have the crosstab
function.
您现在应该拥有该crosstab
功能。
I did not have to restart.
我不必重新启动。