Skip to main content

How to - Resetting a data container

When developing new features or trying to recreate issues with a database involved, returning the database to its starting point is often time consuming and challenging. Using Spawn data containers you can quickly and easily reset your data container, returning it to its starting state, including data and schema changes.

Spawn is currently in open beta. Complete the installation instructions to get access.

This is part of a series of short guides for getting up and running quickly with Spawn.

Data container reset graphic

Create and connect to a data container#

To explore the reset command, we first need a data container. If you don't have a data container available, you can follow this guide.

This example uses an empty PostgeSQL data container, but you can follow along with any type by modifying the connection and queries accordingly. Connect to your data container and examine the current state by finding out which tables exist. Connect using whatever tool you would normally for the database engine type you are working with.

$ psql -h -p 10001 -U <some_user_id>
Password for user <some_user_id>:
psql (10.5, server 11.0 (Debian 11.0-1.pgdg90+2))
<some_user_id>=# \dt
Did not find any relations.

In this case, the data container is empty so no tables exist.

Modify your data container#

Make a modification to the data container, in this example using the same session as the previous step.

<some_user_id>=# CREATE TABLE customers(id INT);
<some_user_id>=# \dt
List of relations
Schema | Name | Type | Owner
public | customers | table | <some_user_id>
(1 row)

There is now a table created in the data container that wasn't present when it was first created.

Reset your data container#

To return the data container to its initial state without modifications, run the reset command.

$ spawnctl reset data-container <data container name>
Successfully reset data container '<data container name>'

You can now reconnect to the data container (the connection details remain the same but the previous connection will have been terminated) and verify that it has returned to its initial state.

$ psql -h -p 10001 -U <some_user_id>
Password for user <some_user_id>:
psql (10.5, server 11.0 (Debian 11.0-1.pgdg90+2))
<some_user_id>=# \dt
Did not find any relations.

Using your data container#

Now you are able to create and reset data containers, other advanced actions are available such as save, graduate and load.