Outdated Version

You are viewing an older version of this section. View current production version.

Database

Within a MemSQL instance, users can create one or more databases. These databases all reside in the MemSQL cluster, with data sharded across nodes.

Database States

The SHOW DATABASES command with the EXTENDED option adds extra information per-database on top of the standard SHOW DATABASES output. The state column conveys the state of each database with respect to replication and recovery. A MemSQL database is in one of the following eight states:

State Description
online The database is available for read and write queries. This is the default state after creating a new database. This is the only state in which a database can be a replication master. A database cannot be a replica in this state.
provisioning Not available for read or write queries. This is the first state after running REPLICATE DATABASE. During this state, the database is a replica and is currently downloading and replaying a snapshot file from the replication master. Once the snapshot has been successfully downloaded and replayed, the database will transition to the replicating state.
replicating Available for read but not write queries. The database is a replica and is continually downloading and replaying committed transactions from the replication master. To find the lag between primary and secondary you can use SHOW REPLICATION STATUS.The exception is child aggregators, where databases show up as replicating but are in fact available for write queries.
pending Not available for read or write queries. The database has finished recovering and is waiting for the master aggregator to attach it back into the cluster as a partition database or reference database. The database state will move to replicating or online once the master aggregator has finished attaching it.
recovering Not available for read or write queries. This is the immediate state after starting MemSQL. The database is currently recovering from snapshot and log files on disk. Once all data is recovered, the database will transition to replicating (if it’s a replica) or online (if it’s not a replica). If the end of the transaction log is corrupted (e.g. due to power loss) and the database is not a replica, then the database will transition to offline.
offline Not available for read or write queries. You can use the REPAIR DATABASE command to repair the end of the transaction log and database will transition to online. As of MemSQL 4.0, the REPAIR DATABASE command will be executed automatically if an offline database is found during recovery to bring the database online.
unrecoverable Not available for read or write queries. The database enters this state if recovery of the snapshot fails. Such a failure occurs if MemSQL runs out of memory while loading the snapshot or if the snapshot file is damaged. The REPAIR DATABASE dbName command cannot be used in this state. If the database is a replica, you can force re-provisioning by running DROP DATABASE and then restarting replication with REPLICATE DATABASE dbName FROM ....