0

I understand there are very many stackoverflow questions on this very topic.

How can get my site out of maintenance mode? for example.

However I've never seen one that explains how to turn off maintenance mode using only a database query. I run a complex site that does not allow you to login directly using /user since it's using a special sso. So there are times when I do not have access to the admin area and I do not have access to the user login either. I don't always have ssh access to run drush, but I do usually have direct access to the mysql database.

I did find an entry in the config table that seems related.

The name is system.maintenance and the data is

a:3:{s:7:"message";s:93:"@site is currently under maintenance. We should be back shortly. Thank you for your patience.";s:8:"langcode";s:2:"en";s:5:"_core";a:1:{s:19:"default_config_hash";s:43:"Z5MXifrF77GEAgx0GQ6iWT8wStjFuY8BD9OruofWTJ8";}}

I see where it shows the message, langcode and hash settings but I do not see where it defines whether it's on or off.

Is there a location in the database that would allow me to turn maintenance mode on and off directly?

3
  • 1
    You can’t do it with a direct query, the data is stored in a php serialised string. It requires php to unserialise it (hence the standard solutions being via php like drush or the admin area). You could manually get the data, manually unserialise it, and manually put it back again - but that’s just a SELECT followed by an UPDATE in terms of sql
    – Clive
    Commented Feb 14, 2019 at 17:51
  • 1
    Actually that might be too simplistic - I think maintenance mode is a state var, which means it’s probably in the key_value or key_value_expire table as a single row. You’ll probably still need to unserialise and reserialise the data with php, but it’ll be slightly easier than updating a whole complicated array
    – Clive
    Commented Feb 14, 2019 at 17:54
  • @Clive I don't mind manually serializing and unserializing things, or manipulating multiple tables. I can do whatever I need with a local php script if necessary. I mainly want to know if it's physically possible and what tables would be involved.
    – Amy
    Commented Feb 14, 2019 at 18:00

1 Answer 1

3

It's never the best idea to manipulate the database directly (for the usual reasons), but if you're out of other options, it's not that unsafe:

UPDATE key_value 
SET value = '<value>' 
WHERE collection = 'state' 
AND name = 'system.maintenance_mode'

Where <value> is replaced with a serialised PHP string representing the integer value 1 for enabled, or 0 for disabled, e.g.

$value = serialize(1);

You'll probably want to invoke a cache rebuild after manually updating the variable, it's probably cached somewhere.

1
  • 1
    Turns out a cache rebuild is not necessary. Thanks!
    – Amy
    Commented Feb 14, 2019 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.