Domanda

sto usando Ubuntu Server 10.10 e ho installato PostgreSQL 8.4 utilizzando apt-get install postgresql. Vorrei utilizzare il built-in funzione di sha1(), ma sembra che devo installare pgcrypto prima. Ma io non so come installarlo.

Non c'è pgcrypto se provo ad installarlo utilizzando apt-get install pgcrypto e non trovo alcun file che iniziano con pgcrypto nel mio sistema (ho provato find / -name "pgcrypto*").

Come si installa pgcrypto modo da poter utilizzare la funzione digest('word-to-hash','sha1') nelle mie query di database?


Aggiornamento: sto lottando per installare pgcrypto su un'altra macchina Ubuntu. Dopo aver installato il pacchetto utilizzando sudo apt-get install postgresql-contrib-8.4 come faccio installo nel mio database PostgreSQL attuale?

È stato utile?

Soluzione

Per la versione più recente di PG, controlla la risposta qui sotto da Dustin Kirkland

E 'un modulo esterno per Postgres. È necessario installare il postgresql-contrib-8.4 (o la versione pg) pacchetto tramite apt:

apt-get install postgresql-contrib-8.4

Poi si trova il file di installazione di SQL da qualche parte nella cartella /usr/share/postgresql, e avrete bisogno di eseguire pgcryto.sql sul database.

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

In alternativa,

$ cd /usr/share/postgresql/8.4/contrib
$ psql -d <database>
    psql (8.4.8)
    Type "help" for help.

    database=# \i pgcrypto.sql

Altri suggerimenti

PostgreSQL 9.1 +

Si noti che sto lavorando su Ubuntu 12.04, che utilizza PostgreSQL 9.1.

, avevo bisogno di:

sudo apt-get install postgresql-contrib

E poi nel mio database:

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

E ora posso usare pgcrypto funzionalità, 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

Per l'ultima versione, non c'è fine percorso del file con pgcrypto.sql.

Crea un pgcrypto estensione sotto l'utente desiderato.

$ 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=> 

Se nel caso, l'utente non dispone dell'autorizzazione per creare un interno, dare il permesso di superutente login come utente postgres (default) e riprovare.

$ 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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange
scroll top