A timeless hush before the ink descends.
ERROR: extension "pgcrypto" is not available
DETAIL: Could not open extension control file "/www/server/pgsql/share/extension/pgcrypto.control": No such file or directory.
HINT: The extension must first be installed on the system where PostgreSQL is running.wget https://ftp.postgresql.org/pub/source/v16.1/postgresql-16.1.tar.gz
tar -zxvf postgresql-16.1.tar.gz
cd postgresql-16.1./configure --with-pgconfig=/www/server/pgsql/bin/pg_configcd contrib/pgcrypto
make
make installubuntu@ubuntu:~$ find / -name "pgcrypto.so" 2>/dev/null
/usr/local/pgsql/lib/pgcrypto.so
/home/ubuntu/postgresql-16.1/contrib/pgcrypto/pgcrypto.so
ubuntu@ubuntu:~$ find / -name "pgcrypto.control" 2>/dev/null
/usr/local/pgsql/share/extension/pgcrypto.control
/usr/local/pgsql/contrib/pgcrypto/pgcrypto.control
/home/ubuntu/postgresql-16.1/contrib/pgcrypto/pgcrypto.controlcp /usr/local/pgsql/lib/pgcrypto.so /www/server/pgsql/lib/
cp /usr/local/pgsql/share/extension/pgcrypto.control /www/server/pgsql/share/extension/
find /usr/local/pgsql/share/extension/ -name "pgcrypto--*.sql" -exec cp {} /www/server/pgsql/share/extension/ \;ubuntu@ubuntu:~$ ls /www/server/pgsql/lib/ | grep pgcrypto
pgcrypto.so
ubuntu@ubuntu:~$ ls /www/server/pgsql/share/extension/ | grep pgcrypto
pgcrypto--1.0--1.1.sql
pgcrypto--1.1--1.2.sql
pgcrypto--1.2--1.3.sql
pgcrypto--1.3.sql
pgcrypto.control/www/server/pgsql/bin/psql -U postgresCREATE EXTENSION pgcrypto;postgres=# CREATE EXTENSION pgcrypto;
ERROR: could not load library "/www/server/pgsql/lib/pgcrypto.so": /www/server/pgsql/lib/pgcrypto.so: undefined symbol: EVP_cast5_cbcubuntu@ubuntu:~$ openssl version
OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024)
ubuntu@ubuntu:~$ ldd /www/server/pgsql/lib/pgcrypto.so
linux-vdso.so.1 (0x00007ffea096a000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x0000754a31f6c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000754a31c00000)
/lib64/ld-linux-x86-64.so.2 (0x0000754a31fc4000)
ubuntu@ubuntu:~$ ldd /www/server/pgsql/bin/postgres
linux-vdso.so.1 (0x00007ffc553a2000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007b8cf4de1000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007b8cf4317000)
libicui18n.so.74 => /lib/x86_64-linux-gnu/libicui18n.so.74 (0x00007b8cf3e00000)
libicuuc.so.74 => /lib/x86_64-linux-gnu/libicuuc.so.74 (0x00007b8cf3a00000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007b8cf3600000)
/lib64/ld-linux-x86-64.so.2 (0x00007b8cf4e08000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007b8cf3200000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007b8cf4db1000)
libicudata.so.74 => /lib/x86_64-linux-gnu/libicudata.so.74 (0x00007b8cf1400000)
ubuntu@ubuntu:~$ openssl list -cipher-algorithms | grep CAST5
cast => CAST5-CBC
cast-cbc => CAST5-CBC
CAST5-CBC
CAST5-CFB
CAST5-ECB
CAST5-OFBcd postgresql-16.1
make distclean
./configure --with-pgconfig=/www/server/pgsql/bin/pg_config --with-openssl
cd contrib/pgcrypto
make clean
makeubuntu@ubuntu:~$ ldd ~/postgresql-16.1/contrib/pgcrypto/pgcrypto.so | grep crypto
libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x0000782303a00000)sudo cp ~/postgresql-16.1/contrib/pgcrypto/pgcrypto.so /www/server/pgsql/lib/
sudo cp ~/postgresql-16.1/contrib/pgcrypto/pgcrypto.control /www/server/pgsql/share/extension/
sudo cp ~/postgresql-16.1/contrib/pgcrypto/pgcrypto--*.sql /www/server/pgsql/share/extension/ubuntu@ubuntu:~$ /www/server/pgsql/bin/psql -U postgres
psql (16.1)
Type "help" for help.
postgres=# CREATE EXTENSION pgcrypto;
pgcrypto
postgres=#wget https://ftp.postgresql.org/pub/source/v16.1/postgresql-16.1.tar.gz
tar -zxvf postgresql-16.1.tar.gzcd postgresql-16.1
./configure --with-pgconfig=/www/server/pgsql/bin/pg_config --with-opensslcd contrib/pgcrypto
makeldd pgcrypto.so | grep cryptoubuntu@ubuntu:~$ ldd ~/postgresql-16.1/contrib/pgcrypto/pgcrypto.so | grep crypto
libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x0000782303a00000)sudo cp ~/postgresql-16.1/contrib/pgcrypto/pgcrypto.so /www/server/pgsql/lib/
sudo cp ~/postgresql-16.1/contrib/pgcrypto/pgcrypto.control /www/server/pgsql/share/extension/
sudo cp ~/postgresql-16.1/contrib/pgcrypto/pgcrypto--*.sql /www/server/pgsql/share/extension//www/server/pgsql/bin/psql -U postgresCREATE EXTENSION pgcrypto;rm -rf ~/postgresql-16.1
这篇文章是踩坑的过程记录,其中包含着一些不可用的命令,请留意文中的提示~ 正确的编译和安装流程从 安装流程 开始
起因
博主的 PostgreSQL 是通过宝塔面板的 PostgreSQL 管理器快速安装的,版本如下:
但在一次使用 prisma 初始化数据库时发生了这样的报错:
报错原因很显然,数据库找不到 /www/server/pgsql/share/extension/pgcrypto.control 这个控制文件。也就是说,宝塔面板预构建的 PG 并没有包含 pgcrypto 之类的扩展,而宝塔官方也没有提供 PostgreSQL 扩展的安装途径。
博主的想法是不完整安装,不重新安装 PostgreSQL 数据库,直接编译 pgcrypto 扩展至宝塔 PG 目录下。这样可以防止系统中存在多个数据库造成冲突,影响数据库运行,同时也防止环境不同导致库文件动态链接失败。
于是,打开搜索引擎找啊找...
后续博主又以“宝塔安装pgcrypto”等关键词查询,但只找到了通过 apt 全新安装一次 PG 及扩展,再将需要的扩展复制至宝塔 PG 目录下这种方法。这并不是博主想要的,于是,又可以多一篇首发原创水文了(笑
折腾小记
以下流程不全部正确,但看看似乎也不错~ 正确的编译和安装流程从后文 安装流程 开始
博主使用的是 PG 16.1 ,为了防止最后将没用的文件丢的到处都是,博主选择了在 ~ (Home) 目录下编译
没有源码还怎么编译呀,所以先搞到对应版本的源码
因为需要为宝塔的 PG 编译,所以自然要使用宝塔的 pg_config 来配置编译环境
配置完成后进入 pgcrypto 扩展的路径开始编译
然后试了试好像有点效果(?之后就立刻把 ~/postgresql-16.1/ 扬了,又不能用了
于是按刚刚的步骤再试一次,看看装到哪里了
欸欸欸我的 pgcrypto,你怎么在 /usr/local/pgsql/ 里啊
那就将错就错吧,复制过去看看
很好,整整齐齐
在宝塔面板重启了 PG 之后,连接数据库,运行导入扩展的命令
但出现了一个奇怪的错误
EVP_cast5_cbc 是 OpenSSL libcrypto 库自带的一个函数,为什么会缺失呢
通过 ldd 查看 pgcrypto.so 使用的共享库并和 postgres 进行比较,pgcrypto.so 并没有链接 libcrypto.so,只链接了 libz 和 libc,并且 OpenSSL 的 CAST5 是正常的。猜测是宝塔的 pg_config 有问题,或是编译时没有启用 OpenSSL 支持。
于是重新配置,重新编译,尝试通过强制开启 OpenSSL 支持来解决
看看有没有 libcrypto.so 呢
那应该没什么问题了,复制过去吧~
重启 PG 之后再导入扩展
大功告成~ 可以愉快的玩耍了 🎉
安装流程
以 PG 16.1 为例
编译
应该有类似如下输出:
安装
后记
后记应该是没人看的吧(大概
喜欢我 95 行的 bash_history 吗