Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

How is it possible to lock all access to the db while resetting the db in production ?

Hello,

For some reasons, I need to add a button to let the user reset the entire database.

But it's a real time application and messages come from RabbitMQ and are handled by the application and needs to access to the DB.

RabbitMQ and the other services have to continue running while resetting the database.

How can I do to avoid the application to throw errors during resetting the DB ?

I have these ideas :

  • set a RESETTING_DATABASE flag in the session

  • handle the messages from RabbitMQ only if the flag is true

  • set the flag to false, reset the database, set the flag to true

Do you see any other ways to do that ?

Thanks for your help.

V

0 likes
5 replies
Snapey's avatar

Pause all queue workers?

(and scheduled jobs)

1 like
MohamedTammam's avatar

@Snapey I guess there's going to be a wait time before it throws the error Lock wait timeout exceeded. I didn't face it before so I'm not 100%.

Maybe @Tray2 can add knowledge to this.

1 like
Tray2's avatar
Tray2
Best Answer
Level 73

Not sure what you mean by resetting the whole database, are we talking a full php artisan migrate:fresh --seed?

Like @snapey says, make sure to stop all the jobs reading from the queue before changing anything in the database, a simple maintenance global that is checked by all the jobs that reads the queues.

if (! $maintenance) {
	fetchContractFromQueue($contract);
}    	
1 like

Please or to participate in this conversation.