40 Commits

Author SHA1 Message Date
Sven Klemm
28c7457faf Move scheduler functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- restart_background_workers()
- stop_background_workers()
- start_background_workers()
- alter_job_set_hypertable_id(integer,regclass)
2023-08-28 14:21:11 +02:00
Sven Klemm
cf04496e4b Move utility functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- generate_uuid()
- get_git_commit()
- get_os_info()
- tsl_loaded()
2023-08-22 13:42:54 +02:00
Lakshmi Narayanan Sreethar
e5691bee11 Cleanup PG12 specific code from source and test files
Removed the PG12 specific macros and all the now, dead code. Also updated
the testcases which had workarounds in place to make them compatible
with PG12.
2023-07-25 16:00:18 +05:30
Alexander Kuzmenkov
27310470be Allow AsyncAppend under IncrementalSort
We forgot to add a case for it.
2022-12-19 21:16:14 +04:00
Bharathy
c06b647680 pg_dump on PG15 does not log messages with log level set to PG_LOG_INFO.
Version 15 pg_dump program does not log any messages with log level <
PG_LOG_WARNING to stdout. Whereas this check is not present in version
14, thus we see corresponding tests fail with missing log information.
This patch fixes by supressing those log information, so that the tests
pass on all versions of postgresql.

Fixes #4832
2022-11-01 20:13:17 +05:30
Fabrízio de Royes Mello
07c5f7281c Create index on Continuous Aggregates
Timescale 2.7 released a new version of Continuous Aggregate (#4269)
that allows users efectivelly create and use indexes in the
materialization hypertable. The boring part of it is that users should
discover what is the associated materialization hypertable to issue a
`CREATE INDEX` statement.

Improved it by allowing users to easily create indexes in the
materialization hypertable by simple executing a `CREATE INDEX` direct
in the Continuous Aggregate.

Example:
`CREATE INDEX name_of_the_index ON continuous_agregate (column);`
2022-06-13 15:45:27 -03:00
Erik Nordström
38e6c0aee5 Improve trigger handling on distributed hypertables
Triggers on distributed hypertables can now be renamed due to having
the rename statement forwarded to data nodes. This also applies to
other objects on such tables, like constraints and indexes, since they
share the same DDL "rename" machinery. Tests are added for these
cases.

For convenience, trigger functions on distributed hypertables will now
also be created automatically on the data nodes. In other words, it is
no longer necessary to pre-create the trigger function on all data
nodes.

This change also fixes an issue with statement-level triggers, which
weren't properly propagated to data nodes during `CREATE TRIGGER`.

Fixes #3238
2021-06-16 14:12:04 +02:00
Mats Kindahl
2cf3af1eb6 Fix dist_hypertable test for parallel execution
Change database names to be unique over the test suite by adding the
test database name in front of the created database names in the test.
This will allow the test to be executed in parallel with other tests
since it will not have conflicting databases in the same cluster.

Previously, there were a few directories created for tablespaces, but
this commit changes that to create one directory for each test where
the tablespace can be put. This is done by using a directory prefix for
each tablespace and each test should then create a subdirectory under
that prefix for the tablespace. The commit keeps variables for the old
tablespace paths around so that old tests work while transitioning to
the new system.
2020-10-21 15:28:58 +02:00
Sven Klemm
1f93536704 Change testsupport.sql to not reference tsl code
testsupport.sql had a reference to TSL code which will fail in
apache-only code since this file is included in every test run
for every build configuration.
2020-06-23 12:12:15 +02:00
niksa
c60cabd768 Improve relation size estimate
In case when there are no stats (number of tuples/pages) we
can use two approaches to estimate relation size: interpolate
relation size using stats from previous chunks (if exists)
or estimate using shared buffer size (shared buffer size should
align with chunk size).
2020-05-27 17:31:09 +02:00
Erik Nordström
3943a758a7 Refactor test of distributed hypertables
This refactors the `hypertable_distributed` test to make better use of
the `remote_exec` utility function. The refactoring also makes sure we
actually use space partitioning when testing distributed hypertables.
2020-05-27 17:31:09 +02:00
niksa
4368fcff3c Add function to reconstruct the creating command for a table
Deparse a table into a set of SQL commands that can be used to
reconstruct it. Together with column definiton it deparses
constraints, indexes, triggers and rules as well. There are some table
types that are not supported: temporary, partitioned, foreign,
inherited and a table that uses options.  Row security is also not
supported.
2020-05-27 17:31:09 +02:00
Brian Rowe
09616da90e Add support for PG12 COPY WHERE statements
PG12 allows users to add a WHERE clause when copying from from a
file into a table.  This change adds support for such clauses on
hypertables.  Also fixes a issue that would have arisen in cases
where a table being copied into had a trigger that caused a row to
be skipped.
2020-04-14 23:12:15 +02:00
Erik Nordström
d747e8d68a Make pg_dump tests use wrapper scripts
The `pg_dump` command has slightly different informational output
across PostgreSQL versions, which causes problems for tests. This
change makes sure that all tests that use `pg_dump` uses the
appropriate wrapper script where we can better control the output to
make it the same across PostgreSQL versions.

Note that the main `pg_dump` test still fails for other reasons that
will be fixed separately.
2020-04-14 23:12:15 +02:00
Erik Nordström
21dc7b9f7b Make tests using pg_dump work for PG12
PostgreSQL 12 changed the log level in client tools, such as
`pg_dump`, which makes some of our tests fail due to different log
level labels.

This change filters and modifies the log level output of `pg_dump` in
earlier PostgreSQL versions to adopt the new PostgreSQL 12 format.
2020-04-14 23:12:15 +02:00
Sven Klemm
0cc22ad278 Stop background worker in tests
To make tests more stable and to remove some repeated code in the
tests this PR changes the test runner to stop background workers.
Individual tests that need background workers can still start them
and this PR will only stop background workers for the initial database
for the test, behaviour for additional databases created during the
tests will not change.
2020-03-06 15:27:53 +01:00
Mats Kindahl
38654b2158 Print notice for COPY TO on hypertable
When using `COPY TO` on a hypertable (which copies from the hypertable
to some other destination), nothing will be printed and nothing will be
copied. Since this can be potentially confusing for users, this commit
print a notice when an attempt is made to copy from a hypertable
directly (not using a query) to some other destination.
2020-01-16 13:19:08 +01:00
Matvey Arye
db23139b3c Fix error for exported_uuid in pg_restore
When restoring a database, people would encounter errors if
the restore happened after telemetry has run. This is because
a 'exported_uuid' field would then exist and people would encounter
a "duplicate key value" when the restore tried to overwrite it.

We fix this by moving this metadata to a different key
in pre_restore and trying to move it back in post_restore.
If the restore create an exported_uuid, that restored
value is used and the moved version is simply deleted

We also remove the error redirection in restore so that errors
will show up in tests in the future.

Fixes #1409.
2019-10-30 11:40:24 -04:00
Sven Klemm
a1666544a2 Ignore .psqlrc in test_fatal_command
When a local .psqlrc sets options that modify output of psql the
loader test will fail. This patch changes the test to ignore
the .psqlrc file.
2019-08-26 08:59:24 +02:00
David Kohn
53f45864b6 Make version mismatch errors FATAL
We currently check and throw an error if the version loaded in the
client is different from the installed extension version, however
there is no way to recover from this state in a backend. (There is
no way to load the new version as we cannot unload the old and no
commands can be effectively run). Now, we instead throw a
FATAL error which will cause the client to reconnect so it can load
the proper extension version.
2019-08-21 14:37:29 -04:00
Erik Nordström
8eb647d4b1 Fix column name in show_columns test function
The "Nullable" column in the output of `show_columns` actually shows
NOT NULL constraints on a column, which is the inverse of what the
column name suggests. This changes "Nullable" to "NotNull" to avoid
confusion.
2019-06-12 07:55:44 -04:00
Joshua Lockerman
ffdc095d6e Enable creating indexes with one transaction per chunk
Currently CREATE INDEX creates the indices for all chunks in a single
transaction, which holds a lock on the root hypertable and all chunks. This
means that during CREATE INDEX no new inserts can occur, even if we're not
currently building an index on the table being inserted to.

This commit adds the option to create indices using a separate
transaction for each chunk. This option, used like

    CREATE INDEX ON <table> WITH (timescaledb.transaction_per_chunk);

should cause less contention than a regular CREATE INDEX, in exchange
for the possibility that the index will be created on only some, or none,
of the chunks, if the command fails partway through. The command holds a lock on
the root index used as a template throughout the command, and each of the only
additionally locks the chunk being indexed. This means that that chunks which
are not currently being indexed can be inserted to, and new chunks can be
created while the CREATE INDEX command is in progress.

To enable detection of failed transaction_per_chunk CREATE INDEXs, the
hypertable's index is marked as invalid while the CREATE INDEX is in progress,
if the command fails partway through, the index will remain invalid. If such an
invalid index is discovered, it can be dropped an recreated to ensure that all
chunks have a copy of the index, in the future, we may add a command to create
indexes on only those chunks which are missing them. Note that even though the
hypertable's index is marked as invalid, new chunks will have a copy of the
index build as normal.

As part of the refactoring to make this command work, normal index creation was
slightly modified. Instead of getting the column names an index uses
one-at-a-time we get them all at once at the beginning of index creation, this
allows to close the hypertable's root table once we've determined all of while
we create the index info for each chunk. Secondly, it changes our function to
lookup a tablespace, ts_hypertable_get_tablespace_at_offset_from, to only take a
hypertable id, instead of the hypertable's entire cache entry; this function
only ever used the id, so this allows us to release the hypertable cache earlier
2019-02-22 14:54:36 -05:00
Sven Klemm
f89fd07c5b Remove year from SQL file license text
This changes the license text for SQL files to be identical
with the license text for C files.
2019-01-13 23:30:22 +01:00
Sven Klemm
787cc0470e Replace hardcoded database name from regression tests
Replace hardcoded database name from regression tests with :TEST_DBNAME
Remove creation of database single_2 from test runner and add it to
bgw_launcher and loader test since no other tests used those
use SQL comments in test scripts
2018-12-28 19:26:27 +01:00
Sven Klemm
31e9c5b5cc Fix time column handling in get_create_command
Fixes get_create_command to produce a valid create_hypertable
call when the column name is a keyword
Add test.execute_sql helper function to test support functions
2018-12-28 18:15:57 +01:00
Joshua Lockerman
20ec6914c0 Add license headers to SQL files and test code 2018-10-29 13:28:19 -04:00
Joshua Lockerman
974788516a Prefix public C functions with ts_
We've decided to adopt the ts_ prefix on all exported C functions in
order to avoid having symbol conflicts with future postgres functions.
We've already started using this prefix on new functions and this commit
adds the prefix to to the old functions.
2018-09-27 11:45:04 -04:00
Sven Klemm
248f6621e4 Fix pg_dump for unprivileged users
When timescaledb is installed in template1 and a user with only createdb
privileges creates a database, the user won't be able to dump the
database because of lacking permissions. This patch grants the missing
permissions to PUBLIC for pg_dump to succeed.

We need to grant SELECT to PUBLIC for all tables even those not
marked as being dumped because pg_dump will try to access all
tables initially to detect inheritance chains and then decide
which objects actually need to be dumped.
2018-09-26 18:04:11 +02:00
Amy Tai
346191d15c Suppress NOTICE welcome message in tests
Suppress NOTICE in tests, either by setting client_min_messages=error or by redirecting pg_restore output (because pg_restore will clobber any client_min_messages value). Also added installation_metadata test back into CMakeList.
2018-09-12 07:42:51 -04:00
didier
0dc5bbb447 Use pg_config bindir directory for pg executables
In case pg_dump, createdb, dropdb and pg_restore aren't in system default path.
2018-09-11 12:30:31 -04:00
Rob Kiefer
61c56fdde1 Fix pg_dump test to work correctly on remote DBs
Using shell scripts in utils/ along with environmental vars we
know to be setup for the test, we can make the dump/restore test
work on remote platforms.
2018-09-08 10:09:44 -04:00
Rob Kiefer
98e56ddb81 Improve show_indexes test func to be more platform agnostic
Windows and Unix platforms had different orderings for some tests
in pg_dump. Now we order by a name that orders consistently on
both platforms.
2018-09-08 10:09:44 -04:00
Amy Tai
c71960c048 Fix pg_dump test and make insert block trigger a non-internal trigger
Previously, the pg_dump test was broken because it is not possible to reference psql variables
from inside bash commands run through psql. This is fixed by hardcoding the username passed to
the bash commands inside the test.

Also, we changed the insert block trigger preventing inserts into hypertable to a non-internal
trigger, because internal triggers are not dumped by pg_dump. We need to dump the trigger so that
it is already in place after a pg_restore, to prevent users from accidentally inserting rows into
a hypertable while timescaledb_restoring=on.
2018-09-04 18:34:57 -04:00
Erik Nordström
148f2da924 Use shared_buffers as the available cache memory
When configuring adaptive chunking and estimating the
chunk_target_size, we should use shared_buffers as an indication of
cache memory instead of trying to estimate based on
effective_cache_memory, system memory or other settings. This is
because shared_buffers should already have been set by the user based
on system memory, and also accurately reflects the cache memory
available to PostgreSQL.

We use a fraction (currently 0.9) of this cache memory as the
chunk_target_size. This assumes no concurrency with other hypertables.
2018-08-08 17:01:31 +02:00
Erik Nordström
9c9cdca6d3 Add support for adaptive chunk sizing
Users can now (optionally) set a target chunk size and TimescaleDB
will try to adapt the interval length of the first open ("time")
dimension in order to reach that target chunk size. If a hypertable
has more than one open dimension, only the first one will have a
dynamically adapting interval.

Users can optionally specify their own function that calculates the
new dimension interval. They can also set a target size of 0 in order
to estimate a suitable target size for a chunk based on available
memory.
2018-08-08 17:01:31 +02:00
Matvey Arye
05609cedae Add constraint options to test output 2018-08-07 10:13:29 -04:00
Erik Nordström
37142e9094 Block INSERTs on a hypertable's root table
A hypertable's root table should never have any tuples, but it can
acquire tuples by accident if the TimescaleDB extension is not
preloaded or `timescaledb.restoring` is set to ON.

To avoid the above issue, a hypertable's root table now has a
(internal) trigger that generates an error when tuples are
inserted. This preserves the integrity of the hypertable even when
restoring or the extension is not preloaded.

An internal trigger has the advantage of being mostly transparent to
users (e.g., it doesn't show up with \d) and it is not inherited by
chunks, so it needs no special handling to avoid adding it to chunks.

The blocking trigger is added in the update script and if it is
detected that the hypertable's root table has data in the process, the
update will fail with an error and instructions on how to fix.
2018-08-07 14:22:41 +02:00
Erik Nordström
1f2d27671b Fix and improve show_indexes test support function
This fixes the show_indexes test support function to properly show the
columns of the indexes instead of the table. The function now also
shows the expressions of expression indexes.
2018-08-03 09:51:28 +02:00
Erik Nordström
d135256ed7 Spread chunk indexes across tablespaces like chunks
Currently, chunk indexes are always created in the tablespace of the
index on the main table (which could be none/default one), even if the
chunks themselves are created in different tablespaces. This is
problematic in a multi-disk setting where each disk is a separate
tablespace where chunks are placed. The chunk indexes might exhaust
the space on the common (often default tablespace) which might not
have a lot of disk space. This also prohibits the database, including
index storage to grow by adding new tablespaces.

Instead, chunk indexes are now created in the "next" tablespace after
that of their chunks to both spread indexes across tablespaces and
avoid colocating indexes with their chunks (for I/O throughput
reasons). To optionally avoid this spreading, one can pin chunk
indexes to a specific tablespace by setting an explicit tablespace on
a main table index.
2018-01-19 10:48:45 +01:00
Erik Nordström
500563ffe5 Add support for PostgreSQL 10
The extension now works with PostgreSQL 10, while
retaining compatibility with version 9.6.

PostgreSQL 10 has numerous internal changes to functions and
APIs, which necessitates various glue code and compatibility
wrappers to seamlessly retain backwards compatiblity with older
versions.

Test output might also differ between versions. In particular,
the psql client generates version-specific output with `\d` and
EXPLAINs might differ due to new query optimizations. The test
suite has been modified as follows to handle these issues. First,
tests now use version-independent functions to query system
catalogs instead of using `\d`. Second, changes have been made to
the test suite to be able to verify some test outputs against
version-dependent reference files.
2017-11-10 09:44:20 +01:00