从今天早上开始:
psql PGP_SYM_DECRYPT : HINT: No function matches the given name and argument types.
LINE 1: select login,PGP_SYM_DECRYPT(password,'*******') from pa...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
存在扩展pg_crypto。
所以我无法从以前的pgp_sym_encrypt查询中选择任何数据。。。出了什么问题?如何解决?
如果扩展没有更新,并且昨天还在工作,那么问题可能是search_path
。确保在search_path中设置了扩展的路径。
因此,要检查扩展的安装位置,请键入dx
并记下模式。然后,键入show search_path;
,并确保扩展的模式列在那里(可能是public
(。如果没有,请将扩展的架构添加到搜索路径中。
为了进行调查,我构建了一个包含较少列的表副本。并尝试了相同的密码视觉检查:
perso=# select quoi,login,pgp_sym_decrypt(password::bytea,'someKEY') from tempo where quoi ilike '%somesite%' ;
quoi | login | pgp_sym_decrypt
--------------+-----------------------+-----------------
somesite.com | somename@somewhere.fr | foobar
(1 row)
perso=# select quoi,login,pgp_sym_decrypt(password,'someKEY') from tempo where quoi ilike '%somesite%' ;
quoi | login | pgp_sym_decrypt
--------------+-----------------------+-----------------
somesite.com | somename@somewhere.fr | foobar
(1 row)
perso=# d+ tempo
Table "public.tempo"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+---------+----------+--------------+-------------
ref | integer | | | | plain | |
quoi | text | | | | extended | |
login | text | | | | extended | |
password | bytea | | | | extended | |
这里没有更多的问题,所以表或数据存储模式存在问题。
perso=# d+ passwd
Table "public.passwd"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+-------------------------------------+----------+--------------+-------------
ref | integer | | not null | nextval('passwd_ref_seq'::regclass) | plain | |
quoi | text | | not null | | extended | |
login | text | | not null | | extended | |
password | text | | not null | | extended | |
Indexes:
"passwd_pkey" PRIMARY KEY, btree (ref)
"passwd_password_key" UNIQUE CONSTRAINT, btree (password)
perso=#
perso=# select quoi,login,pgp_sym_decrypt(password,'someKEY') from passwd where quoi ilike '%somesite%' ;
ERROR: function pgp_sym_decrypt(text, unknown) does not exist
LINE 1: select quoi,login,pgp_sym_decrypt(password,'someKEY') fr...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
perso=#
这里我们有返回错误&在密码列上检测text
。所以测试:
- 更改表=>BIG FAIL第二次重新编码所有数据
- 删除测试表密码
- 还原测试表passwd
- 在节拍表中复制数据
- 删除passwd表中的数据
- 更改passwd表
- 将数据复制回passwd表
作为我的测试程序。
所以我做了:
perso=#
perso=# delete from passwd ;
DELETE 106
perso=# alter table passwd alter column password type bytea using PGP_SYM_ENCRYPT(password::text,'someKEY');
ALTER TABLE
perso=# d+ passwd
Table "public.passwd"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+-------------------------------------+----------+--------------+-------------
ref | integer | | not null | nextval('passwd_ref_seq'::regclass) | plain | |
quoi | text | | not null | | extended | |
login | text | | not null | | extended | |
password | bytea | | not null | | extended | |
Indexes:
"passwd_pkey" PRIMARY KEY, btree (ref)
"passwd_password_key" UNIQUE CONSTRAINT, btree (password)
perso=# insert into passwd (ref,quoi,login,password) select ref,quoi,login,password::bytea from tempo ;
INSERT 0 106
perso=#
perso=#
perso=# select quoi,login,pgp_sym_decrypt(password,'someKEY') from passwd where quoi ilike '%somesite%' ;
quoi | login | pgp_sym_decrypt
--------------+-----------------------+-----------------
somesite.com | somename@somewhere.fr | foobar
(1 row)
perso=#
然后我备份数据库;并采用了类似的程序成功地解决了这个问题。这可能是一个更好的方法,但通过这种方式我理解了这个过程。
两种解决方案都在那里:
- 使用带column:bytea语法的查询
- 将列类型固定为:byta