AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 1883
Accepted
Jonas
Jonas
Asked: 2011-03-25 05:58:29 +0800 CST2011-03-25 05:58:29 +0800 CST 2011-03-25 05:58:29 +0800 CST

如何在 PostgreSQL 8.4 中安装 pgcrypto?

  • 772

我正在使用 Ubuntu Server 10.10,并且我已经使用apt-get install postgresql. 我想使用内置sha1()功能,但似乎必须先安装pgcrypto。但我不知道如何安装它。

如果pgcrypto我尝试使用安装它apt-get install pgcrypto并且在我的系统中找不到任何以开头的文件pgcrypto(我试过find / -name "pgcrypto*"),则没有。

如何安装 pgcrypto 以便digest('word-to-hash','sha1')在我的数据库查询中使用该函数?


更新:我正在努力在另一台 Ubuntu 机器上安装 pgcrypto。使用安装软件包后,sudo apt-get install postgresql-contrib-8.4如何将其安装到我当前的 PostgreSQL 数据库?

postgresql installation
  • 3 3 个回答
  • 57035 Views

3 个回答

  • Voted
  1. Dustin Kirkland
    2012-03-31T09:51:49+08:002012-03-31T09:51:49+08:00

    PostgreSQL 9.1+

    请注意,我正在使用 Ubuntu 12.04,它使用 postgresql 9.1。

    在那里,我需要:

    sudo apt-get install postgresql-contrib
    

    然后在我的数据库中:

    postgres@ztrustee:~$ psql test
    psql (9.1.3)
    Type "help" for help.
    test=# CREATE EXTENSION pgcrypto;
    CREATE EXTENSION
    

    现在我可以使用 pgcrypto 功能,gen_random_bytes():

    test=# create table test ( 
      id 
        text 
        not null 
        default encode( gen_random_bytes( 32 ), 'hex' ) 
        primary key, 
      value 
        text 
    ); 
    NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "test_pkey" for table "test"
    CREATE TABLE
    test=# \d test
                                Table "public.test"
     Column | Type |                         Modifiers                          
    --------+------+------------------------------------------------------------
     id     | text | not null default encode(gen_random_bytes(32), 'hex'::text)
     value  | text | 
    Indexes:
        "test_pkey" PRIMARY KEY, btree (id)
    
    test=# insert into test (value) VALUES ('scoobydoo');
    INSERT 0 1
    test=# select * from test;
                                    id                                |   value   
    ------------------------------------------------------------------+-----------
     76dd5bd0120d3df797f932fbcb4f8aa5088e215ee2b920dddbff59c8595fbac7 | scoobydoo
    
    • 20
  2. Best Answer
    DrColossos
    2011-03-25T06:35:53+08:002011-03-25T06:35:53+08:00

    对于更新版本的 PG,请查看以下 Dustin Kirkland 的答案

    它是 Postgres 的外部模块。您应该postgresql-contrib-8.4通过 apt 安装(或您的 pg 版本)包:

    apt-get install postgresql-contrib-8.4
    

    然后您在文件夹中的某处找到 sql 安装文件/usr/share/postgresql,您需要pgcryto.sql在数据库上运行。

    psql -d <database> -f /usr/share/postgresql/8.4/contrib/pgcrypto.sql
    

    或者,

    $ cd /usr/share/postgresql/8.4/contrib
    $ psql -d <database>
        psql (8.4.8)
        Type "help" for help.
    
        database=# \i pgcrypto.sql
    
    • 18
  3. Veeresh Digasangi
    2019-02-14T01:46:21+08:002019-02-14T01:46:21+08:00

    对于最新版本,没有以 pgcrypto.sql 结尾的文件路径。

    在所需用户下创建扩展 pgcrypto。

    $ psql -U <username> -d mydb
    
    psql (10.6 (Ubuntu 10.6-0ubuntu0.18.04.1))
    Type "help" for help.
    
    mydb=> CREATE EXTENSION pgcrypto;
    
    CREATE EXTENSION
    mydb=> 
    

    如果万一,用户没有创建扩展的权限,请以 postgres(默认)用户身份登录并授予超级用户权限,然后重试。

    $ psql --u postgres
    
    psql (10.6 (Ubuntu 10.6-0ubuntu0.18.04.1))
    Type "help" for help.
    
    postgres=# ALTER USER <username> WITH SUPERUSER;
    
    ALTER ROLE
    
    • 2

相关问题

  • 我可以在使用数据库后激活 PITR 吗?

  • 运行时间偏移延迟复制的最佳实践

  • 存储过程可以防止 SQL 注入吗?

  • PostgreSQL 中 UniProt 的生物序列

  • PostgreSQL 9.0 Replication 和 Slony-I 有什么区别?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    您如何显示在 Oracle 数据库上执行的 SQL?

    • 2 个回答
  • Marko Smith

    如何选择每组的第一行?

    • 6 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    我可以查看在 SQL Server 数据库上运行的历史查询吗?

    • 6 个回答
  • Marko Smith

    如何在 PostgreSQL 中使用 currval() 来获取最后插入的 id?

    • 10 个回答
  • Marko Smith

    如何在 Mac OS X 上运行 psql?

    • 11 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Marko Smith

    将数组参数传递给存储过程

    • 12 个回答
  • Martin Hope
    Manuel Leduc PostgreSQL 多列唯一约束和 NULL 值 2011-12-28 01:10:21 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Stuart Blackler 什么时候应该将主键声明为非聚集的? 2011-11-11 13:31:59 +0800 CST
  • Martin Hope
    pedrosanta 使用 psql 列出数据库权限 2011-08-04 11:01:21 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST
  • Martin Hope
    BrunoLM Guid vs INT - 哪个更好作为主键? 2011-01-05 23:46:34 +0800 CST
  • Martin Hope
    bernd_k 什么时候应该使用唯一约束而不是唯一索引? 2011-01-05 02:32:27 +0800 CST
  • Martin Hope
    Patrick 如何优化大型数据库的 mysqldump? 2011-01-04 13:13:48 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve