Skip to content

Commit

Permalink
Pull policy section out of about
Browse files Browse the repository at this point in the history
  • Loading branch information
Loquacity committed Aug 30, 2023
1 parent 8db02ac commit fb7e4a5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 88 deletions.
82 changes: 0 additions & 82 deletions use-timescale/compression/about-compression.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,84 +23,6 @@ best possible compression ratio.

For more information about compressing chunks, see [manual compression][manual-compression].

## Enable compression

You can enable compression on individual hypertables, by declaring which column
you want to segment by. This procedure uses an example table, called `example`,
and segments it by the `device_id` column. Every chunk that is more than seven
days old is then marked to be automatically compressed.

|time|device_id|cpu|disk_io|energy_consumption|
|-|-|-|-|-|
|8/22/2019 0:00|1|88.2|20|0.8|
|8/22/2019 0:05|2|300.5|30|0.9|

<Procedure>

### Enabling compression

1. At the `psql` prompt, alter the table:

```sql
ALTER TABLE example SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device_id'
);
```

1. Add a compression policy to compress chunks that are older than seven days:

```sql
SELECT add_compression_policy('example', INTERVAL '7 days');
```

</Procedure>

For more information, see the API reference for
[`ALTER TABLE (compression)`][alter-table-compression] and
[`add_compression_policy`][add_compression_policy].

You can also set a compression policy through
the Timescale console. The compression tool automatically generates and
runs the compression commands for you. To learn more, see the
[Timescale documentation](/use-timescale/latest/services/service-explorer/#setting-a-compression-policy-from-timescale-cloud-console).

## View current compression policy

To view the compression policy that you've set:
```sql
SELECT * FROM timescaledb_information.jobs
WHERE proc_name='policy_compression';
```
For more information, see the API reference for [`timescaledb_information.jobs`][timescaledb_information-jobs].
## Remove compression policy
To remove a compression policy, use `remove_compression_policy`. For example, to
remove a compression policy for a hypertable named `cpu`:
```sql
SELECT remove_compression_policy('cpu');
```
For more information, see the API reference for
[`remove_compression_policy`][remove_compression_policy].
## Disable compression
You can disable compression entirely on individual hypertables. This command
works only if you don't currently have any compressed chunks:

```sql
ALTER TABLE <TABLE_NAME> SET (timescaledb.compress=false);
```

If your hypertable contains compressed chunks, you need to
[decompress each chunk][decompress-chunks] individually before you can disable
compression.

## Compression policy intervals

Data is usually compressed after an interval of time, and not
Expand Down Expand Up @@ -274,9 +196,5 @@ chunks. When you do this,the data that is being inserted is not compressed
immediately. It is stored alongside the chunk it has been inserted into, and
then a separate job merges it with the chunk and compresses it later on.

[alter-table-compression]: /api/:currentVersion:/compression/alter_table_compression/
[add_compression_policy]: /api/:currentVersion:/compression/add_compression_policy/
[decompress-chunks]: /use-timescale/:currentVersion:/compression/decompress-chunks
[remove_compression_policy]: /api/:currentVersion:/compression/remove_compression_policy/
[timescaledb_information-jobs]: /api/:currentVersion:/informational-views/jobs/
[manual-compression]: /use-timescale/:currentVersion:/compression/manual-compression/
96 changes: 96 additions & 0 deletions use-timescale/compression/compression-policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: Create a compression policy
excerpt: Create a compression policy on a hypertable
products: [cloud, mst, self_hosted]
keywords: [compression, hypertables, policy]
---

import CompressionIntro from 'versionContent/_partials/_compression-intro.mdx';

# Compression policy

You can enable compression on individual hypertables, by declaring which column
you want to segment by.

## Enable a compression policy

This procedure uses an example table, called `example`,
and segments it by the `device_id` column. Every chunk that is more than seven
days old is then marked to be automatically compressed.

|time|device_id|cpu|disk_io|energy_consumption|

Check warning on line 21 in use-timescale/compression/compression-policy.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'device_id'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'device_id'?", "location": {"path": "use-timescale/compression/compression-policy.md", "range": {"start": {"line": 21, "column": 7}}}, "severity": "WARNING"}

Check warning on line 21 in use-timescale/compression/compression-policy.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'cpu'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'cpu'?", "location": {"path": "use-timescale/compression/compression-policy.md", "range": {"start": {"line": 21, "column": 17}}}, "severity": "WARNING"}

Check warning on line 21 in use-timescale/compression/compression-policy.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'disk_io'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'disk_io'?", "location": {"path": "use-timescale/compression/compression-policy.md", "range": {"start": {"line": 21, "column": 21}}}, "severity": "WARNING"}

Check warning on line 21 in use-timescale/compression/compression-policy.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'energy_consumption'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'energy_consumption'?", "location": {"path": "use-timescale/compression/compression-policy.md", "range": {"start": {"line": 21, "column": 29}}}, "severity": "WARNING"}
|-|-|-|-|-|
|8/22/2019 0:00|1|88.2|20|0.8|
|8/22/2019 0:05|2|300.5|30|0.9|

<Procedure>

### Enabling compression

1. At the `psql` prompt, alter the table:

```sql
ALTER TABLE example SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device_id'
);
```

1. Add a compression policy to compress chunks that are older than seven days:

```sql
SELECT add_compression_policy('example', INTERVAL '7 days');
```

</Procedure>

For more information, see the API reference for
[`ALTER TABLE (compression)`][alter-table-compression] and
[`add_compression_policy`][add_compression_policy].

You can also set a compression policy through
the Timescale console. The compression tool automatically generates and
runs the compression commands for you. To learn more, see the
[Timescale documentation](/use-timescale/latest/services/service-explorer/#setting-a-compression-policy-from-timescale-cloud-console).

## View current compression policy

To view the compression policy that you've set:
```sql
SELECT * FROM timescaledb_information.jobs
WHERE proc_name='policy_compression';
```
For more information, see the API reference for [`timescaledb_information.jobs`][timescaledb_information-jobs].
## Remove compression policy
To remove a compression policy, use `remove_compression_policy`. For example, to
remove a compression policy for a hypertable named `cpu`:
```sql
SELECT remove_compression_policy('cpu');
```
For more information, see the API reference for
[`remove_compression_policy`][remove_compression_policy].
## Disable compression
You can disable compression entirely on individual hypertables. This command

Check warning on line 81 in use-timescale/compression/compression-policy.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.WordList] Use 'turn off' or 'off' instead of 'disable'. Raw Output: {"message": "[Google.WordList] Use 'turn off' or 'off' instead of 'disable'.", "location": {"path": "use-timescale/compression/compression-policy.md", "range": {"start": {"line": 81, "column": 9}}}, "severity": "WARNING"}
works only if you don't currently have any compressed chunks:

```sql
ALTER TABLE <TABLE_NAME> SET (timescaledb.compress=false);
```

If your hypertable contains compressed chunks, you need to
[decompress each chunk][decompress-chunks] individually before you can turn off
compression.

[alter-table-compression]: /api/:currentVersion:/compression/alter_table_compression/
[add_compression_policy]: /api/:currentVersion:/compression/add_compression_policy/
[decompress-chunks]: /use-timescale/:currentVersion:/compression/decompress-chunks
[remove_compression_policy]: /api/:currentVersion:/compression/remove_compression_policy/
[timescaledb_information-jobs]: /api/:currentVersion:/informational-views/jobs/
5 changes: 0 additions & 5 deletions use-timescale/compression/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,3 @@ data to the form of compressed columns. This occurs across chunks of Timescale
hypertables.

<UsageBasedStorage />

[backfill-historical]: /use-timescale/:currentVersion:/compression/backfill-historical-data/
[decompress-chunks]: /use-timescale/:currentVersion:/compression/decompress-chunks/
[modify-schema]: /use-timescale/:currentVersion:/compression/modify-a-schema/
[compression-tshoot]: /use-timescale/:currentVersion:/compression/troubleshooting/
7 changes: 6 additions & 1 deletion use-timescale/page-index/page-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ module.exports = [
{
title: "About compression",
href: "about-compression",
excerpt: "Compress data chunks",
excerpt: "Learn about how compression works",
},
{
title: "Enable a compression policy",
href: "compression-policy",
excerpt: "Create a compression policy on a hypertable",
},
{
title: "Manual compression",
Expand Down

0 comments on commit fb7e4a5

Please sign in to comment.