pg_background
pg_background copied to clipboard
background query not executed with pg_background_detach(pg_background_launch('...'))
Steps to reproduce the problem:
- Open two sessions for database (S1 and S2)
- Execute
LISTEN test_background;
in S1 - Execute
NOTIFY test_background, '1';select pg_background_detach(pg_background_launch('NOTIFY test_background, ''2'';'));
in S2 - Execute
SELECT;
in S1
Expected result: two notification messages with payloads 1 and 2 in S1. Actual result: single notification message with payload 1.
Looks like pg_background_detach terminates pg_background_launch call (with rollback). Inserting pg_sleep(0.1) between pg_background_launch and pg_background_detach solves the problem.
PostgreSQL version: "PostgreSQL 9.6.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11), 64-bit"
Hi,
As far as I can see this is the same problem as reported in https://github.com/vibhorkum/pg_background/issues/1, as the logs show:
2021-05-16 23:04:07.711 CST [27600] ERROR: unable to map dynamic shared memory segment
2021-05-16 23:04:07.713 CST [26820] LOG: background worker "pg_background" (PID 27600) exited with exit code 1
So until this problem is fixed, you can either avoid to call pg_background_detach()
, or call instead pg_background_result()