postgresql 加载共享库时出错:libpq.so.5:无法打开共享对象文件:没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12781566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:46:20  来源:igfitidea点击:

Error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

postgresqldebian

提问by McKibet

I am trying to execute pg_dumpon PostgreSQL 9.0.4 server running on Debian and I am getting the error below:

我正在尝试pg_dump在 Debian 上运行的 PostgreSQL 9.0.4 服务器上执行,但出现以下错误:

./pg_dump: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory 

libpq.so.5is a link to libpq.so.5.3as shown below

libpq.so.5是一个链接,libpq.so.5.3如下所示

lrwxrwxrwx 1 root root     12 Jun 27 16:24 libpq.so.5 -> libpq.so.5.3
-rwxr-xr-x 1 root root 180749 Jun 21 02:43 libpq.so.5.3

What is it that I am doing wrong?

我做错了什么?

回答by Yahya Yahyaoui

Try this:

尝试这个:

1: Know the path of libpq.so.5

1:了解路径 libpq.so.5

find / -name libpq.so.5

Output example: /usr/pgsql-9.4/lib/libpq.so.5If found nothing, check if you have already installed the suitable postgresql-libs for your postgresql version and your OS platform

输出示例: /usr/pgsql-9.4/lib/libpq.so.5如果什么也没找到,请检查您是否已经为您的 postgresql 版本和操作系统平台安装了合适的 postgresql-libs

2: Symbolic link that library in a "well known" library path like /usr/lib:

2:在“众所周知的”库路径中符号链接该库,例如/usr/lib

ln -s /usr/pgsql-9.4/lib/libpq.so.5 /usr/lib/libpq.so.5

Attention: If your platform is 64 bit, you MUST also symbolic link to 64 bit libraries path:

注意:如果您的平台是 64 位,您还必须符号链接到 64 位库路径:

ln -s /usr/pgsql-9.4/lib/libpq.so.5 /usr/lib64/libpq.so.5

3: Be happy !

3:快乐!

回答by Michael Krelin - hacker

In which directory are these libpqfiles? You can try setting environment variable LD_LIBRARY_PATHto point to this directory or make sure it's in standard place.

这些libpq文件在哪个目录?您可以尝试将环境变量设置LD_LIBRARY_PATH为指向此目录或确保它位于标准位置。

Also, why isn't the libpq.so.5link shown in the "as shown below" section? Maybe you should just run ldconfig?

另外,为什么libpq.so.5“如下所示”部分中没有显示链接?也许你应该跑ldconfig

回答by oden

I was getting the same error message on Postgres 9.5 on RHEL 6.5 which lead me to this post. But a find for the file libpq.so.5returned nothing, which made things more confusing.

我在 RHEL 6.5 上的 Postgres 9.5 上收到相同的错误消息,这使我看到了这篇文章。但是对文件的查找libpq.so.5没有返回任何内容,这让事情变得更加混乱。

In the end the following symbolic links made it run

最后,以下符号链接使其运行

ln -s /opt/rh/rh-postgresql95/root/usr/lib64/libpq.so.rh-postgresql95-5  /usr/lib64/libpq.so.rh-postgresql95-5 
ln -s /opt/rh/rh-postgresql95/root/usr/lib64/libpq.so.rh-postgresql95-5  /usr/lib/libpq.so.rh-postgresql95-5

These paths are for RHEL, use find / -name libpq.soto location your installation and add it to the same destination folders /usr/lib/and /usr/lib64/using the orginal file name.

这些路径用于 RHEL,用于find / -name libpq.so定位您的安装并将其添加到相同的目标文件夹/usr/lib//usr/lib64/使用原始文件名。

The root cause appears that the installation did not place this file into a shared location.

根本原因似乎是安装没有将此文件放入共享位置。

回答by Joabe Lucena

This error probably occurs because of $LD_LIBRARY_PATHenvironment variable is not set.

发生此错误的原因可能$LD_LIBRARY_PATH是未设置环境变量。

When you install your application from source code using prefix (./configure --prefix=/some/path), you have to inform where your lib/path is. I just found a solution for this, and I added this variable to postgres user init bash script:

当您使用前缀 ( ./configure --prefix=/some/path)从源代码安装应用程序时,您必须告知您的lib/路径在哪里。我刚刚为此找到了一个解决方案,并将此变量添加到 postgres 用户 init bash 脚本中:

printf 'export PATH=$PATH:/opt/apl/pgsql/bin\nexport LD_LIBRARY_PATH=/opt/apl/pgsql/lib:$LD_LIBRARY_PATH\n' > /etc/profile.d/postgres.sh

回答by taitelman

redhat 7 is missing few steps after installing yum install pgadmin4:

redhat 7 安装后缺少几个步骤yum install pgadmin4

sudo ln -s /usr/lib64/pgdg-libpq5/lib/libpq.so /usr/lib64/libpq.so.5
sudo ln -s /usr/lib64/pgdg-libpq5/lib/libpq.so /usr/lib/libpq.so.5
sudo chown -R apache:apache  /var/lib/pgadmin4/

then you can run

然后你可以运行

sudo python3 /usr/lib/python3.6/site-packages/pgadmin4-web/setup.py

and if all successful:

如果一切顺利:

systemctl start httpd
systemctl status httpd
apachectl configtest

and make sure the httpd starts ok

并确保 httpd 启动正常

回答by Ade

I had exactly the same problem with the pg 9.6 install. I fixed it like this. Rather irritating that the installer doesn't factor this in.

我在安装 pg 9.6 时遇到了完全相同的问题。我是这样修的。令人恼火的是安装程序没有考虑到这一点。

***********post yum install & running initdb *********
Success. You can now start the database server using:

    /opt/rh/rh-postgresql96/root/usr/bin/pg_ctl -D /var/opt/rh/rh-postgresql96/lib/pgsql/data -l logfile start

-bash-4.2$ /opt/rh/rh-postgresql96/root/usr/bin/pg_ctl -D /var/opt/rh/rh-postgresql96/lib/pgsql/data -l logfile start
/opt/rh/rh-postgresql96/root/usr/bin/pg_ctl: **error while loading shared libraries: libpq.so.rh-postgresql96-5: cannot open shared object file: No such file or directory**

-bash-4.2$ id
uid=26(postgres) gid=26(postgres) groups=26(postgres) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

**************
-bash-4.2$ cat LibFix
ln -s /opt/rh/rh-postgresql96/root/usr/lib64/libpq.so.rh-postgresql96-5  /usr/lib64/libpq.so.rh-postgresql96-5
ln -s /opt/rh/rh-postgresql96/root/usr/lib64/libpq.so.rh-postgresql96-5  /usr/lib/libpq.so.rh-postgresql96-5
**************

[root@****lab ~]# ln -s /opt/rh/rh-postgresql96/root/usr/lib64/libpq.so.rh-postgresql96-5  /usr/lib64/libpq.so.rh-postgresql96-5
[root@****lab ~]# ln -s /opt/rh/rh-postgresql96/root/usr/lib64/libpq.so.rh-postgresql96-5  /usr/lib/libpq.so.rh-postgresql96-5

[root@****lab ~]# su - postgres
Last login: Thu Apr  5 08:57:21 CEST 2018 on pts/0

-bash-4.2$ /opt/rh/rh-postgresql96/root/usr/bin/pg_ctl -D /var/opt/rh/rh-postgresql96/lib/pgsql/data -l logfile start
server starting

-bash-4.2$ ps -ef | grep postgres
root     12778  7883  0 09:07 pts/0    00:00:00 su - postgres
postgres 12779 12778  0 09:07 pts/0    00:00:00 -bash
postgres 12802     1  0 09:08 pts/0    00:00:00 /opt/rh/rh-postgresql96/root/usr/bin/postgres -D /var/opt/rh/rh-postgresql96/lib/pgsql/data
postgres 12803 12802  0 09:08 ?        00:00:00 postgres: logger process
postgres 12805 12802  0 09:08 ?        00:00:00 postgres: checkpointer process
postgres 12806 12802  0 09:08 ?        00:00:00 postgres: writer process
postgres 12807 12802  0 09:08 ?        00:00:00 postgres: wal writer process
postgres 12808 12802  0 09:08 ?        00:00:00 postgres: autovacuum launcher process
postgres 12809 12802  0 09:08 ?        00:00:00 postgres: stats collector process
postgres 12810 12779  0 09:08 pts/0    00:00:00 ps -ef

-bash-4.2$ id
uid=26(postgres) gid=26(postgres) groups=26(postgres) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
-bash-4.2$ psql
psql (9.6.5)

postgres=# \conninfo

You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".