831 Commits

Author SHA1 Message Date
Rafia Sabih
f7c769c684 Allow manual index creation in CAggs
The materialised hypertable resides in the _timescaledb.internal schema
which resulted in permission error at the time of manual index creation
by non super user. To solve this, it now switches to timescaledb user
before index creation of CAgg.

Fixes #4735
2022-09-30 07:55:38 -07:00
Konstantina Skovola
9bd772de25 Add interface for troubleshooting job failures
This commit gives more visibility into job failures by making the
information regarding a job runtime error available in an extension
table (`job_errors`) that users can directly query.
This commit also adds an infromational view on top of the table for
convenience.
To prevent the `job_errors` table from growing too large,
a retention job is also set up with a default retention interval
of 1 month. The retention job is registered with a custom check
function that requires that a valid "drop_after" interval be provided
in the config field of the job.
2022-09-30 15:22:27 +02:00
Sven Klemm
d833293a52 Add missing ORDER BY clause to dist_move_chunk 2022-09-28 16:22:06 +02:00
Fabrízio de Royes Mello
893faf8a6b Fix Continuous Aggregate migration policies
After migrate a Continuous Aggregate from the old format to the new
using `cagg_migrate` procedure we end up with the following problems:
* Refresh policy is not copied from the OLD to the NEW cagg;
* Compression setting is not copied from the OLD to the NEW cagg.

Fixed it by properly copying the refresh policy and setting the
`timescaledb.compress=true` flag to the new CAGG.

Fix #4710
2022-09-22 17:38:21 -03:00
Konstantina Skovola
97a603fe5c Remove support for procedures as custom checks
Procedures doing their own transaction handling could lead to errors
or even crashes.

Fixes #4703
2022-09-19 08:39:23 +02:00
Bharathy
d00a55772c error compressing wide table
Consider a compressed hypertable has many columns (like more than 600 columns).
In call to compress_chunk(), the compressed tuple size exceeds, 8K which causes
error as "row is too big: size 10856, maximum size 8160."

This patch estimates the tuple size of compressed hypertable and reports a
warning when compression is enabled on hypertable. Thus user gets aware of
this warning before calling compress_chunk().

Fixes #4398
2022-09-17 11:24:23 +05:30
Sven Klemm
1cb3edddc1 Fix bgw_db_scheduler regresscheck configuration
Recent refactoring changed bgw_db_scheduler to also be run on
non-Debug builds. Adjust the configuration so it is only included
for debug builds.
2022-09-16 13:05:48 +02:00
Sven Klemm
424f6f7648 Remove database port from test output
Don't include the used database ports into test output as this
will lead to failing tests when running against a local instance
or against a preconfigured cloud instance.
2022-09-15 07:56:12 +02:00
Sven Klemm
1642750e47 Remove multiple PG configurations from regresscheck-t
Using multiple different configurations in a single target will
not work when running against a local instance or when running
against a preconfigured cloud instance. With recent adjustments
to the test cleanup this should not be needed anymore and if we
really need different configuration we should make it a separate
target to make it compatible with instances configured outside
of pg_regress.
2022-09-15 07:56:12 +02:00
Konstantina Skovola
3b3681858d Remove test case causing bgw_custom crash
Patch #4425 introduced regression test failures, namely, a crash
in function `ts_bgw_job_update_by_id`. The failures are due to the
COMMIT statement in the custom check procedure. This patch removes
that particular test case from bgw_custom.
2022-09-14 16:24:28 +03:00
Sven Klemm
0144c75b3f Remove flaky test from bgw_db_scheduler
The out of background worker test in bgw_db_scheduler is flaky and
fails very often, especially in the 32bit environment and on windows.
This patch removes that specific test from bgw_db_scheduler. If we
want to test this specific part of the scheduler this should be
better rewritten in an isolation test.
2022-09-14 14:44:23 +02:00
Fabrízio de Royes Mello
02ad4f6b76 Change parameter names of cagg_migrate procedure
Removed the underline character prefix '_' from the parameter names of
the procedure `cagg_migrate`. The new signature is:

cagg_migrate(
    IN cagg regclass,
    IN override boolean DEFAULT false,
    IN drop_old boolean DEFAULT false
)
2022-09-13 17:22:27 -03:00
Fabrízio de Royes Mello
6ecefff93e Add CAGG migration permission tests
Timescale 2.8 released a migration path from the old format of
Continuous Aggregate to the new format (#4552).

Unfortunately it lacks of proper tests when a non-superuser execute the
migration. For a non-superuser execute the migration properly it
requires SELECT/INSERT/UPDATE permissions in some catalog objects:
* _timescaledb_catalog.continuous_agg_migrate_plan
* _timescaledb_catalog.continuous_agg_migrate_plan_step
* _timescaledb_catalog.continuous_agg_migrate_plan_step_step_id_seq

Improved the regression tests to cover the lack of permissions in the
catalog objects for non-superusers.
2022-09-12 17:04:59 -03:00
Konstantina Skovola
fca9078d6c Exponentially backoff when out of background workers
The scheduler detects the following three types of job failures:

1.Jobs that fail to launch (due to shortage of background workers)
2.Jobs that throw a runtime error
3.Jobs that crash due to a process crashing

In cases 2 and 3, additive backoff is applied in calculating the next
start time of a failed job.
In case 1 we previously retried to launch all jobs that failed to launch
simultaneously.

This commit introduces exponential backoff in case 1,
randomly selecting a wait time in [2, 2 + 2^f] seconds at microsecond granularity.
The aim is to reduce the collision probability for jobs that compete
for a background worker. The maximum backoff value is 1 minute.
It does not change the behavior for cases 2 and 3.

Fixes #4562
2022-09-01 15:13:38 +03:00
Bharathy
ed212b4442 GROUP BY error when setting compress_segmentby with an enum column
When using a custom ENUM data type for compressed hypertable on the GROUP BY
clause raises an error.

Fixed it by generating scan paths for the query by checking if the SEGMENT BY
column is a custom ENUM type and then report a valid error message.

Fixes #3481
2022-09-01 07:31:07 +05:30
Sven Klemm
1fa8373931 Fix segfaults in policy check functions 2022-08-30 18:32:30 +02:00
Dmitry Simonenko
c697700add Add hypertable distributed argument and defaults
This PR introduces a new `distributed` argument to the
create_hypertable() function as well as two new GUC's to
control its default behaviour: timescaledb.hypertable_distributed_default
and timescaledb.hypertable_replication_factor_default.

The main idea of this change is to allow automatic creation
of the distributed hypertables by default.
2022-08-29 17:44:16 +03:00
Fabrízio de Royes Mello
e34218ce29 Migrate Continuous Aggregates to the new format
Timescale 2.7 released a new version of Continuous Aggregate (#4269)
that store the final aggregation state instead of the byte array of
the partial aggregate state, offering multiple opportunities of
optimizations as well a more compact form.

When upgrading to Timescale 2.7, new created Continuous Aggregates
are using the new format, but existing Continuous Aggregates keep
using the format they were defined with.

Created a procedure to upgrade existing Continuous Aggregates from
the old format to the new format, by calling a simple procedure:

test=# CALL cagg_migrate('conditions_summary_daily');

Closes #4424
2022-08-25 17:49:09 -03:00
Alexander Kuzmenkov
706a3c0e50 Enable statement logging in the tests
Remove 'client_min_messages = LOG' where not needed, and add the 'LOG:
statement' output otherwise.
2022-08-25 15:29:28 +03:00
Sven Klemm
5d934baf1d Add timezone support to time_bucket
This patch adds a new function time_bucket(period,timestamp,timezone)
which supports bucketing for arbitrary timezones.
2022-08-25 12:59:05 +02:00
Konstantina Skovola
dc145b7485 Add parameter check_config to alter_job
Previously users had no way to update the check function
registered with add_job. This commit adds a parameter check_config
to alter_job to allow updating the check function field.

Also, previously the signature expected from a check was of
the form (job_id, config) and there was no validation
that the check function given had the correct signature.
This commit removes the job_id as it is not required and
also checks that the check function has the correct signature
when it is registered with add_job, preventing an error being
thrown at job runtime.
2022-08-25 10:38:03 +03:00
Mats Kindahl
e0f3e17575 Use new validation functions
Old patch was using old validation functions, but there are already
validation functions that both read and validate the policy, so using
those. Also removing the old `job_config_check` function since that is
no longer use and instead adding a `job_config_check` that calls the
checking function with the configuration.
2022-08-25 10:38:03 +03:00
gayyappan
7c55d0d5dc Modify OSM chunk's constraint info in chunk catalog
The OSM chunk registers a dummy primary dimension range
in the TimescaleDB catalog. Use the max interval of
the dimension instead of the min interval i.e
use range like [Dec 31 294246 PST, infinity).
Otherwise, policies can try to apply the policy on an OSM
chunk.

Add test with policies for OSM chunks
2022-08-24 17:14:36 -04:00
Alexander Kuzmenkov
bc85fb1cf0 Fix the flaky dist_ddl test
Add an option to hide the data node names from error messages.
2022-08-24 15:51:27 +03:00
Dmitry Simonenko
82fc2cac69 Fix rename for distributed hypertable
Fix ALTER TABLE RENAME TO command execution on a distributed
hypertable, make sure data node list is set and command is
executed on the data nodes.

Fix #4491
2022-08-22 18:37:30 +03:00
gayyappan
c643173b8b Filter out osm chunks from chunks information view
Modify timescaledb_information.chunks
view to filter out osm chunks. We do not want
user to invoke chunk specific operations on
OSM chunks.
2022-08-22 09:59:57 -04:00
gayyappan
6beda28965 Modify chunk exclusion to include OSM chunks
OSM chunks manage their ranges and the timescale
catalog has dummy ranges for these dimensions.
So the chunk exclusion logic cannot rely on the
timescaledb catalog metadata to exclude an OSM chunk.
2022-08-18 09:32:21 -04:00
Fabrízio de Royes Mello
8f920b393a Add missing gitignore entry
Pull request #4416 introduced a new template SQL test file but missed
to add the properly gitgnore entry to ignore generated test files.
2022-08-17 20:18:09 -03:00
Sven Klemm
5c96d25058 Clean up multinode databases in tests
Not cleaning up created databases will prevent multiple
regresschecklocal runs against the same instance cause it will
block recreating the test users as they are still referenced in
those databases.
2022-08-17 10:30:13 +02:00
Markos Fountoulakis
9c6433e6ed Handle TRUNCATE TABLE on chunks
Make truncating a uncompressed chunk drop the data for the case where
they reside in a corresponding compressed chunk.

Generate invalidations for Continuous Aggregates after TRUNCATE, so
as to have consistent refresh operations on the materialization
hypertable.

Fixes #4362
2022-08-17 10:23:40 +03:00
Sven Klemm
8c5a759765 Add missing ORDER BY clauses to cagg_policy test 2022-08-16 00:16:36 +02:00
Sven Klemm
a6cda9c9f0 Fix chunk_utils_internal test
Change chunk_utils_internal test to not use oid but instead use the
role name. Using the oid can lead to failing tests when oid assignment
is different especially when run with regresschecklocal-t.
2022-08-15 15:09:57 +02:00
Sven Klemm
131773a902 Reset compression sequence when group resets
The sequence number of the compressed tuple is per segment by grouping
and should be reset when the grouping changes to prevent overflows with
many segmentby columns.
2022-08-15 13:34:00 +02:00
Fabrízio de Royes Mello
500c225999 Handle properly default privileges on CAggs
If a default privilege is configured and applied to a given Continuous
Aggregate during it creation just the user view has the ACL properly
configured but the underlying materialization hypertable no leading to
permission errors.

Fixed it by copying the privileges from the user view to the
materialization hypertable during the Continous Aggregate creation.

Fixes #4555
2022-08-12 14:30:10 -03:00
Rafia Sabih
16fdb6ca5e Checks for policy validation and compatibility
At the time of adding or updating policies, it is
checked if the policies are compatible with each
other and to those already on the CAgg.
These checks are:
- refresh and compression policies should not overlap
- refresh and retention policies should not overlap
- compression and retention policies should not overlap

Co-authored-by: Markos Fountoulakis <markos@timescale.com>
2022-08-12 00:55:18 +03:00
Rafia Sabih
088f688780 Miscellaneous
-Add infinity for refresh window range
 Now to create open ended refresh policy
 use +/- infinity for end_offset and star_offset
 respectivly for the refresh policy.
-Add remove_all_policies function
 This will remove all the policies on a given
 CAgg.
-Remove parameter refresh_schedule_interval
-Fix downgrade scripts
-Fix IF EXISTS case

Co-authored-by: Markos Fountoulakis <markos@timescale.com>
2022-08-12 00:55:18 +03:00
Rafia Sabih
bca65f4697 1 step CAgg policy management
This simplifies the process of adding the policies
for the CAggs. Now, with one single sql statements
all the policies can be added for a given CAgg.
Similarly, all the policies can be removed or modified
via single sql statement only.

This also adds a new function as well as a view to show all
the policies on a continuous aggregate.
2022-08-12 00:55:18 +03:00
gayyappan
95cc330e0c Add inherited check constraints to OSM chunk
When a table is added to an inheritance hierrachy, PG checks
if all check constraints are present on this table. When a OSM chunk
is added as a child of a hypertable with constraints,
make sure that all check constraints are replicated on the child OSM
chunk as well.
2022-08-10 10:20:14 -04:00
Erik Nordström
025bda6a81 Add stateful partition mappings
Add a new metadata table `dimension_partition` which explicitly and
statefully details how a space dimension is split into partitions, and
(in the case of multi-node) which data nodes are responsible for
storing chunks in each partition. Previously, partition and data nodes
were assigned dynamically based on the current state when creating a
chunk.

This is the first in a series of changes that will add more advanced
functionality over time. For now, the metadata table simply writes out
what was previously computed dynamically in code. Future code changes
will alter the behavior to do smarter updates to the partitions when,
e.g., adding and removing data nodes.

The idea of the `dimension_partition` table is to minimize changes in
the partition to data node mappings across various events, such as
changes in the number of data nodes, number of partitions, or the
replication factor, which affect the mappings. For example, increasing
the number of partitions from 3 to 4 currently leads to redefining all
partition ranges and data node mappings to account for the new
partition. Complete repartitioning can be disruptive to multi-node
deployments. With stateful mappings, it is possible to split an
existing partition without affecting the other partitions (similar to
partitioning using consistent hashing).

Note that the dimension partition table expresses the current state of
space partitions; i.e., the space-dimension constraints and data nodes
to be assigned to new chunks. Existing chunks are not affected by
changes in the dimension partition table, although an external job
could rewrite, move, or copy chunks as desired to comply with the
current dimension partition state. As such, the dimension partition
table represents the "desired" space partitioning state.

Part of #4125
2022-08-02 11:38:32 +02:00
Dmitry Simonenko
65b5dc900f Support add_dimension() with existing data
This change allows to create new dimensions even with
existing chunks.

It does not modify any existing data or do migration,
instead it creates full-range (-inf/inf) dimension slice for
existing chunks in order to be compatible with newly created
dimension.

All new chunks created after this will follow logic of the new
dimension and its partitioning.

Fix: #2818
2022-08-01 10:52:03 +03:00
Fabrízio de Royes Mello
28440b7900 Enable ORDER BY on Continuous Aggregates
Users often execute TopN like queries over Continuous Aggregates and
now with the release 2.7 such queries are even faster because we
remove the re-aggregation and don't store partials anymore.

Also the previous PR #4430 gave us the ability to create indexes
direct on the aggregated columns leading to performance improvements.

But there are a noticable performance difference between
`Materialized-Only` and `Real-Time` Continuous Aggregates for TopN
queries.

Enabling the ORDER BY clause in the Continuous Aggregates definition
result in:

1) improvements of the User Experience that can use this so commom
   clause in SELECT queries

2) performance improvements because we give the planner a chance to
   use the MergeAppend node by producing ordered datasets.

Closes #4456
2022-07-31 15:52:55 -03:00
Sven Klemm
eccd6df782 Throw better error message on incompatible row fetcher settings
When a query has multiple distributed hypertables the row-by-by
fetcher cannot be used. This patch changes the fetcher selection
logic to throw a better error message in those situations.
Previously the following error would be produced in those situations:
unexpected PQresult status 7 when starting COPY mode
2022-07-29 11:40:00 +02:00
Rafia Sabih
a584263179 Fix alter column for compressed table
Enables adding a boolean column with default value to a compressed table.
This limitation was occurring due to the internal representation of default
boolean values like 'True' or 'False', hence more checks are added for this.

Fixes #4486
2022-07-27 17:19:01 +02:00
Sven Klemm
ce9672aee3 Fix dist_copy_long test on macOS
On macOS zcat expects the file to end in .Z appending that extension
when the supplied filename does not have it. Leading to the following
error for the dist_copy_long test:

zcat: can't stat: data/prices-10k-random-1.tsv.gz
(data/prices-10k-random-1.tsv.gz.Z): No such file or directory

This patch changes the dist_copy_long test to use the shell to read
the file instead and use input redirection so zcat never sees the
filename.
2022-07-22 12:03:14 +02:00
gayyappan
6b0a9937c5 Fix attach_osm_table_chunk
Add chunk inheritance when attaching a OSM
tabel as a chunk of the hypertable
2022-07-21 19:27:24 -04:00
Alexander Kuzmenkov
1f6b0240a3 Add a distributed COPY test with more data
Use data sets with 10k and 100k rows with a variety of partitioning
settings. This may help to catch some rare corner cases.
2022-07-21 23:10:45 +05:30
Dmitry Simonenko
4ed116b6f6 Fix ANALYZE on dist hypertable for a set of nodes
Make sure ANALYZE can be run on a specific set of data nodes
assigned to the distributed hypertable

Fix #4508
2022-07-21 12:39:17 +03:00
Nikhil Sontakke
63a80eec0d Handle stats properly for range types
For range types, the operator entry in statistics table is invalid.
Also, certain range types don't have "VALUES" but only have "NUMBERS"
entries.
2022-07-20 12:31:26 +05:30
Nikhil Sontakke
fdb12f7abe Handle timescaledb versions aptly in multinode
The current check where we deem a DN incompatible if it's on a newer
version is exactly the opposite of what we want it to be. Fix that and
also add relevant test cases.
2022-07-06 20:09:09 +05:30
gayyappan
6c20e74674 Block drop chunk if chunk is in frozen state
A chunk in frozen state cannot be dropped.
drop_chunks will skip over frozen chunks without erroring.
Internal api , drop_chunk will error if you attempt to  drop
a chunk without unfreezing it.

This PR also adds a new internal API to unfreeze a chunk.
2022-06-30 09:56:50 -04:00