class optuna.storages.RDBStorage(url, engine_kwargs=None, skip_compatibility_check=False)[source]

Storage class for RDB backend.

Note that library users can instantiate this class, but the attributes provided by this class are not supposed to be directly accessed by them.


We create an RDBStorage instance with customized pool_size and max_overflow settings.

>>> import optuna
>>> def objective(trial):
>>>     ...
>>> storage = optuna.storages.RDBStorage(
>>>     url='postgresql://foo@localhost/db',
>>>     engine_kwargs={
>>>         'pool_size': 20,
>>>         'max_overflow': 0
>>>     }
>>> )
>>> study = optuna.create_study(storage=storage)
>>> study.optimize(objective)
  • url – URL of the storage.
  • engine_kwargs – A dictionary of keyword arguments that is passed to sqlalchemy.engine.create_engine function.
  • skip_compatibility_check – Flag to skip schema compatibility check if set to True.


If you use MySQL, pool_pre_ping will be set to True by default to prevent connection timeout. You can turn it off with engine_kwargs['pool_pre_ping']=False, but it is recommended to keep the setting if execution time of your objective function is longer than the wait_timeout of your MySQL configuration.