> For the complete documentation index, see [llms.txt](https://docs.tryterra.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tryterra.co/faq/help-topics/webhook/storage-destinations-s3-sqs-supabase-sql-gcs/sql-destination-schema-setup.md).

# How do I set up a Postgres SQL destination?

The [SQL destination](https://docs.tryterra.co/health-and-fitness-api/integration-setup/setting-up-data-destinations/sql-database-postgres-mysql) requires a specific schema and tables to exist **before** delivery. To set it up:

{% stepper %}
{% step %}
Create a schema named `terra` (the name is fixed, not freely choosable).
{% endstep %}

{% step %}
Create the `terra_users`, `terra_data_payloads` and `terra_other_payloads` tables.
{% endstep %}

{% step %}
Set the **Scheme** field to the database type (`postgres` or `mysql`), not a custom value, or delivery will return `500`.
{% endstep %}
{% endstepper %}

`reference_id` is stored in the users table; join it on `user_id` to associate data with your internal users.

{% hint style="info" %}
Updated payloads (for example revised dailies) are inserted as **new rows** with a new `created_at` rather than overwriting, since there is no unique constraint. Deduplicate downstream.
{% endhint %}
