pgcryptoをpostgresql 8.4にインストールするにはどうすればよいですか?
-
16-10-2019 - |
質問
Ubuntu Server 10.10を使用していますが、PostgreSQL 8.4を使用してインストールしました 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データベースにインストールするにはどうすればよいですか?
解決
PGの新しいバージョンについては、Dustin Kirklandの以下の回答をご覧ください
Postgresの外部モジュールです。インストールする必要があります postgresql-contrib-8.4
(またはPGバージョン)APT経由のパッケージ:
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
他のヒント
postgreSQL 9.1+
PostgreSQL 9.1を使用するUbuntu 12.04に取り組んでいることに注意してください。
そこで、私は:
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
最新バージョンの場合、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