Upgrading a Heroku Key-Value Store Version
Last updated October 30, 2024
Table of Contents
Heroku Key-Value Store (KVS) defaults to the latest stable version of Valkey supported for the platform. Valkey is fully compatible with existing KVS add-ons and implementations. Newly created Heroku Key-Value Store instances always use the latest version, currently 7.2. See Version Support and Legacy Infrastructure for more version info.
There are two methods for upgrading an existing KVS add-on version:
- Upgrade in-place with the
heroku redis:upgrade
command. - Creating and promoting a new Heroku Key-Value Store add-on with
--fork
.
Performing an in-place upgrade is suitable for most cases.
For Premium, Private, and Shield plans, Heroku Key-Value Store version 6.0 and higher require TLS connections. You must configure your client to support TLS. This process can require updating and deploying your application before returning the app to normal operation.
For Mini plans, using TLS is optional, but encouraged via using the REDIS_TLS_URL
config var. Mini plans will require TLS connections on December 2, 2024.
For instructions on upgrading your Heroku Key-Value Store plan instead of its version, see Heroku Key-Value Store.
Upgrade Using redis:upgrade
If your plan is a production plan (everything but mini
), this command creates a maintenance that can then be run to perform an in-place upgrade of your KVS version. Internally, this process prepares a follower on the desired upgrade version and creates a maintenance that you trigger which promotes that instance as the leader.
If your addon is on a mini
plan the upgrade happens immediately without a maintenance, as mini
plans do not support maintenance windows.
When promoting the new instance, there’s a chance of data loss if your applications continue writing to KVS as the failover itself happens. To minimize this impact, put your app on maintenance mode and pause any jobs or external tasks that write to your KVS add-on.
Step 1: Prepare the Upgrade
The redis:upgrade
command prepares your add-on for upgrade and creates a maintenance for you to run:
$ heroku redis:upgrade redis-addon-name --version 7.2 --app example-app
▸ WARNING: Irreversible action.
▸ Redis database will be upgraded to 7.2. This cannot be undone.
▸ To proceed, type example-app or re-run this command with --confirm example-app
>example-app
Requesting upgrade of redis-addon-name to 7.2... Your Redis version is being upgraded to 7.2. The system is preparing a maintenance. Once the maintenance is ready you can run it with heroku data:maintenances:run. See: https://devcenter.heroku.com/articles/data-maintenance-cli-commands#heroku-data-maintenances-run.
If your addon is on a mini
plan, heroku redis:upgrade
triggers the upgrade immediately. For mini
plans, put your app in maintenance mode before this step if you need to minimize data loss.
Step 2: Wait for the Maintenance to Be Created
Install the Data Maintenance CLI plugin to run the heroku data:maintenances:info
command.
Using the heroku data:maintenances:info
command, you can confirm the maintenance has been created. It can take ~15 minutes for the system to prepare the maintenance depending on which version you’re upgrading from.
When the maintenance has been created, you see a maintenance with the status ready
.
heroku data:maintenances:info redis-addon-name -a example-app
Fetching maintenance... done
addon_attachments: REDIS_ADDON_URL
addon_description: premium HA
addon_kind: heroku-redis
addon_name: redis-addon-name
addon_plan: premium-0
addon_window: Tuesdays 18:30 to 22:30 UTC
app_name: example-app
method: failover
reason: customer_request
required_by: 2023-03-29T17:26:56.220+00:00
scheduled_for: 2023-03-14T18:30:00.000+00:00
server_created_at: 2023-03-01T16:51:27.021+00:00
status: ready
window: Tuesdays 18:30 to 22:30 UTC
Step 3: Prevent New Updates (Recommended)
When you’re ready to run the maintenance, minimize data loss by placing your app in maintenance mode to prevent writing new data to KVS during the upgrade. If you have scheduler jobs running, disable them.
$ heroku maintenance:on
Maintenance mode doesn’t automatically scale down any dynos. Scale down any non-web dynos, such as worker dynos for queueing jobs, to ensure that no connections are writing data to KVS.
Step 4: Perform Upgrade
You can perform an in-place upgrade of KVS by running the prepared maintenance:
$ heroku data:maintenances:run redis-addon-name --app example-app
Triggering maintenance... maintenance triggered
The maintenance takes a few seconds to complete. You know the maintenance is done when the info command shows the maintenance status as completed
.
heroku data:maintenances:info redis-addon-name -a example-app
Fetching maintenance... done
addon_attachments: REDIS_ADDON_URL
addon_description: premium HA
addon_kind: heroku-redis
addon_name: redis-addon-name
addon_plan: premium-0
addon_window: Tuesdays 18:30 to 22:30 UTC
app_name: example-app
completed_at: 2023-03-03T17:06:16.358+00:00
duration_approximate: ~ less than a minute
duration_seconds: 8
method: failover
reason: customer_request
required_by: 2023-03-31T17:02:32.773+00:00
scheduled_for: 2023-03-03T17:06:06.701+00:00
server_created_at: 2023-03-01T17:35:52.572+00:00
started_at: 2023-03-03T17:06:08.341+00:00
status: completed
window: Tuesdays 18:30 to 22:30 UTC
Step 5: Resume Normal Operation
If you turned on maintenance mode and downscaled your dynos in step 3, you must make your application active again.
To resume normal application operation, scale any non-web dynos back to their original levels. Then, turn off maintenance mode:
$ heroku maintenance:off
Upgrade Using a Fork
Step 1: Prevent New Updates
You must prevent new data from writing to your app during the upgrade process to ensure a complete data transfer to the new KVS instance. Place your app into maintenance mode. If you have scheduler jobs running, disable them.
$ heroku maintenance:on
Maintenance mode doesn’t automatically scale down any dynos. Scale down any non-web dynos, such as worker dynos for queueing jobs, to ensure that no connections are writing data to KVS.
Step 2: Create the Fork
After preventing new updates, create a fork of your KVS instance. You can obtain the connection info (rediss://:<password>@<hostname>:<port>
) of the current KVS instance by using heroku config:get REDIS_URL
. The following command creates a Heroku Key-Value Store add-on instance, forking the data from the URL of the old one:
The addons:create
example follows the syntax for Heroku CLI v9.0.0 or later. If you’re on v8.11.5 or earlier, use the command:
$ heroku addons:create heroku-redis:premium-0 --fork rediss://:<password>@<hostname>:<port> -a example-app
$ heroku addons:create heroku-redis:premium-0 -a example-app -- --fork rediss://:<password>@<hostname>:<port>
Creating heroku-redis:premium-0 on ⬢ example-app... $15/month
Your add-on is being provisioned and will be available shortly
redis-spherical-37410 is being created in the background. The app will restart when complete...
Use heroku addons:info redis-spherical-37410 to check creation progress
Use heroku addons:docs heroku-redis to view documentation
You can follow this process using heroku redis:info
.
Heroku recommends using encryption and uses a rediss://
URL instead of redis://
when creating a fork. Heroku Key-Value Store instances expose a rediss://
service on port 6480
instead of the cleartext port 6479
for most databases. For Mini, the ports are different, you can find the TLS connection string (including port) in the TLS_URL
config var.
The fork command doesn’t copy any customized settings, including eviction policies. For example, if you’ve customized the connection timeout using heroku redis:timeout
the timeout isn’t copied to the fork.
Step 3: Promote the Fork
After the data transferred to the forked instance, you must promote it. Confirm that the forked KVS instance is available with heroku redis:info
. Note the name of this instance from the output, for example, redis-spherical-37410
. Use this name to promote the fork:
$ heroku redis:promote redis-spherical-37410 -a example-app
Promoting redis-spherical-37410 to REDIS_URL on example-app
Promoting a forked KVS instance updates the REDIS_URL
config var, and restarts the application.
Step 4: Resume Normal Operation
To resume normal application operation, scale any non-web dynos back to their original levels. Then, turn off maintenance mode.
$ heroku maintenance:off
The old KVS add-on isn’t automatically removed from your application with version upgrades. If it’s no longer needed, remove it with heroku addons:destroy
.