vibhorkum / pg_background

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

background query not executed with pg_background_detach(pg_background_launch('...')) #6

Open radist-nt opened 6 years ago

radist-nt commented 6 years ago

Steps to reproduce the problem:

  1. Open two sessions for database (S1 and S2)
  2. Execute LISTEN test_background; in S1
  3. Execute NOTIFY test_background, '1';select pg_background_detach(pg_background_launch('NOTIFY test_background, ''2'';')); in S2
  4. 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"

rjuju commented 3 years ago

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()