0

I got this error after upgrading to ubuntu 22.04 from 20.04, what should I do to fix this?

<internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require': /var/lib/gems/3.0.0/gems/do_postgres-0.10.17/lib/do_postgres/do_postgres.so: undefined symbol: pg_fprintf - /var/lib/gems/3.0.0/gems/do_postgres-0.10.17/lib/do_postgres/do_postgres.so (LoadError)
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
         from /var/lib/gems/3.0.0/gems/do_postgres-0.10.17/lib/do_postgres.rb:27:in `<top (required)>'
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
         from /var/lib/gems/3.0.0/gems/dm-postgres-adapter-1.2.0/lib/dm-postgres-adapter/adapter.rb:1:in `<top (required)>'
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
         from /var/lib/gems/3.0.0/gems/dm-postgres-adapter-1.2.0/lib/dm-postgres-adapter.rb:1:in `<top (required)>'
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:160:in `require'
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:149:in `require'
         from /var/lib/gems/3.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:163:in `load_adapter'
         from /var/lib/gems/3.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:133:in `adapter_class'
         from /var/lib/gems/3.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:13:in `new'
         from /var/lib/gems/3.0.0/gems/dm-core-1.2.1/lib/dm-core.rb:230:in `setup'
         from /test/models/db/schema.rb:8:in `<top (required)>'
         from /test/tcpserver.rb:7:in `require_relative'
         from /test/tcpserver.rb:7:in `<main>'
 <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- dm-postgres-adapter (LoadError)
         from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
         from /var/lib/gems/3.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:163:in `load_adapter'
         from /var/lib/gems/3.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:133:in `adapter_class'
         from /var/lib/gems/3.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:13:in `new'
         from /var/lib/gems/3.0.0/gems/dm-core-1.2.1/lib/dm-core.rb:230:in `setup'
         from /test/models/db/schema.rb:8:in `<top (required)>'
         from /test/tcpserver.rb:7:in `require_relative'
         from /test/tcpserver.rb:7:in `<main>'

What I've tried:

sudo apt remove postgres-14 
sudo apt install postgres-server-dev-12
gem uninstall do_postgres
gem install do_postgres

but still got the same error, maybe because libpq-dev using 14 instead of 12? and I can't find version 12 anywhere

root@data:~# dpkg -l | grep postgres
ii  postgresql-12                         12.12-0ubuntu0.20.04.1                  amd64        object-relational SQL database, version 12 server
ii  postgresql-client-12                  12.12-0ubuntu0.20.04.1                  amd64        front-end programs for PostgreSQL 12
ii  postgresql-client-common              238                                     all          manager for multiple PostgreSQL client versions
ii  postgresql-common                     238                                     all          PostgreSQL database-cluster manager
ii  postgresql-doc-12                     12.12-0ubuntu0.20.04.1                  all          documentation for the PostgreSQL database management system
ii  postgresql-server-dev-12              12.12-0ubuntu0.20.04.1                  amd64        development files for PostgreSQL 12 server-side programming
root@data:~# dpkg -l | grep libpq
ii  libpq-dev                             14.5-0ubuntu0.22.04.1                   amd64        header files for libpq5 (PostgreSQL library)
ii  libpq5:amd64                          14.5-0ubuntu0.22.04.1                   amd64        PostgreSQL C client library

Tried downgrading libpq to 12

wget http://security.ubuntu.com/ubuntu/pool/main/p/postgresql-12/libpq-dev_12.12-0ubuntu0.20.04.1_amd64.deb
wget http://security.ubuntu.com/ubuntu/pool/main/p/postgresql-12/libpq-dev_12.12-0ubuntu0.20.04.1_amd64.deb
sudo dpkg -i libpq*.deb
root@data:~# dpkg -l | grep libpq
ii  libpq-dev                             12.12-0ubuntu0.20.04.1                  amd64        header files for libpq5 (PostgreSQL library)
ii  libpq5:amd64                          12.12-0ubuntu0.20.04.1                  amd64        PostgreSQL C client library
gem uninstall do_postgres
gem install do_postgres

also got the same error

root@data:~# ldd /var/lib/gems/3.0.0/gems/do_postgres-0.10.17/lib/do_postgres/do_postgres.so | grep pq
        libpq.so.5 => /lib/x86_64-linux-gnu/libpq.so.5 (0x00007fb756725000)
root@data:~# ls -al /lib/x86_64-linux-gnu/libpq.so.5
lrwxrwxrwx 1 root root 13 Aug 12 02:54 /lib/x86_64-linux-gnu/libpq.so.5 -> libpq.so.5.12
root@data:~# ls -al /lib/x86_64-linux-gnu/libpq.so.5.12
-rw-r--r-- 1 root root 321672 Aug 12 02:54 /lib/x86_64-linux-gnu/libpq.so.5.12
root@data:~# strings /lib/x86_64-linux-gnu/libpq.so.5.12 | grep pg_fprintf # no result
Kokizzu
  • 24,974
  • 37
  • 137
  • 233

1 Answers1

0

Downgrading to ruby2.7 fixes this issue:

sudo ln -sf ruby2.7 /usr/bin/ruby # previously pointing to ruby3.0
gem uninstall do_postgres
gem install do_postgres
Kokizzu
  • 24,974
  • 37
  • 137
  • 233
  • 1
    The latest version of the `do_postgres` is six years old. And that was only a bug fix to a minor version that is 13 years old. The [docs for that gem](https://www.rubydoc.info/gems/do_postgres/0.10.17) tell that the gem was tested with Ruby 1.8.6/7 and 1.9. I am actually surprised that it still works on Ruby 2.7. Because even support for Ruby 2.7 will end in five months, I highly advise switching to a Postgres gem that is still maintained and updating your application to an up-to-date Ruby version. – spickermann Nov 02 '22 at 07:16
  • yup might as well rewrite in Golang (I rewrite most of the code 5 years ago except this part), since this is the only Ruby code left XD the part that already serverd for 8 years without problem – Kokizzu Nov 02 '22 at 07:26