Does Temporal upgrade DB schemas automatically?

For example, going from temporalio/server:1.19.1 to 1.20.1

I’m not clear if I need to manually run “auto-setup” again when upgrading, or if it does DB updates automatically (if needed).

I think because these are consecutive (1.19 → 1.20) we don’t need to do anything special here and can just switch out the container image tag - is that right?

Many thanks

The docker image you update to includes the latest version binary and schema files. After update image version you should only need to update the existing schema, see for example here. I believe if you are running auto-setup, the script should take care of that part.

That’s what I’m confused about. I used the auto-setup images while provisioning the server. Now we’re in run mode I switched to the “plain” server docker images (i.e. temporalio/server:1.19.1)

So if I just swapped to temporalio/server:1.20.1, it would not automatically run the schema updates? Should we use the auto-setup image full time instead?

Should we use the auto-setup image full time instead?

No, it’s just for testing / local development as it runs all services in same process, and you cannot scale that for a production env.

You have to run the update schema commands using the db-specific cli tool.

Ah OK, so then the high level process would be:

  1. Run a new container on the target version
  2. Exec into it and run the temporal-sql-tool command
  3. Upgrade the production containers to the new image

Is that right?

I think the sql-tools are included in admin-tools image so you could run schema updates from that.

There is more info on updating server in docs here as well if that helps.

1 Like

I’m on Postgres 13, should I still use “v96”?

I tried this with 12 (on a test cluster) and all seemed fine

## Main Schema update
temporal-sql-tool --plugin postgres12 --ep "${POSTGRES_SEEDS}" -u "${POSTGRES_USER}" -pw "${POSTGRES_PWD}" -p "${DB_PORT}" --db "${DBNAME}" update-schema -d "/etc/temporal/schema/postgresql/v12/temporal/versioned"

## Visibility schema update
temporal-sql-tool --plugin postgres12 --ep "${POSTGRES_SEEDS}" -u "${POSTGRES_USER}" -pw "${POSTGRES_PWD}" -p "${DB_PORT}" --db "temporal_visibility" update-schema -d "/etc/temporal/schema/postgresql/v12/visibility/versioned"

Do you set DB env var to “postgres12”? If so yes. This should mean “12+”

I’ve not set that env var anywhere in production (should we?), I was just trying to extract the upgrade command we need to run from the auto-setup script :slight_smile: