rubyrubygemsdatamapperubuntu-22.04postgres-12

`require': /var/lib/gems/3.0.0/gems/do_postgres-0.10.17/lib/do_postgres/do_postgres.so: undefined symbol: pg_fprintf


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

Solution

  • 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