# Does Temporal upgrade DB schemas automatically?

**URL:** <https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777>\
**Category:** Community Support\
**Created:** [April 3, 2023, 7:28pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777 "2023-04-03T19:28:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichRM](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/richrm/32/3640_2.png) [@RichRM](https://community.temporal.io/u/RichRM)\
**Post date:** [April 3, 2023, 7:28pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/1 "2023-04-03T19:28:46Z")

</div>

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  
Rich

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [April 3, 2023, 7:50pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/2 "2023-04-03T19:50:11Z")

</div>

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](https://github.com/temporalio/docker-builds/blob/main/docker/auto-setup.sh#L191). I believe if you are running auto-setup, the auto-setup.sh script should take care of that part.

---

<div class="post-metadata">

**Author:** ![RichRM](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/richrm/32/3640_2.png) [@RichRM](https://community.temporal.io/u/RichRM)\
**Post date:** [April 3, 2023, 7:54pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/3 "2023-04-03T19:54:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [April 3, 2023, 7:56pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/4 "2023-04-03T19:56:12Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![RichRM](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/richrm/32/3640_2.png) [@RichRM](https://community.temporal.io/u/RichRM)\
**Post date:** [April 3, 2023, 7:58pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/5 "2023-04-03T19:58:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [April 3, 2023, 8:03pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/6 "2023-04-03T20:03:17Z")

</div>

I think the sql-tools are included in [admin-tools image](https://github.com/temporalio/docker-builds/blob/main/admin-tools.Dockerfile) so you could run schema updates from that.

There is more info on updating server in docs [here](https://docs.temporal.io/cluster-deployment-guide#upgrade-server) as well if that helps.

---

<div class="post-metadata">

**Author:** ![RichRM](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/richrm/32/3640_2.png) [@RichRM](https://community.temporal.io/u/RichRM)\
**Post date:** [April 3, 2023, 8:30pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/7 "2023-04-03T20:30:30Z")

</div>

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

> <https://github.com/temporalio/docker-builds/blob/main/docker/auto-setup.sh#L205>

---

<div class="post-metadata">

**Author:** ![RichRM](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/richrm/32/3640_2.png) [@RichRM](https://community.temporal.io/u/RichRM)\
**Post date:** [April 3, 2023, 9:07pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/8 "2023-04-03T21:07:02Z")

</div>

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

```auto
## 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"

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [April 3, 2023, 9:35pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/9 "2023-04-03T21:35:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RichRM](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/richrm/32/3640_2.png) [@RichRM](https://community.temporal.io/u/RichRM)\
**Post date:** [April 3, 2023, 9:46pm UTC](https://community.temporal.io/t/does-temporal-upgrade-db-schemas-automatically/7777/10 "2023-04-03T21:46:19Z")

</div>

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 🙂
