In order to Spawn a database to work against, you'll need to create a data container. A data container is created from a data image.
You can specify a lifetime for a data container via the
lifetime flag. This will automatically delete your data container after the time specified, in time duration format (number followed by a unit suffix. Valid units are "h", "m", "s").
If no value is provided, your data container will have an unlimited lifetime, and will only be deleted if you explicitly request it.
You can update data containers after creation to alter their lifetime
In this tutorial we will create a data image and then use it to create a 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' (10001) 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 dev --lifetime 1h30mData container 'dev-rambbomj' (10001) 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.$ spawnctl get data-containersNAME CONTAINER ID REVISION STATUS MESSAGE ENGINE CREATED EXPIRES ATdev-rambbomj 10001 rev.0 2 Running PostgreSQL 1 minute ago 1 hour from now
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)