问题描述
从今天早上开始:
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,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,'someKEY') from passwd where quoi ilike '%somesite%' ;
ERROR: function pgp_sym_decrypt(text,unknown) does not exist
LINE 1: select quoi,'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表中
作为我的测试程序。
所以我做到了:
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,password) select ref,password::bytea from tempo ;
INSERT 0 106
perso=#
perso=#
perso=# select quoi,'someKEY') from passwd where quoi ilike '%somesite%' ;
quoi | login | pgp_sym_decrypt
--------------+-----------------------+-----------------
somesite.com | somename@somewhere.fr | foobar
(1 row)
perso=#
然后我备份数据库;并应用了类似的步骤来成功解决该问题。这样做可能是一个更好的方法,但是这样我可以理解过程。
两种解决方案都在其中:
- 使用具有column:bytea语法的查询
- 将列类型固定为:bytea