Skip to content

PGMQ queue creation fails on preview branch reset: relation "pgmq.q_my_queue_msg_id_seq" does not exist #4492

Closed as not planned

Description

@ToJen

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When resetting a Supabase preview branch, PGMQ queue creation fails with a sequence-related error. The pgmq.create() call for a queue (e.g., my_queue) references a sequence (pgmq.q_my_queue_msg_id_seq) that doesn't exist, causing the migration to fail.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a preview branch with migrations that create PGMQ queues:
   CREATE EXTENSION IF NOT EXISTS pgmq;
   SELECT pgmq.create('my_queue');
   SELECT pgmq.create('my_queue_dlq');
  1. Let the branch build successfully (first build works).
  2. Reset the preview branch via the Supabase dashboard.
  1. The branch rebuilds and the migration fails.
  2. View the logs of the latest build
  3. See error

Expected behavior

  • Queues should be created successfully on branch reset.
  • PGMQ extension state should be consistent after reset.
  • No sequence-related errors should occur.

Actual behavior

  • Migration fails with:
  ERROR: relation "pgmq.q_my_queue_msg_id_seq" does not exist (SQLSTATE 42P01)
  At statement: 786
  SELECT pgmq.create('my_queue_dlq')
  • The first queue (my_queue) may be created, but the second queue (my_queue_dlq) fails.
  • This only occurs on branch reset, not on first build or new commits.

System information

  • Supabase: Preview branch reset functionality
  • PGMQ extension: Latest version (via CREATE EXTENSION IF NOT EXISTS pgmq)
  • Migration file: Baseline migration or any migration creating PGMQ queues

Activity

  1. ToJen commented on Nov 21, 2025

    @ToJen
    Author

    Hey @sweatybridge, any thoughts on this

  2. sweatybridge commented on Nov 24, 2025

    @sweatybridge
    Contributor

    Can you show me the full migration file that you are trying to apply? The error happens at statement 786 but your example only has 3 statements.

  3. kallebysantos commented on Nov 24, 2025

    @kallebysantos
    Member

    Hi @sweatybridge
    I believe this issue is related with platform branching, not the migrations command 😕
    So probably the user doesn't have access to full the migration script

  4. ToJen commented on Nov 24, 2025

    @ToJen
    Author

    Hi @sweatybridge it's not about migrations but rather about a behaviour of the Preview Branches. Once the extension pgmq has been enabled and a queue has been created and the preview branch is restarted, that error always happens.

    I've described the steps to reproduce. You could even run the CREATE EXTENSION IF NOT EXISTS pgmq inside the SQL Editor and the create a queue. Then restart the preview branch. It's not a migrations issue.

  5. sweatybridge commented on Nov 24, 2025

    @sweatybridge
    Contributor

    Could you share your postgres version and project ref?

    I tried reproducing here but to no avail. https://github.com/qiao-supabase/branching-demo/pull/25/files

    Migrations ran successfully on every reset of preview branch.

  6. ToJen commented on Nov 27, 2025

    @ToJen
    Author

    Made a mistake when cleaning different migrations files. I hadn't enabled pgmq and created the queue at the right position before using it.

  7. ToJen commented on Nov 27, 2025

    @ToJen
    Author

    Looks like the issue has returned @sweatybridge @kallebysantos. It tends to happen when a branch is left active overnight. Also, I rebased my local feature branch and git push --force-with-lease to the remote feature branch. Then the Supabase Preview Branch integration triggered the branch rebuild then the same error happened again. I think something isn't being properly cleared/restored by Supabase for the pgmq extension.

  8. reopened this on Nov 27, 2025
  9. qualitate-samparl commented on Dec 1, 2025

    @qualitate-samparl

    We experience this as well. It seems as though the CLI command supabase db reset isn't properly resetting the pgmq schema. We testing the fix and updated an old migration by adding the extra line DROP SCHEMA IF EXISTS pgmq CASCADE; before running CREATE EXTENSION IF NOT EXISTS pgmq;. Now we can reset our branches without issue.

  10. dumko2001 commented on Mar 8, 2026

    @dumko2001

    Hey @sweatybridge, I've tracked this down to a side effect of how pgmq is excluded in drop.sql. Because PR #3043 added pgmq to the exclusion loop in drop.go and drop.sql, branch resets refuse to clean up the queue tables, leaving them orphaned for the next migration run.

    Similarly, the sed replacement in dump_schema.sh from PR #4391 strips WITH SCHEMA "pgmq". This installs pgmq into public on Branch copies, causing issue #40666.

    I have submitted PR #4940 to cleanly resolve both of these problems by removing the pgmq exclusions from drop.sql (so resets successfully drop the queues) and fixing the sed syntax to include CREATE SCHEMA IF NOT EXISTS "pgmq"!

    Unlike PR #4471, PR #4940 does not add any custom Go-level retries or extension management; it strictly reverts the unintended schema exclusions.

  11. added and removed
    bugSomething isn't working
    on Apr 20, 2026
  12. github-actions commented on Jun 17, 2026

    @github-actions
    Contributor

    Hi! Thanks for opening this issue.

    We're closing this because it has not had any activity for 45 days, and we try to keep the Supabase CLI issue tracker focused on reports that are still current.

    If this still reproduces on the latest Supabase CLI, please comment with /reopen on its own line and include your CLI version, updated reproduction steps, and any recent error output. We appreciate the signal and are happy to take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stale-closedIssue closed by stale cleanup.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions