Create a hypertable
Hypertables and chunks make storing and querying times-series data fast at petabyte scale.
TimescaleDB automatically partitions time-series data into chunks, or sub-tables, based on time and space. You can configure chunk size so that recent chunks fit in memory for faster queries.
A hypertable is an abstraction layer over chunks that hold the time-series data. Hypertables enable you to query and access data from all the chunks within the hypertable. You get all the benefits of automatic chunking for time-series data, alongside the simplicity of working with what looks like a standard, single PostgreSQL table.
Hypertables and chunks enable superior performance for shallow and wide queries, like those used in real-time monitoring. They are also good for deep and narrow queries, like those used in time-series analysis.
For more information, see .
Convert the regular table into a hypertable partitioned on the
time
column using thecreate_hypertable()
function provided by TimescaleDB. You must provide the name of the table () and the column in that table that holds the timestamp data to use for partitioning (time
):Create an index to support efficient queries on the
symbol
and columns:
note
Because you often query the stock trade data by the company symbol, you should add an index for it. Include the time column because time-series data typically looks for data in a specific period of time.
TimescaleDB isn’t just for hypertables. Remember, TimescaleDB is PostgreSQL. When you have other relational data that enhances your time-series data, you can create regular PostgreSQL tables just as you would normally. For this dataset, there is one other table of data called company
.
Creating regular PostgreSQL tables
Add a table to store the company name and symbol for the stock trade data:
To learn more about hypertables and best practices for configuring chunks, see Hypertable How-To. For information about how hypertables help with storing and querying data, see the .