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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:21:43  来源:igfitidea点击:

How do I import modules or install extensions in Postgres 8.4?

postgresqlimportpostgresql-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 contribmodules on Ubuntu or Kubuntu (or similar Linux distributions):

contrib在 Ubuntu 或 Kubuntu(或类似的 Linux 发行版)上安装 PostgreSQL模块:

  1. Install the contrib package: sudo apt-get install postgresql-contrib
  2. Restart the database: sudo /etc/init.d/postgresql-8.4 restart
  3. Change to the database owner account (e.g., postgres).
  4. Change to the contrib modules' directory: /usr/share/postgresql/8.4/contrib/
  5. Use lsto 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
    
  6. Load the SQL files using: psql -U user_name -d database_name -f module_name.sql

  1. 安装 contrib 包: sudo apt-get install postgresql-contrib
  2. 重启数据库: sudo /etc/init.d/postgresql-8.4 restart
  3. 更改为数据库所有者帐户(例如,postgres)。
  4. 切换到 contrib 模块的目录: /usr/share/postgresql/8.4/contrib/
  5. 使用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
    
  6. 使用以下命令加载 SQL 文件: psql -U user_name -d database_name -f module_name.sql

For example, if your administrative user was named postgresand your database was named storageand 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 步之后,执行:

  1. sudo /etc/init.d/postgresql restart
  2. (same as #3 above)
  3. cd /usr/share/postgresql/9.1/extension(has extensions)
  4. open psql
  5. CREATE EXTENSION "uuid-ossp";
  1. sudo /etc/init.d/postgresql restart
  2. (同上面的#3)
  3. cd /usr/share/postgresql/9.1/extension(有扩展)
  4. 打开 psql
  5. CREATE EXTENSION "uuid-ossp";

回答by David

  1. login as postgres user
  2. use create extension to load it
  1. 以 postgres 用户身份登录
  2. 使用创建扩展来加载它

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