postgresql 如何在 Postgres 8.4 中导入模块或安装扩展?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1564056/
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 Postgres 8.4?
提问by
I'm trying to import several modules that come bundled with 8.4.1 postgres, and all the commands to do so (such as contrib.import etc) do not work or cannot be found. Please help me.
我正在尝试导入与 8.4.1 postgres 捆绑在一起的几个模块,并且所有这样做的命令(例如 contrib.import 等)都不起作用或找不到。请帮我。
回答by
To install PostgreSQL contrib
modules on Ubuntu or Kubuntu (or similar Linux distributions):
contrib
在 Ubuntu 或 Kubuntu(或类似的 Linux 发行版)上安装 PostgreSQL模块:
- Install the contrib package:
sudo apt-get install postgresql-contrib
- Restart the database:
sudo /etc/init.d/postgresql-8.4 restart
- Change to the database owner account (e.g.,
postgres
). - Change to the contrib modules' directory:
/usr/share/postgresql/8.4/contrib/
Use
ls
to see a list of the following modules:adminpack autoinc btree_gin btree_gist chkpass citext cube dblink dict_int dict_xsyn earthdistance fuzzystrmatch hstore insert_username int_aggregate isn lo ltree moddatetime pageinspect pg_buffercache pgcrypto pg_freespacemap pgrowlocks pg_stat_statements pgstattuple pg_trgm pgxml refint seg sslinfo tablefunc test_parser timetravel tsearch2 uuid-ossp
Load the SQL files using:
psql -U user_name -d database_name -f module_name.sql
- 安装 contrib 包:
sudo apt-get install postgresql-contrib
- 重启数据库:
sudo /etc/init.d/postgresql-8.4 restart
- 更改为数据库所有者帐户(例如,
postgres
)。 - 切换到 contrib 模块的目录:
/usr/share/postgresql/8.4/contrib/
使用
ls
看看下面的模块列表:adminpack autoinc btree_gin btree_gist chkpass citext cube dblink dict_int dict_xsyn earthdistance fuzzystrmatch hstore insert_username int_aggregate isn lo ltree moddatetime pageinspect pg_buffercache pgcrypto pg_freespacemap pgrowlocks pg_stat_statements pgstattuple pg_trgm pgxml refint seg sslinfo tablefunc test_parser timetravel tsearch2 uuid-ossp
使用以下命令加载 SQL 文件:
psql -U user_name -d database_name -f module_name.sql
For example, if your administrative user was named postgres
and your database was named storage
and the module you wanted was cube
, you would type:
例如,如果您的管理用户被命名postgres
,您的数据库被命名storage
并且您想要的模块是cube
,您将键入:
psql -U postgres -d storage -f cube.sql
PostgreSQL 9.1:
PostgreSQL 9.1:
After step #1 above, do:
在上面的第 1 步之后,执行:
sudo /etc/init.d/postgresql restart
- (same as #3 above)
cd /usr/share/postgresql/9.1/extension
(has extensions)- open
psql
CREATE EXTENSION "uuid-ossp";
sudo /etc/init.d/postgresql restart
- (同上面的#3)
cd /usr/share/postgresql/9.1/extension
(有扩展)- 打开
psql
CREATE EXTENSION "uuid-ossp";
回答by David
- login as postgres user
- use create extension to load it
- 以 postgres 用户身份登录
- 使用创建扩展来加载它
I have a database named 'book' for example,
例如,我有一个名为“book”的数据库,
psql -U postgres book create extension cube
psql -U postgres book 创建扩展立方体
Repeat for each extension required, then \q to logouy
对每个需要的扩展重复,然后 \q 到 logouy