Skip to main content
Topic: Ruby data_mapper gem w/ Postgres error (Read 671 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Ruby data_mapper gem w/ Postgres error

My first post as this is my first Artix install... on a "backup" laptop.  I want to make sure it works ok before i dump the O/S (Pop!OS) on my main laptop.  Anyway, i have ruby scripts that i've written that access a postgresql database.  This requires installing a bunch of gems -- data_mapper, of course,  and also dm-postgres-adapter and do_postgres.

Everything seemed to build and install ok but when i run my scripts, i get an error (from the do_postgres extension) saying that the symbol pg_fprintf is not found.  I've reinstalled and rebuilt all these gems multiple times, without any change in behavior.  There's a pg_conf.h file in the gem extension directory for do_postgres which i've altered a bit (lines that specify whether snprintf is defined or not) and then run make, but the do_postgres.so library always comes out exactly the same (diffing), so that turned out to be a dead end.  Searching for *any* (potentially relevant) file that actually contains a reference to pg_fprintf turns up nothing.  (The closest thing was the snprintf i found, and that -- the idea that it was related -- was a long shot.)

I've searched quite a bit for any sort of clue as to what is going on but have found zip.  Unfortunately, i don't understand the way gems (which i've always thought were an abomination from a design standpoint) load their required files.   I've stepped through the debugger for at least a couple of hours and ended up none the wiser.  The error i see is a failure to load 'do_postgres', ostensibly because of pg_fprintf not being found.  But the 'throw' comes from the load failure itself.

It's been a couple of weeks that i've been stuck at this point, which is not looking good for Artix as my next O/S.  Any help would be greatly appreciated because, except for this, i'm really liking Artix.  The install went smoothly, everything seems to work well.  The only real glitch was being unable to move or resize any window immediately after installing, but that was resolved fairly easily.
 

Re: Ruby data_mapper gem w/ Postgres error

Reply #1
Looking at similar errors, pg_fprintf seems to be from postgres
https://github.com/postgres/postgres/search?q=pg_fprintf
https://bugzilla.redhat.com/show_bug.cgi?id=1849884
https://bugzilla.redhat.com/show_bug.cgi?id=1849884

So I guess you have to include that somehow. There was also some mention in one of those bug reports that Ubuntu which pop!os is based on uses different locations for the relevant items.

Re: Ruby data_mapper gem w/ Postgres error

Reply #2
I had found that first link... but didn't know what to make of it.  All i could think of was that Postgres binaries are going to have that compiled in.  So...???  But the following two links seem promising.  Thanks much.  I'll be working on those leads tomorrow.

Re: Ruby data_mapper gem w/ Postgres error

Reply #3
If it is saying "SYMBOL" not found then it could be referring to something in a .so file rather than a header include.
/usr/lib/postgresql/pg_prewarm.so seems to be the one with pg_fprintf in it, part of the postgresql package.
Ubuntu seems to use a different location, where 12 is the package version:
/usr/lib/postgresql/12/lib/pg_prewarm.so

Re: Ruby data_mapper gem w/ Postgres error

Reply #4
Yes, it is a runtime error, occurring because the .so file contains an invocation of pg_fprintf somewhere.  I presume the library is loaded dynamically, so the missing symbol isn't noticed until the library is needed and loaded.  That's how it behaves, anyway.

I solved the problem, thanks to the link proferred in the initial response (##...).  I referred to the links as "promising" but it turns out (to those who have eyes) that the two links were exactly the same.  It offered a good explanation as to why the problem occurred... not *supposed* to include "postgresql.h" which (presumably) redefines printf's to pg_printf's when this isn't desired in an extension like this.  The linked post stated that you could try to solve the problem by linking in the missing function but you don't want to go down that road.  That was the most valuable bit of info in the post.  So that left just trying to get that symbol out of there.  The idea that replacing "postgresql.h" with more appropriate header files would solve this, though, was over-optimistic (the writer said they hadn't tried it).  I tried everything, getting it to compile cleanly with different headers.  But that damn symbol always ended up in the .so anyway.  So, i turned verbose on in the makefile, ran the same compile line for do_postgres.c code, except using -E instead of producing an object file.  I then edited the preprocessed output to replace all the pg_fprintf's with fprintf's, renamed this file to do_postgres.c and continued with the make and, presto, everything now works.

I could see from the preprocessed output where the pg_fprintf's were, and the context, but it was way too much of a tangle to figure out what, properly, to do about it.  For a moment i thought the bug might be in the extension writer's code, but then i changed my mind.  It seems more likely that it's in the Artix Postgres packages.  I've built the exact same everything on my Pop!OS system and all the ruby gems are exactly the same version, but i didn't have any problems on Pop!OS.  The do_postgres gem hasn't been updated since 2016.  But it still builds and works perfectly on the current Pop!OS and, before, on my Debian system (lost, less than a year ago, to drive corruption).

My "complaints" now, about Artix, are that, once i got my ruby stuff running, i found that Artix has no "keylaunch" package, which many other distributions do.   *And*... the first missing package i encountered (missed?) was "most".  I looked all over for that, right at the start.  Now, i've adapted to "less".  It's better than i remembered.  But... no "most"???  How can that be?  Most is the best.  :-)

Re: Ruby data_mapper gem w/ Postgres error

Reply #5
most is in the Arch repo "extra" which can be enabled if desired as per the Artix wiki repo guide:
extra/most 5.1.0-2
    A terminal pager similar to 'more' and 'less'
keylaunch seems to be related to the oroborus project but the home page for that appears to no longer exist. Searching on GitHub for keylaunch found this though, an old PKGBUILD:
https://github.com/aur-archive/keylaunch/blob/master/PKGBUILD
It looks like it uses a Debian package as source material. Given the age of this you might need to tweak something, keylaunch itself seems to have not been updated for many years.
Glad you got the pg_fprintf thing to work, it also appears in the header files in /usr/include/postgresql, perhaps those could be relevant too. Sometimes new versions move header file contents about or one header stops including another so you have to add an extra include when you didn't before.

Re: Ruby data_mapper gem w/ Postgres error

Reply #6
This is off-topic now but, initially, missing "most", i found it in this Arch repo:
https://archlinux.org/packages/extra/x86_64/most/

I then followed some instructions to add Arch to the repos my Artix system knows about.
After doing that, i searched for "most" (pacman -Ss, probably) and never got any indication that it was now available.  This was virtually my first exposure to pacman (quite different from apt-get/aptitude) and when it didn't work i just moved on because i had no real idea what i was doing.  Didn't even know whether i should have properly expected it to show up in my  searches.

I'll be getting back to this now, but the learning curve for pacman, coming from the Debian world, is not insignificant.
Maybe if my naivete, coming from the Debian world, is putting false assumptions in my head, someone can straighten me out.

As far as keylaunch, i just (back when) grabbed the simplest key configuration program i could find, wanting to globally remap keys for use in my music player application (those ruby scripts).  The best solution for this -- given what #### found re this app -- would seem to be just to find a suitable substitute.

Thanks for the help, btw.

Re: Ruby data_mapper gem w/ Postgres error

Reply #7
https://wiki.artixlinux.org/Main/Repositories
If you carefully follow the short instructions on the Artix wiki (other instructions might be outdated or not for Artix) then it ought to work, perhaps you should run pacman -Sy afterwards before trying -Ss, and -Syu before installing anything new from the repos is usually advisable. Look carefully at the example /etc/pacman.conf as both the [reponame] and include lines need to be uncommented, also the artix-archlinux-support package needs to be installed.

Installing keylaunch is simple too, testing it shows the PKGBUILD does still work:
Code: [Select]
$ mkdir 2
$ cd 2
$ git clone https://github.com/aur-archive/keylaunch.git
$ cd keylaunch/
$ ls
PKGBUILD
$ makepkg
$ sudo pacman -U keylaunch-1.3.9-1-x86_64.pkg.tar.zst
$ keylaunch --help
Could not open the configuration.

keylaunch 1.3.9
2021 (c) Stefan Pfetzing <[email protected]>
Usage: (null)
keylaunch, has no Options at all.
You will need to create a ~/.keylaunchrc in order to use it.
But no idea how it works or what a .keylaunchrc should contain, hopefully you know that part  :D
The Arch (not Artix) wiki has some helpful pages explaining more about pacman and also makepkg, which is the fundamental command line tool used to build things quickly and easily from PKGBUILD's.

 

Re: Ruby data_mapper gem w/ Postgres error

Reply #8
Thankee, thankee, thankee...

The page on repository info that ###... gave a link to was what i had followed.  The problem was that, when it spat out its output of repo lines to add to pacman.conf, i did not know that i had to actually add them manually.  I'm curious as to whether installation of the 'artix-archlinux-support' package does more than just output these lines?  I suppose it does but have no idea what.

Doing that, and then running 'pacman -Syu most', and it was installed and working.

I then simply followed the instructions given for making 'keylaunch' (needing to install 'git' and 'fakeroot' along the way) and that worked perfectly, as well.

Again, many thanks for the help.  I am now ready, i think, to wipe Pop!OS off my main laptop and install Artix there as well, seeing how everything is working so very nicely.  What a relief that will be, as i hate Gnome with a passion.  :-)  (Not to mention systemd... which, while an evil trojan horse, at least doesn't annoy you or cause problems with every window switch or inadvertant keypress.)