Recent

Author Topic: PostgreSQL on Linux  (Read 1789 times)

lainz

  • Hero Member
  • *****
  • Posts: 3874
PostgreSQL on Linux
« on: October 05, 2021, 02:00:05 am »
Hi, I've downloaded the .so files from this site
https://www.enterprisedb.com/download-postgresql-binaries

And I want to use them with my executable on Linux. I place the .so files in the same folder as the executable and it always ask me the same .so file 'libpq.so.5' in an error message.

I have the same program running on Windows without problems.

PierceNg

  • Full Member
  • ***
  • Posts: 146
Re: PostgreSQL on Linux
« Reply #1 on: October 05, 2021, 03:05:44 am »
By default, Linux doesn't look for shared library files in the directory where the executable is located. There is a standard list of locations for that. This standard list is not identical across different Linux distros.

Two possible solutions:

- Instead of downloading the PostgreSQL binaries, use your Linux distro's package manager to install the PostgreSQL client package. This will place the .so files in the right places on the system with the right permissions.

- Execute your Pascal program from a shell script that sets LD_LIBRARY_PATH to the directory where the Pascal executable and PostgreSQL .so files are located. Working example for Ubuntu:

Code: Text  [Select][+][-]
  1. #!/bin/sh
  2. MYPASPROGPATH=$(/bin/dirname `/bin/readlink -f "$0"`)
  3. LD_LIBRARY_PATH="$MYPASPROGPATH" exec "$MYPASPROGPATH/mypasprog" $@ &

The first line sets MYPASPROGPATH to the directory that contains your executable and the .so files. The second line sets LD_LIBRARY_PATH to that same directory, then runs your program (named "mypasprog" in the script). In this way, "mypasprog" will look for the .so files in that directory.

lainz

  • Hero Member
  • *****
  • Posts: 3874
Re: PostgreSQL on Linux
« Reply #2 on: October 07, 2021, 05:00:21 pm »
Ok thanks, then better use the installed library.

There's a way to detect at runtime if the library is installed?

MarkMLl

  • Hero Member
  • *****
  • Posts: 3463
Re: PostgreSQL on Linux
« Reply #3 on: October 07, 2021, 07:12:43 pm »
I would strongly suggest using the libraries packaged by whatever distro you're using.

At that point you might find that the ordinary client package installs various .so files, but that you can benefit from (also) installing the developer package since it sets up a symlink from a more generic name to the specific files supplied:

Code: [Select]
$ locate libpq | grep /usr/lib/
/usr/lib/x86_64-linux-gnu/libpq.a
/usr/lib/x86_64-linux-gnu/libpq.so
/usr/lib/x86_64-linux-gnu/libpq.so.5
/usr/lib/x86_64-linux-gnu/libpq.so.5.11
/usr/lib/x86_64-linux-gnu/pkgconfig/libpq.pc

$ cd /usr/lib/x86_64-linux-gnu

$ find . -iname 'libpq*' -ls
 44092818    452 -rw-r--r--   1 root     root       462106 May 12 15:42 ./libpq.a
 44046882    296 -rw-r--r--   1 root     root       301040 May 12 15:42 ./libpq.so.5.11
 45620852      4 -rw-r--r--   1 root     root          319 May 12 15:42 ./pkgconfig/libpq.pc
 44092820      0 lrwxrwxrwx   1 root     root           13 May 12 15:42 ./libpq.so -> libpq.so.5.11
 44092832      0 lrwxrwxrwx   1 root     root           13 May 12 15:42 ./libpq.so.5 -> libpq.so.5.11

I believe that some of the pain has been reduced by the addition of a library loader component, but I've not investigated recently.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

devEric69

  • Hero Member
  • *****
  • Posts: 644
Re: PostgreSQL on Linux
« Reply #4 on: October 07, 2021, 09:41:30 pm »
I don't know PostgreSQL. Nevertheless, here are some informations:
- there is a short summary about the techniques on how to dynamically load a shared library from an *.elf application, on the *nixes, and on Linux in particular.
- there's a freeware named Debreate in order to create a binary installation package (*.deb), under Linux (in which one can code a bash script for example - #! /bin/bash -e - in its proposed post-install event, among other events; we can code inside an "un-gzip", an "un-tar" a tree-archive, create a soft-symlink, launch an "apt-get install *.deb" of an already existing and shipped\included binary package dropped inside the\your said current installation, ...).
- from one embedded to another, maybe: you could look at the installation discussions concerning the Firebird embedded applications. It's possible that the same recipes work with the embedded PostgreSQL version, too (that said, I don't know if you're using such an embedded PostgreSQL's version).
« Last Edit: October 07, 2021, 10:23:51 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

MarkMLl

  • Hero Member
  • *****
  • Posts: 3463
Re: PostgreSQL on Linux
« Reply #5 on: October 07, 2021, 11:11:29 pm »
I don't know PostgreSQL.

I do. Been using it on Linux for 20+ years. And the major gotcha (as far as clients are concerned) is that symlink.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018