Resetting a Data Container allows you to remove all changes (schema and data) made to it since the last revision. This is useful when you want to discard the last changes you have made, especially ones that would be difficult to revert otherwise (e.g. dropping a table with data).
Reset a data-container with id
Reset a data-container with name
Reset multiple data-containers with ids
Reset multiple data-container with names
In this tutorial we will create a Data Image, then create a Data Container from that image. We'll then make some changes to the Data Container (or database) followed by a
reset operation. We will finally inspect the state of this Data Container.
As a prerequisite you should've followed the instructions to install spawnctl
Create a file
development.yamlwith your Data Image specifications.sourceType: emptyname: devengine: postgresqlversion: 11.0
In this case we want to create a PostgreSQL Data Image that is completely empty and is named
Run the following command to create a Data Image.$ spawnctl create data-image -f ./development.yamlData image 'dev' created!
You can verify your Data Image by running the following command.$ spawnctl get data-imagesNAME IMAGE ID ENGINE STATUS MESSAGE CREATEDdev 10001 PostgreSQL 2 Created 2 minutes ago
Create a Data Container from the newly created Data Image.$ spawnctl create data-container --image devData container 'dev-rambbomj' created!-> Host=instances.spawn.cc;Port=53223;User ID=<some_user_id>;Password=<some_password>;
You can verify your Data Container was properly created by running the following command.
Notice the created Data Container has revision
rev.0.$ spawnctl get data-containersNAME CONTAINER ID REVISION STATUS MESSAGE ENGINE CREATEDdev-rambbomj 10001 rev.0 2 Running PostgreSQL 1 minute ago
You should now be able to connect to your database and execute queries.
In this example we connect to the PostgreSQL Data Container (database) using psql.$ psql -h instances.spawn.cc -p 53223 -U <some_user_id>Password for user <some_user_id>:psql (10.5, server 11.0 (Debian 11.0-1.pgdg90+2))SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)Type "help" for help.<some_user_id>=# CREATE TABLE customers(id INT);CREATE TABLE<some_user_id>=# \dtList of relationsSchema | Name | Type | Owner--------+-----------+-------+------------------public | customers | table | <some_user_id>(1 row)
We can now perform a reset operation on this Data Container.$ spawnctl reset data-container dev-rambbomjData container 'dev-rambbomj' reset!
You can now connect to this Data Container (database) and verify its content.$ psql -h instances.spawn.cc -p 53223 -U <some_user_id>psql (10.5, server 11.0 (Debian 11.0-1.pgdg90+2))SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)Type "help" for help.<some_user_id>=# \dtDid not find any relations.
Notice that there are no relations even though we just added the table
customers. This is because all data changes that happened after our last save are removed and the Data Container is restarted for the data at that checkpoint.