Skip to content

BackgroundWorkerBuilder quietly registers broken workers #2160

Description

@cbandy

What happened

In the early stages of developing a background worker on Postgres 17.6, I built a worker that logged a few messages:

BackgroundWorkerBuilder::new("worker")
        .set_start_time(BgWorkerStartTime::PostmasterStart)
        .set_function("worker_main")
        .set_library("worker")
        .load();#[pg_guard]
#[unsafe(no_mangle)]
pub extern "C-unwind" fn worker_main(_arg: pg_sys::Datum) {
    log!("{} is starting", BackgroundWorker::get_name());
    log!("{} stopped", BackgroundWorker::get_name());
}

Postgres started successfully, but instead of my messages, Postgres logged:

[2025-10-22 00:21:52.679 CDT] [25769] [68f869f0.64a9]: LOG:  background worker "worker": background workers without shared memory access are not supported

I had to call enable_shmem_access(None) for Postgres to start the worker.

    BackgroundWorkerBuilder::new("worker")
        .set_start_time(BgWorkerStartTime::PostmasterStart)
        .set_function("worker_main")
        .set_library("worker")
        .enable_shmem_access(None)
        .load();
[2025-10-22 00:23:00.205 CDT] [26443] [68f86a34.674b]: LOG:  worker is starting

What I expected

  1. I expected my initial set of builder calls to produce a valid background worker.
  2. I expected an error when I produced a background worker that Postgres didn't like. The LOG level from Postgres honestly surprised me.

Other information

That message led straight to this discussion about why shmem access is necessary now: https://postgr.es/m/20210802065116.j763tz3vz4egqy3w@alap3.anarazel.de

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions