> For the complete documentation index, see [llms.txt](https://docs.monokot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.monokot.io/time-series-and-stores/postgresql-connectivity/database-design.md).

# Database Design

By default, the store creates a database and two tables: *tssamples\_metadata* and *tssamples\_data*. Metadata of the time series associated with the store is placed In *tssamples\_metadata*, while the time series values are written in *tssamples\_data*.&#x20;

Structure of the time series metadata table (*tssamples\_metadata*):

| <p>tag\_set \[PK]</p><p><strong>jsonb</strong></p> | <p>server\_uid</p><p><strong>text</strong></p> | <p>store\_uid</p><p><strong>text</strong></p> | <p>ts\_uid</p><p><strong>text</strong></p> | <p>ts\_path</p><p><strong>text</strong></p> | <p>ts\_comment</p><p><strong>text</strong></p> | <p>tag\_set\_id</p><p><strong>integer</strong></p> |
| -------------------------------------------------- | ---------------------------------------------- | --------------------------------------------- | ------------------------------------------ | ------------------------------------------- | ---------------------------------------------- | -------------------------------------------------- |

* **tag\_set**: The column is the primary key of the table and is of the JSONB type. The column is a set of attributes or *tags* (key-value pairs) identifying a time series. By default, the set contains only one tag, *tsid*, representing the address of the time series. However, by changing parameters from the *Advanced* category, you can add additional tags. For example, if you set the parameter *Add Time Series Comment to Tag*, a *tsc* tag will be added to the set containing a comment to the series.
* **server\_uid**: The column is of the TEXT type and contains a unique server identifier.
* **store\_uid**: The column is of the TEXT type and contains unique store identifier.
* **ts\_uid**: The column is of the TEXT type and contains unique time series identifier.
* **ts\_path**: The column is of the TEXT type and contains path to time series. The values of this column are indexed.
* **ts\_comment**: The column is of the TEXT type and contains comment for time series.
* **tag\_set\_id**: The column is of the INTEGER type, is auto-incremental and contains unique numeric identifier for time series.

Structure of the time series data table (*tssamples\_data*):

| <p>sample\_time</p><p><strong>timestamp without time zone</strong></p> | <p>tag\_id</p><p><strong>integer</strong></p> | <p>sample\_value</p><p><strong>double precision</strong></p> | <p>sample\_status</p><p><strong>integer</strong></p> |
| ---------------------------------------------------------------------- | --------------------------------------------- | ------------------------------------------------------------ | ---------------------------------------------------- |

* **sample\_time:** The column is of the TIMESTAMP WITHOUT TIME ZONE type and contains measurement time. The values of this column are indexed.
* **tag\_id**: The column is of the INTEGER type and contains the link to the *tag\_set\_id* column from the *tssamples\_metadata* table. The values of this column are indexed.
* **sample\_value**: The column is of the FLOAT8 type and contains the sample value.
* **sample\_status**: The column is of the INTEGER type and contains the sample status.

Below is an example of a database query that will return data for a 5-minute interval for time series with the paths *MySeries.Temperature* and *MySeries.Pressure*:

```sql
SELECT m.ts_path, d.sample_time, d.sample_value, d.sample_status
FROM public.tssamples_data d
JOIN public.tssamples_metadata m ON m.tag_set_id = d.tag_id
WHERE d.sample_time BETWEEN '2020-03-20T09:20:00' AND '2020-03-20T09:25:00'
AND (m.ts_path = 'MySeries.Temperature' OR m.ts_path = 'MySeries.Pressure')
ORDER BY m.tag_set_id, d.sample_time DESC
```

Note that the time of this query is in the UTC format.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.monokot.io/time-series-and-stores/postgresql-connectivity/database-design.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
