Quickstart with ReadySet
This page shows you how to run ReadySet against a Postgres or MySQL database.
Tip
For a walk-through of ReadySet's capabilities and features, see the ReadySet Demo instead.
Before you begin
- Install and start Docker for your OS.
- Install the
psql
shell or themysql
shell.
Step 1. Configure your database
If you don't already have a Postgres or MySQL database running locally, start a new database and load some sample data.
-
Create a Docker container and start Postgres inside it:
docker run -d \ --name=postgres \ --publish=5432:5432 \ -e POSTGRES_PASSWORD=readyset \ -e POSTGRES_DB=testdb \ postgres:14 \ -c wal_level=logical
This command starts the database with the correct configuration for ReadySet.
-
Download a sample data file:
-
Connect the
psql
shell to your database: -
Load the sample data into your database:
-
Create a Docker container and start MySQL inside it:
docker run -d \ --name=mysql \ --publish=3306:3306 \ -e MYSQL_ROOT_PASSWORD=readyset \ -e MYSQL_DATABASE=testdb \ mysql
This command starts the database with the correct configuration for ReadySet.
-
Download a sample data file:
-
Connect the
mysql
shell to your database: -
Load the sample data into your database:
ReadySet uses your database's replication stream to automatically keep your cache up-to-date as the database changes. In Postgres, the replication stream is called logical replication. In MySQL, the replication stream is called the binary log.
In this step, you'll ensure replication is enabled.
-
Connect the
psql
shell to your database, replacing the example values with your database connection details: -
Check if replication is enabled:
If
wal_level
islogical
, you're all set; skip to Step 2:If
wal_level
is set to any other value (for example,replica
), continue to the next step. -
Stop the database.
-
Restart the database with replication enabled:
Alternately, you can add the following to the
postgresql.conf
file and then restart the database:
-
Connect the
mysql
shell to your database, replacing the example values with your database connection details: -
Check if replication is enabled with the
ROW
logging format:If
log_bin
isON
andbinlog_format
isROW
, you're all set; skip to Step 2. Start ReadySet:+---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | ON | +---------------+-------+ 1 row in set (0.01 sec) +---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set (0.01 sec)
If either is set to any other value, continue to the next step.
-
Stop the database.
-
Restart the database with replication enabled and the logging format set to
ROW
:
Step 2. Start ReadySet
Create a Docker container and start ReadySet inside it, connecting ReadySet to the database via the connection string in --upstream-db-url
:
docker run -d \
--name=readyset \
--publish=5433:5433 \
--platform=linux/amd64 \
--volume='readyset:/state' \
--pull=always \
-e DEPLOYMENT_ENV=quickstart_docker \
-e RS_API_KEY \
public.ecr.aws/readyset/readyset:beta-2023-01-18 \
--standalone \
--deployment='quickstart-postgres' \
--database-type=postgresql \
--upstream-db-url=postgresql://postgres:readyset@172.17.0.1:5432/testdb \
--address=0.0.0.0:5433 \
--username='postgres' \
--password='readyset' \
--query-caching='explicit' \
--db-dir='/state'
docker run -d \
--name=readyset \
--publish=3307:3307 \
--platform=linux/amd64 \
--volume='readyset:/state' \
--pull=always \
-e DEPLOYMENT_ENV=quickstart_docker \
-e RS_API_KEY \
public.ecr.aws/readyset/readyset:beta-2023-01-18 \
--standalone \
--deployment='quickstart-mysql' \
--database-type=mysql \
--upstream-db-url=mysql://root:readyset@172.17.0.1:3306/testdb \
--address=0.0.0.0:5433 \
--username='root' \
--password='readyset' \
--query-caching='explicit' \
--db-dir='/state'
Create a Docker container and start ReadySet inside it:
Note
Be sure to update --upstream-db-url
, --username
and --password
with your database connection string and credentials.
docker run -d \
--name=readyset \
--publish=5433:5433 \
--platform=linux/amd64 \
--volume='readyset:/state' \
--pull=always \
-e DEPLOYMENT_ENV=quickstart_docker \
-e RS_API_KEY \
public.ecr.aws/readyset/readyset:beta-2023-01-18 \
--standalone \
--deployment='quickstart-postgres' \
--database-type=postgresql \
--upstream-db-url=postgresql://postgres:readyset@172.17.0.1:5432/testdb \
--address=0.0.0.0:5433 \
--username='postgres' \
--password='readyset' \
--query-caching='explicit' \
--db-dir='/state'
docker run -d \
--name=readyset \
--publish=3307:3307 \
--platform=linux/amd64 \
--volume='readyset:/state' \
--pull=always \
-e DEPLOYMENT_ENV=quickstart_docker \
-e RS_API_KEY \
public.ecr.aws/readyset/readyset:beta-2023-01-18 \
--standalone \
--deployment='quickstart-mysql' \
--database-type=mysql \
--upstream-db-url=mysql://root:readyset@172.17.0.1:3306/testdb \
--address=0.0.0.0:5433 \
--username='root' \
--password='readyset' \
--query-caching='explicit' \
--db-dir='/state'
For details about the readyset
command above, see the ReadySet Demo.
Next steps
-
Connect an app
Once you have a ReadySet instance up and running, the next step is to connect your application by swapping out your database connection string to point to ReadySet instead. The specifics of how to do this vary by database client library, ORM, and programming language. See Connect an App for examples.
Note
By default, ReadySet will proxy all queries to the database, so changing your app to connect to ReadySet should not impact performance. You will explicitly tell ReadySet which queries to cache.
-
Profile and cache queries
Once you are running queries against ReadySet, connect a database SQL shell to ReadySet and use the custom
SHOW PROXIED QUERIES
SQL command to view the queries that ReadySet has proxied to your upstream database and identify which queries are supported by ReadySet. Then use the customCREATE CACHE
SQL command to cache supported queries.Note
To successfully cache the results of a query, ReadySet must support the SQL features and syntax in the query. For more details, see SQL Support.
-
Tear down
When you are done testing, stop and remove the ReadySet container and volume:
If you started a new database, also stop and remove its container: