Install a package to a different location

Hi, all. I need to install postgresql18-{client,contrib,server} packages to a different location on a test machine, then copy all its files & directories to the needed machine, so that pg_upgrade from an earlier version of PG, which is installed there as packages, works. The pg_upgrade manual states this:


Code:
        3. Install the new PostgreSQL binaries: Install the new server's
           binaries and support files.  pg_upgrade is included in a default
           installation.

           For source installs, if you wish to install the new server in a
           custom location, use the prefix variable:

               make prefix=/usr/local/pgsql.new install

But this doesn't work. After some googling I changed prefix in the command above to be upper case PREFIX, and then do this:

Code:
cd /usr/ports/databases/postgresql18-client
sudo make PREFIX=/usr/local/pgsql.new install

But after the build completes it fails with many errors of this kind:

Code:
pkg-static: Unable to access file /usr/ports/databases/postgresql18-client/work/stage/usr/local/pgsql.new/lib/postgresql/pgxs/src/Makefile.shlib:No such file or directory
pkg-static: Unable to access file /usr/ports/databases/postgresql18-client/work/stage/usr/local/pgsql.new/lib/postgresql/pgxs/src/makefiles/pgxs.mk:No such file or directory
pkg-static: Unable to access file /usr/ports/databases/postgresql18-client/work/stage/usr/local/pgsql.new/lib/postgresql/pgxs/src/nls-global.mk:No such file or directory
pkg-static: Unable to access file /usr/ports/databases/postgresql18-client/work/stage/usr/local/pgsql.new/lib/postgresql/pgxs/src/test/regress/pg_regress:No such file or directory
pkg-static: Unable to access file /usr/ports/databases/postgresql18-client/work/stage/usr/local/pgsql.new/share/postgresql/postgres.bki:No such file or directory
pkg-static: Unable to access file /usr/ports/databases/postgresql18-client/work/stage/usr/local/pgsql.new/share/postgresql/system_constraints.sql:No such file or directory
pkg-static: Unable to access file /usr/ports/databases/postgresql18-client/work/stage/usr/local/pgsql.new/share/postgresql/pg_service.conf.sample:No such file or directory
pkg-static: Unable to access file /usr/ports/databases/postgresql18-client/work/stage/usr/local/pgsql.new/share/postgresql/psqlrc.sample:No such file or directory

My first idea was simply to install packages normally, and copy all their files (as determined by "pkg -l packagename") to the needed machine, it seemingly works, but there are library issues with needed symbols not being found in /usr/local/lib/libpq.so.5 which is from older postgresql-client package, while psql 18 depends on the file copied, and I couldn't get libmap.conf to make ldd happy and route that library to the new version's path).
 
Ok, after carefully reading libmap.conf manual I found what was wrong - I tested the executable with ldd using its relative path from the shell, such as ldd bin/psql, while listing its absolute path in libmap.conf. Feeding ldd with the absolute path worked, the library now points to the correct file, and this should work. Still wondering if it's possible to build a port so all its libraries are resolved from a certain build-time hard-coded library path.
 
But I guess patching up /etc/libmap.conf only for the PG's libraries is better, because PostgreSQL depends on too many 3-rd party ports which I'd have to install in the same temporary area.

Code:
/usr/local/lib/libicudata.so.76
/usr/local/lib/libicui18n.so.76
/usr/local/lib/libicuuc.so.76
/usr/local/lib/libintl.so.8
/usr/local/lib/liblz4.so.1
/usr/local/lib/libreadline.so.8
/usr/local/lib/libxml2.so.16
/usr/local/lib/libzstd.so.1
 
You can't install two versions in parallel - exactly because of those library issues you already encountered. This only works (somewhat, and only as an ugly hack) in linux-world where they mix and mash all kind of library versions (which *will* cause chaos at some point, hence why linux folks need docker for everything nowadays...) or if you manually move them around.
You *could* build the port of the new version with another PREFIX defined in the Makefile, but this way you'd need to remove and re-build/install it with the correct paths afterwards.

It's *much* easier to just use pg_dumpall & psql -X -f db.out -d postgres.

I usually set up a new jail for the new version and directly send the pg_dumpall stream to psql -f - on the new jail, which minimizes the downtime significantly (IIRC last time I moved ~25GB of databases to a new jail it took less than 10 minutes).
This way you also have your original, working database untouched and ready to go if there are any issues during the db-update or with the new version.
 
Back
Top