A New Era of Time Series Databases: dbForge Studio for PostgreSQL + TimescaleDB

The latest update of dbForge Studio for PostgreSQL adds one more item to its list of supported databases. We're talking about TimescaleDB, a PostgreSQL fork advertised as "the easiest, fastest, most cost-effective time-series database". It can now be accessed and managed seamlessly from Studio - that's our story.

If you are new to TimescaleDB, below is the fastest way to find out all about it. If you're already an active user, chances are after reading this article you'll discover a great database management tool that will make your day-to-day work a breeze. Anyway, buckle up and let's go!

What is TimescaleDB used for?

TimescaleDB is designed to be a superior as-a-service replacement for regular PostgreSQL, which retains all of its benefits, including compatibility with the entire ecosystem of PostgreSQL tools, drivers, and connectors, while also offering significantly improved performance, better Scalability and time series hyperfunctions. The latter is the main focus of TimescaleDB.

If you don't know what a time series database is , let us explain. It is a database that allows storage, retrieval and management of time-stamped data. This includes data records that are part of a so-called "time series", where data points are associated with timestamps that define the actual relationship between the data points.

Let's make this more clear with a simple example. Imagine an application that continuously retrieves measurements from sensors and allows you to monitor them in real time. This is certainly a large stream of data, but it is conveniently time-stamped, and you can always retrieve the data points you need from any time period for subsequent analysis.

Time-series databases are used with hypertables, a specific type of table designed to improve performance by partitioning time-series data according to its time parameters. More precisely, a hypertable consists of multiple regular PostgreSQL subtables called chunks. Chunks are partitions based on specific time constraints and thus contain data from a specific time range. However, it's not as complicated as it sounds - since blocks are set and managed automatically by the database, you can manage your data as if it were stored in a standard table.

Here is a comparison of a regular table with a hypertable where the block time span is equal to 1 day. 

By the way, hypertables and standard PostgreSQL tables can easily coexist in the same database. You just use hypertables for time series data and standard tables for relational data, and that's it.

Now, with the basics covered, we'll show you how to install a self-hosted TimescaleDB database and connect to it using dbForge Studio for PostgreSQL.

How to install TimescaleDB extension and connect to dbForge Studio for PostgreSQL

The first thing you need to do is add two system environment variables: and . need to be able to do this:C:\Program Files\PostgreSQL\15\binC:\Program Files\Git\mingw64\bin

  1. Go to the Start menu, start typing "environment variables" and you will be prompted to open " Edit system environment variables" .
  2. Click it to open the System Properties window. There, click on Environment Variables .
  3. In the Environment Variables window that opens , find Path under System Variables , select it and click Edit .
  4. In the Edit Environment Variables window that opens , click New and add the above two variables.
  5. Finally, click OK to apply your changes.

Let us now show you how to install self-hosted TimescaleDB on a Windows machine. The following guide is a condensed version of the official TimescaleDB installation manual. If any problem occurs during installation, please feel free to consult for more details.

prerequisites

  • Operating System: Microsoft Windows 10 / Microsoft Windows 11 / Microsoft Windows Server 2019
  • The minimum supported PostgreSQL versions are: 12.8 / 13.5 / 14.0 / 15.0; in order to install PostgreSQL 15.1.1 or higher, make sure you have OpenSSL 1.1.1 installed on your computer

Install self-hosted TimescaleDB on Windows

  1. Download and install the Visual C++ Redistributable for Visual Studio from the Microsoft website .
  2. Download and install PostgreSQL from the PostgreSQL website . You may need to add the pg_config file location to your path.
  3. Download the TimescaleDB installation .zip file from the Windows version .
  4. Locate the downloaded archive and extract the file.
  5. In the extracted TimescaleDB directory, right-click the setup.exe file and select Run as administrator to start the installer.
  6. After the installation is complete, you need to configure the database. You can do this by running the timescaledb-tune script, which is included in the timescaledb-tools package.

Setting up the TimescaleDB extension

1. Go to a command prompt and postgresconnect to the PostgreSQL instance as superuser.

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">psql </span></span><span style="color:#666600"><span style="color:#666600">-</span></span><span style="color:#000000"><span style="color:#000000">U postgres </span></span><span style="color:#666600"><span style="color:#666600">-</span></span><span style="color:#000000"><span style="color:#000000">h localhost</span></span></code></span></span>

If the connection is successful, you'll see a message similar to the following, followed by a prompt psql:

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">psql </span></span><span style="color:#666600"><span style="color:#666600">(</span></span><span style="color:#006666"><span style="color:#006666">13.3</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000"> server </span></span><span style="color:#006666"><span style="color:#006666">12.8</span></span> <span style="color:#666600"><span style="color:#666600">(</span></span><span style="color:#660066"><span style="color:#660066">Ubuntu</span></span> <span style="color:#006666"><span style="color:#006666">12.8</span></span><span style="color:#666600"><span style="color:#666600">-</span></span><span style="color:#006666"><span style="color:#006666">1.pgdg21.04</span></span><span style="color:#666600"><span style="color:#666600">+</span></span><span style="color:#006666"><span style="color:#006666">1</span></span><span style="color:#666600"><span style="color:#666600">))</span></span>
<span style="color:#000000"><span style="color:#000000">SSL connection </span></span><span style="color:#666600"><span style="color:#666600">(</span></span><span style="color:#000000"><span style="color:#000000">protocol</span></span><span style="color:#666600"><span style="color:#666600">:</span></span> <span style="color:#660066"><span style="color:#660066">TLSv1</span></span><span style="color:#666600"><span style="color:#666600">.</span></span><span style="color:#006666"><span style="color:#006666">3</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000"> cipher</span></span><span style="color:#666600"><span style="color:#666600">:</span></span><span style="color:#000000"><span style="color:#000000"> TLS_AES_256_GCM_SHA384</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000"> bits</span></span><span style="color:#666600"><span style="color:#666600">:</span></span> <span style="color:#006666"><span style="color:#006666">256</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000"> compression</span></span><span style="color:#666600"><span style="color:#666600">:</span></span><span style="color:#000000"><span style="color:#000000"> off</span></span><span style="color:#666600"><span style="color:#666600">)</span></span>
<span style="color:#660066"><span style="color:#660066">Type</span></span> <span style="color:#008800"><span style="color:#008800">"help"</span></span> <span style="color:#000088"><span style="color:#000088">for</span></span><span style="color:#000000"><span style="color:#000000"> help</span></span><span style="color:#666600"><span style="color:#666600">.</span></span>
<span style="color:#000000"><span style="color:#000000">tsdb</span></span><span style="color:#666600"><span style="color:#666600">=></span></span></code></span></span>

2. According to psqlthe prompt, create an empty database. This is what a database called example looks like:

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">CREATE database example</span></span><span style="color:#666600"><span style="color:#666600">;</span></span></code></span></span>

3. Next, connect to the database you created using the following command:

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">\c example</span></span></code></span></span>

4. Then add the TimescaleDB extension:

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">CREATE EXTENSION IF NOT EXISTS timescaledb</span></span><span style="color:#666600"><span style="color:#666600">;</span></span></code></span></span>

5. Finally, you can connect to the database with the following command:

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">psql </span></span><span style="color:#666600"><span style="color:#666600">-</span></span><span style="color:#000000"><span style="color:#000000">U postgres </span></span><span style="color:#666600"><span style="color:#666600">-</span></span><span style="color:#000000"><span style="color:#000000">h localhost </span></span><span style="color:#666600"><span style="color:#666600">-</span></span><span style="color:#000000"><span style="color:#000000">d example</span></span></code></span></span>

Connect to TimescaleDB via dbForge Studio

We will now connect to the newly created database using dbForge Studio for PostgreSQL, an advanced IDE for database development and administration. When we open it, we see the Database Connection Properties window where we can enter the credentials for the newly created database.

Then we click Connect and that's it!

Note: dbForge Studio for PostgreSQL is available either individually or as part of a bundle called dbForge Edge , which includes three additional Studios for SQL Server, MySQL, and Oracle databases.

 

How to create a super table in TimescaleDB

Now let's move on to creating our first supertable. To do this, we will run the following query in dbForge Studio.

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">CREATE TABLE conditions</span></span><span style="color:#666600"><span style="color:#666600">(</span></span><span style="color:#000000"><span style="color:#000000">
tstamp timestamptz NOT NULL</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000">
device VARCHAR</span></span><span style="color:#666600"><span style="color:#666600">(</span></span><span style="color:#006666"><span style="color:#006666">32</span></span><span style="color:#666600"><span style="color:#666600">)</span></span><span style="color:#000000"><span style="color:#000000"> NOT NULL</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000">
temperature FLOAT NOT NULL</span></span><span style="color:#666600"><span style="color:#666600">);</span></span>
 <span style="color:#000000"><span style="color:#000000">
SELECT create_hypertable</span></span><span style="color:#666600"><span style="color:#666600">(</span></span>
<span style="color:#008800"><span style="color:#008800">'conditions'</span></span><span style="color:#666600"><span style="color:#666600">,</span></span> <span style="color:#008800"><span style="color:#008800">'tstamp'</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000">
chunk_time_interval </span></span><span style="color:#666600"><span style="color:#666600">=></span></span><span style="color:#000000"><span style="color:#000000"> INTERVAL </span></span><span style="color:#008800"><span style="color:#008800">'1 day'</span></span>
<span style="color:#666600"><span style="color:#666600">);</span></span></code></span></span>

This is what it looks like in the Studio interface.

Note : An alternative query with column partitioning would look like this:

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">SELECT create_hypertable</span></span><span style="color:#666600"><span style="color:#666600">(</span></span>
<span style="color:#008800"><span style="color:#008800">'conditions'</span></span><span style="color:#666600"><span style="color:#666600">,</span></span> <span style="color:#008800"><span style="color:#008800">'tstamp'</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000">
partitioning_column </span></span><span style="color:#666600"><span style="color:#666600">=></span></span> <span style="color:#008800"><span style="color:#008800">'device'</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000">
number_partitions </span></span><span style="color:#666600"><span style="color:#666600">=></span></span> <span style="color:#006666"><span style="color:#006666">8</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000">
chunk_time_interval </span></span><span style="color:#666600"><span style="color:#666600">=></span></span><span style="color:#000000"><span style="color:#000000"> INTERVAL </span></span><span style="color:#008800"><span style="color:#008800">'1 day'</span></span><span style="color:#666600"><span style="color:#666600">);</span></span></code></span></span>

After running the query, our table is successfully created and we can immediately populate it with data. For this we use the following query.

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">INSERT INTO conditions</span></span><span style="color:#000000"><span style="color:#000000">
SELECT</span></span><span style="color:#000000"><span style="color:#000000">
tstamp</span></span><span style="color:#666600"><span style="color:#666600">,</span></span> <span style="color:#008800"><span style="color:#008800">'device-'</span></span> <span style="color:#666600"><span style="color:#666600">||</span></span> <span style="color:#666600"><span style="color:#666600">(</span></span><span style="color:#000000"><span style="color:#000000">random</span></span><span style="color:#666600"><span style="color:#666600">()*</span></span><span style="color:#006666"><span style="color:#006666">30</span></span><span style="color:#666600"><span style="color:#666600">)::</span></span><span style="color:#000000"><span style="color:#000000">INT</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000"> random</span></span><span style="color:#666600"><span style="color:#666600">()*</span></span><span style="color:#006666"><span style="color:#006666">80</span></span> <span style="color:#666600"><span style="color:#666600">-</span></span> <span style="color:#006666"><span style="color:#006666">40</span></span><span style="color:#000000"><span style="color:#000000">
FROM</span></span><span style="color:#000000"><span style="color:#000000">
generate_series</span></span><span style="color:#666600"><span style="color:#666600">(</span></span><span style="color:#000000"><span style="color:#000000">
NOW</span></span><span style="color:#666600"><span style="color:#666600">()</span></span> <span style="color:#666600"><span style="color:#666600">-</span></span><span style="color:#000000"><span style="color:#000000"> INTERVAL </span></span><span style="color:#008800"><span style="color:#008800">'90 days'</span></span><span style="color:#666600"><span style="color:#666600">,</span></span><span style="color:#000000"><span style="color:#000000">
NOW</span></span><span style="color:#666600"><span style="color:#666600">(),</span></span>
<span style="color:#008800"><span style="color:#008800">'1 min'</span></span>
<span style="color:#666600"><span style="color:#666600">)</span></span><span style="color:#000000"><span style="color:#000000"> AS tstamp</span></span><span style="color:#666600"><span style="color:#666600">;</span></span></code></span></span>

This is what it looks like in the studio.

Now let's check it using a SELECT query. voila! We've got the data.

We can also view blocks with the following code:

<span style="background-color:#f1f1f1"><span style="color:#656871"><code><span style="color:#000000"><span style="color:#000000">SELECT show_chunks</span></span><span style="color:#666600"><span style="color:#666600">(</span></span><span style="color:#008800"><span style="color:#008800">'conditions'</span></span><span style="color:#666600"><span style="color:#666600">);</span></span>
 
<span style="color:#666600"><span style="color:#666600">--</span></span> <span style="color:#660066"><span style="color:#660066">The</span></span> <span style="color:#000088"><span style="color:#000088">function</span></span><span style="color:#000000"><span style="color:#000000"> selects chunks </span></span><span style="color:#000088"><span style="color:#000088">from</span></span><span style="color:#000000"><span style="color:#000000"> the following view</span></span><span style="color:#000000"><span style="color:#000000">
SELECT </span></span><span style="color:#666600"><span style="color:#666600">*</span></span><span style="color:#000000"><span style="color:#000000"> FROM timescaledb_information</span></span><span style="color:#666600"><span style="color:#666600">.</span></span><span style="color:#000000"><span style="color:#000000">chunks</span></span><span style="color:#666600"><span style="color:#666600">;</span></span></code></span></span>

Once we run it, this is what we get.

Let us now show you some of the most important features of dbForge Studio applied to the TimescaleDB database.

 

Code completion, formatting and syntax checking in TimescaleDB

First, let's talk about one of the first elements of dbForge database solutions: SQL coding assistance . It does it all for you, from context-aware code completion and syntax validation (helping you write clean, error-free SQL code faster), to advanced SQL formatting with a rich set of options and templates designed to Helps create a uniform, consistent coding style.

Schema and Data Comparison in TimescaleDB

Studio's integrated tool, Schema Compare, provides the easiest way to discover differences between TimescaleDB database objects. Just like with a regular PostgreSQL database, you can set the source, set the target, and run comparisons. Afterwards, differences can be viewed and synchronized to the target database.

How about comparing the actual table data? Well, since blocks are basically your regular tables, Studio has no problem comparing entire hypertables and identifying differences. This is especially useful for time-series databases that tend to handle large amounts of data. Likewise, diffs can also be synchronized for short periods of time.

Note : Data Compare and Schema Compare are also available as standalone applications for PostgreSQL.

Test data generation in TimescaleDB

Finally, you can use Studio's built-in data generator to populate the TimescaleDB database with real test data. A large number of predefined generators will quickly provide any number of column-smart data, customized to the specifics of your database. If that's not enough, you can easily create your own custom generators.

TimescaleDB in action: use cases and business applications

Now that you understand how TimescaleDB works, let us give you a few examples where time-series databases can be applied:

  • Data-Driven Predictive Analytics
  • Software that uses telemetry data from IoT devices
  • Solutions involving rapidly changing financial market data
  • telecommunications
  • machine learning algorithm
  • System or application performance monitoring software
  • security application

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/131697935