4

I'm trying to get postgres server status with:

sudo /etc/init.d/postgres status -u postgres

But getting following error:

/home/alex/olddisk/usr/local/pgsql/bin/pg_ctl: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

I added:

export LD_LIBRARY_PATH=""
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/alex/olddisk/usr/local/pgsql/lib/"

to my .bashrc, but it didn't help.

Thank you.

0xAX
  • 20,957
  • 26
  • 117
  • 206
  • `libpg.so.5` lies in `/home/alex/olddisk/usr/local/pgsql/lib/`, I guess? – hagello Feb 15 '15 at 20:25
  • Per @survivor , does [Error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory](http://stackoverflow.com/questions/12781566/error-while-loading-shared-libraries-libpq-so-5-cannot-open-shared-object-file) help? – Brad Koch May 15 '15 at 22:03
  • @BradKoch yes sure ! I changed my name, I was survivor (but still inside) – Yahya Yahyaoui Apr 27 '18 at 15:35

5 Answers5

3

I think this issue is duplicated, I faced the same problem and posted a solution here.

try this:

1: Know the path of "libpq.so.5"

find / -name libpq.so.5

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

2: Symbolic link that library in a "well known" library path like "/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:

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

3: Be happy !

Community
  • 1
  • 1
Yahya Yahyaoui
  • 2,833
  • 23
  • 30
  • 1
    Your comments helped me. But also check this answer for anyone that is still stuck http://stackoverflow.com/questions/12781566/error-while-loading-shared-libraries-libpq-so-5-cannot-open-shared-object-file/40200411#40200411 – oden Oct 23 '16 at 07:05
  • Cannot thank you enough for this. – zerohedge Apr 14 '23 at 15:34
3

I ran into this error when I built postgresql from source using the --prefix flag. Building from source installs the necessary shared libs to the libs folder under the prefix directory you specified, instead of the usual place installations put shared libs. To solve the problem I just added the [prefix].libs folder to the LD_LIBRARY_PATH environment variable. For example, after building postgres using --prefix /mike/sandbox/postgres, the below command solved the issue:

export LD_LIBRARY_PATH=/mike/sandbox/postgres/lib:$LD_LIBRARY_PATH

mancini0
  • 4,285
  • 1
  • 29
  • 31
2

Please ensure you have 'postgresql94' package installed as well (in addition to postgresql94-server, postgresql94-lib, postgresql94-devel and whatever other PG related package you already have). These libraries get installed along with that package.

Rahul R
  • 21
  • 3
1

Some ideas:

  • Your modified ~/.bashrc only takes effect when you start a new (interactive) shell. Though catching up on that will not help you because:

  • /etc/sudoers, your configuration file of sudo, probably specifies env_reset. This means, that /etc/init.d/postgres will not see the content of $LD_LIBRARY_PATH of your shell.

  • Insert debug statements in /etc/init.d/postgres to verify what I told you: echo "LDPATH: $LD_LIBRARY_PATH" >&2

  • Check /etc/init.d/postgres. Probably you will have to insert the third one of your export statements near the start of this script. Or you will have to update an existing export LD_LIBRARY_PATH= statement.

hagello
  • 2,843
  • 2
  • 27
  • 37
0

Have you installed the necessary libraries? If you are using ubuntu try:

  sudo apt-get install libpq libpq-dev
Bruno
  • 623
  • 4
  • 6