vibhorkum / pg_background

pg_background
GNU General Public License v3.0
136 stars 35 forks source link

pg16beta1: could not find function pg_background_worker_main #47

Closed a-mckinley closed 9 months ago

a-mckinley commented 1 year ago

I was attempting to test pg_background on postgres 16beta1 and ran into the following issue. All statements appear to fail with the following message in the log:

2023-06-07 20:05:32.859 UTC [79] STATEMENT: select pg_backgroung_launch('select 1'); 2023-06-07 20:05:36.807 UTC [81] ERROR: could not find function "pg_background_worker_main" in file "/usr/lib/postgresql/16/lib/pg_background.so" 2023-06-07 20:05:36.808 UTC [1] LOG: background worker "pg_background" (PID 81) exited with exit code 1

Steps to reproduce are below.

FROM docker.io/library/postgres:16beta1
RUN apt -y install postgresql-server-dev-16 pkg-config libkrb5-dev
RUN apt install -y build-essential
RUN git clone https://github.com/vibhorkum/pg_background
RUN cd pg_background && git checkout v1.1
RUN cd pg_background && make install
docker build . -t pg_background_16
docker run -d -e POSTGRES_PASSWORD=testing --name=pg-bg-test pg_background_16
docker exec -it --user postgres pg-bg-test psql -c "create extension if not exists pg_background; select pg_background_launch('select 1');"
docker logs pg-bg-test | grep background
vibhorkumar123 commented 1 year ago

Yeah. it's not tested on version 16 yet.

vibhorkumar123 commented 1 year ago

So, I did a quick test with PostgreSQL 16 beta version. Below are the results

root@ip-20-0-10-44 pgsql]# export PATH=/usr/pgsql-16/bin:$PATH
[root@ip-20-0-10-44 pgsql]# which pg_config
/usr/pgsql-16/bin/pg_config
[root@ip-20-0-10-44 pgsql]# cd pg_background/
[root@ip-20-0-10-44 pg_background]# make distclean
rm -f pg_background.so   libpg_background.a  libpg_background.pc
rm -f pg_background.o pg_background.bc
rm -rf results/ regression.diffs regression.out tmp_check/ tmp_check_iso/ log/ output_iso/
[root@ip-20-0-10-44 pg_background]# make 
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -fvisibility=hidden -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal  -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include  -c -o pg_background.o pg_background.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -fvisibility=hidden -shared -o pg_background.so pg_background.o -L/usr/pgsql-16/lib  -Wl,--as-needed -L/usr/lib64 -L/usr/lib  -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-16/lib',--enable-new-dtags  -fvisibility=hidden 
/usr/bin/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -Xclang -no-opaque-pointers -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -O2  -I. -I./ -I/usr/pgsql-16/include/server -I/usr/pgsql-16/include/internal  -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include -flto=thin -emit-llvm -c -o pg_background.bc pg_background.c
[root@ip-20-0-10-44 pg_background]# make install
/usr/bin/mkdir -p '/usr/pgsql-16/lib'
/usr/bin/mkdir -p '/usr/pgsql-16/share/extension'
/usr/bin/mkdir -p '/usr/pgsql-16/share/extension'
/usr/bin/install -c -m 755  pg_background.so '/usr/pgsql-16/lib/pg_background.so'
/usr/bin/install -c -m 644 .//pg_background.control '/usr/pgsql-16/share/extension/'
/usr/bin/install -c -m 644 .//pg_background--1.0.sql  '/usr/pgsql-16/share/extension/'
/usr/bin/mkdir -p '/usr/pgsql-16/lib/bitcode/pg_background'
/usr/bin/mkdir -p '/usr/pgsql-16/lib/bitcode'/pg_background/
/usr/bin/install -c -m 644 pg_background.bc '/usr/pgsql-16/lib/bitcode'/pg_background/./
cd '/usr/pgsql-16/lib/bitcode' && /usr/bin/llvm-lto -thinlto -thinlto-action=thinlink -o pg_background.index.bc pg_background/pg_background.bc
[root@ip-20-0-10-44 pg_background]# 
[root@ip-20-0-10-44 pg_background]# 
[root@ip-20-0-10-44 pg_background]# sudo -iu postgres psql postgres
psql (16beta1)
Type "help" for help.

postgres=# create extension pg_background ;
CREATE EXTENSION
postgres=# \dt
Did not find any relations.
postgres=# select pg_background_launch('select 1');
 pg_background_launch 
----------------------
              2870181
(1 row)
a-mckinley commented 11 months ago

Hi, I just tested again with 16beta2.

I found the same as you in that pg_background_launch() appears to succeed but the underlying statement fails to execute.

For example:

postgres=# select pg_background_launch('vacuum');
 pg_background_launch 
----------------------
                   94
(1 row)

postgres=# select * from pg_background_result(94) as (result text);
ERROR:  lost connection to worker process with PID 94

And in the logs:

2023-07-31 14:53:57.478 UTC [94] ERROR:  could not find function "pg_background_worker_main" in file "/usr/lib/postgresql/16/lib/pg_background.so"
2023-07-31 14:53:57.479 UTC [1] LOG:  background worker "pg_background" (PID 94) exited with exit code 1
gsiz007 commented 11 months ago

Can you change line 116 in pg_background.c from void pg_background_worker_main(Datum); to PGDLLEXPORT void pg_background_worker_main(Datum); and test it ?

Thanks

a-mckinley commented 11 months ago

Looks good!

devrimgunduz commented 10 months ago

@vibhorkumar123 we need a new release for v16. It's due next week.

Regards, Devrim

vibhorkum commented 10 months ago

@devrimgunduz Please use the following release - https://github.com/vibhorkum/pg_background/releases/tag/v1.2

Thank you!

devrimgunduz commented 9 months ago

Thanks a lot! I confirm that it passes all tests.