250 Commits

Author SHA1 Message Date
Rob Kiefer
b1710f16bb Release 1.0.0-rc1 2018-09-12 07:59:55 -04:00
Lee Hampton
2b5bc30937 Prepare the repo for the next development cycle 2018-09-11 11:00:35 -04:00
Lee Hampton
86633c29f5 Release 0.12.0 2018-09-10 15:53:13 -04:00
Matvey Arye
f662ae1191 Add telemetry job and turn off default jobs in tests
This adds the telemetry job to the job scheduler. Telemetry is
scheduled to run every 24 hours with a 1 hour exponential backoff
retry period. Additional fixes related to the  telemetry job:

- Add separate ID space to the bgw_job table for default jobs. We do not dump this ID space inside pg_dump to prevent job insertion conflicts.
- Add check to update scripts for default jobs.
- Change shmem_callback so that it doesn't modify state since state transitions are not atomic with respect to interrupts and interrupt callbacks.
- Disable default telemetry job in regression and docker tests.
2018-09-10 13:29:59 -04:00
Erik Nordström
ebe0915669 Refactor telemetry and fixes
The installation metadata has been refactored:

- The installation metadata store now takes Datums of any
  type as input and output
- Move metadata functions from uuid.c -> metadata.c
- Make metadata functions return native types rather than text,
  including for tests

Telemetry tests for ssl and nossl have been combined.

Note that PG 9.6 does not have pg_backend_random() that gives us a
secure random numbers for UUIDs that we send in telemetry. Therefore,
we fall back to the generating the UUID from the timestamp if we are
on PG 9.6.

This change also fixes a number of test issues. For instance, in the
telemetry test the escape char `E` was passed on as part of the
response string when set as a variable with `\set`. This was not
detected before because the response parser didn't parse the start of
the response properly.

A number of fixes have been made to the formatting of log messages for
telemetry to conform to the PostgreSQL standard as well as being
consistent with other messages.

Numerous build issues on Windows have been resolved. There is also new
functionality to get OS version info on Windows (for telemetry),
including a SQL function get_os_info() to retrieve this information.

The net library will now allow connecting to a servicename, e.g., http
or https. A port is resolved from this service name via getaddrinfo().
An explicit port can still be given, and it that case it will not
resolve the service name.

Databases the are updated to the new version of the extension will
have an install_timestamp in their installation metadata that does not
reflect the actual original install date of the extension. To be able
to distinguish these updated installations from those that are freshly
installed, we add a bogus "epoch" install_timestamp in the update
script.

Parsing of the version string in the telemetry response has been
refactored to be more amenable to testing. Tests have been added.
2018-09-10 13:29:59 -04:00
Amy Tai
faf481b061 Add telemetry functionality
Adding the telemetry BGW and all auxiliary functions, such as generating a UUID, creating the internal metadata
table for storing UUIDs, and parsing the server-side response with the latest version of TimescaleDB.
2018-09-10 13:29:59 -04:00
Matvey Arye
5d8c7cc6f6 Add a scheduler for background jobs
TimescaleDB will want to run multiple background jobs. This PR
adds a simple scheduler so that jobs inserted into a jobs table
could be run on a schedule. This first implementation has two limitations:

1) The list of jobs to be run is read from the database when the scheduler
is first started. We do not update this list if the jobs table changes.

2) There is no prioritization for when to run jobs.

There design of the scheduler is as follows:
The scheduler itself is a background job that continuously runs and waits
for a time when  jobs need to be scheduled. It then launches jobs as new
background workers that it controls through the background worker handle.

Aggregate statistics about a job are kept in the job_stat catalog table.
These statistics include the start and finish times of the last run of the job
as well as whether or not the job succeeded. The next_start is used to
figure out when next to run a job after a scheduler is restarted.

The statistics table also tracks consecutive failures and crashes for the job
which is used for calculating the exponential backoff after a crash or failure
(which is used to set the next_start after the crash/failure). Note also that
there is a minimum time after the db scheduler starts up and a crashed job
is restarted. This is to allow the operator enough time to disable the job
if needed.

Note that the number of crashes is an overestimate of the actual number of crashes
for a job. This is so that we are conservative and never miss a crash and fail to
use the appropriate backoff logic.  Note that there is some complexity
in ensuring that all crashes are counted since a crash in Postgres causes /all/
processes to SIGQUIT: we must commit changes to the stats
table /before/ a job starts so that we can then deduce after a job has crashed
and the scheduler comes back up that a job was started, and not finished before
the crash (meaning that it could have been the crashing process).
2018-09-10 13:29:59 -04:00
David Kohn
55a7141953 Implement a cluster-wide launcher for background workers
The launcher controls how Timescale DB schedulers for each database are stopped/started
both at server start time and if they are started or stopped while the server is running
which can happen when, say, an update of the extension is performed.
Includes tests for multiple types of behavior within the launcher, but only a mock for the
db schedulers which will be dealt with in future commits. This launcher code is mostly in the loader,
as such it must remain backwards compatible for the foreseeable future, so significant thought and design
has gone into making interactions with this code well defined and consistent so that maintaining
backwards compatibility is relatively easy.
2018-09-10 13:29:59 -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
Lee Hampton
b376fc3b25 Prepare the repo for next development cycle 2018-08-09 13:18:16 -04:00
Lee Hampton
f67c10772f Release 0.11.0 2018-08-08 16:25:34 -04:00
Floris van Nee
1d9ade7145 add support for other types as timescale column 2018-08-08 11:45:23 -04:00
Erik Nordström
2e7b32cd91 Add WARNING when doing min-max heap scan for adaptive chunking
Adaptive chunking uses the min and max value of previous chunks
to estimate their "fill factor". Ideally, min and max should be
retreived using an index, but if no index exists we fall back
to a heap scan. A heap scan can be very expensive, so we now
raise a WARNING if no index exists.

This change also renames set_adaptive_chunk_sizing() to simply
set_adaptive_chunking().
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
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
Narek Galstyan
a8c637e112 Create aggregate functions only once to avoid dependency issues
There is no CREATE OR REPLACE AGGREGATE which means that the only way to replace
an aggregate is to DROP then CREATE which is problematic as it will fail
if the previous version of the aggregate has dependencies.
This commit makes sure aggregates are not dropped and recreated every time.
NOTE that WHEN CREATING NEW FUNCTIONS in sql/aggregates.sql you should also make
sure they are created in an update script so that both new users and people
updating from a previous version get the new function.
sql/aggregates.sql is run only once when TimescaleDB is installed and is not
rerun during updates that is why everything created there should also be in an
update file.
Fixes #612
2018-08-06 15:07:12 -04:00
Rob Kiefer
d967bce275 Prepare the repo for next development cycle 2018-07-13 15:22:12 -04:00
Rob Kiefer
f06f853f89 Release 0.10.1 2018-07-12 15:54:17 -04:00
David Kohn
8b58500d76 Fix bug where dropping triggers caused dangling references in pg_depend, disallow disabling triggers on hypertables 2018-07-11 13:44:22 -04:00
Rob Kiefer
67a8a41e22 Make chunk identifiers formatting safe using format 2018-07-11 11:54:33 -04:00
Rob Kiefer
41af6ff3ae Fix misreported toast_size in chunk_relation_size funcs
A bug in the SQL for getting the size of chunks would use the
TOAST size of the main/dummy table as the toast size for the
chunks rather than each chunks' own toast size.
2018-07-11 11:54:33 -04:00
Mike Futerko
4f2f1a6eb7 Update the error messages to conform with the style guide; Fix tests
An attempt to unify the error messages to conform with the PostgreSQL error
messages style guide. See the link below:
https://www.postgresql.org/docs/current/static/error-style-guide.html
2018-07-10 12:55:02 -04:00
Rob Kiefer
106adfb735 Prepare the repo for next development cycle 2018-06-28 15:38:50 -04:00
Rob Kiefer
5be8fb5301 Release 0.10.0 2018-06-27 11:36:38 -04:00
Narek Galstyan
4b4211fe94 Fix some external functions when setting a custom schema
Make sure internal references to timescale functions use the correct schema to refer to these functions. Fixes #554
2018-06-19 10:15:19 -04:00
Rob Kiefer
c660fcd8ff Add hypertable_approximate_row_count convenience function
Getting an approximate row count for a hypertable involves getting
estimates for all of its chunks rather than just looking up a
single value in the catalog tables. This PR provides a convenience
function for doing the JOINs/summing.
2018-05-18 10:21:43 -04:00
Rob Kiefer
02a8fc7e1a Prepare the repo for next development cycle 2018-05-07 11:09:19 -04:00
Rob Kiefer
ff3ab04bd9 Release 0.9.2 2018-05-04 13:41:39 -04:00
Rob Kiefer
43f812c158 Prepare the repo for next development cycle 2018-03-27 11:03:10 -04:00
Rob Kiefer
1fbb7e7466 Release 0.9.1 2018-03-26 15:13:43 -04:00
Rob Kiefer
63230c4c42 Prepare the repo for next development cycle 2018-03-06 12:14:31 -05:00
Erik Nordström
ddd61bc86d Fix update to 0.9.0
This fixes a bug in the upgrade script to 0.9.0 that was caused by a
bad query to delete orphaned dimension slices.
2018-02-28 10:55:43 -05:00
Erik Nordström
7883890a2d Fix update scripts for version 0.6.1
A fix for updates of version 0.6.1 was lost in the previous PR that
refactored the update process. This change adds back that fix.

The build process for update scripts now also supports versioned
"origin" modfiles, which are included only in the update scripts that
origins in a particular version given by the origin modfile's
name. Origin modfiles make it possible to add fixes that should be
included only for the version upgrading from.
2018-02-28 00:03:14 +01:00
Erik Nordström
939930881f Refactor/simplify update scripts and build process
Update scripts have so far been built by concatenating all the
historical changes and code from previous versions, leading to bloated
update scripts, complicated script build process, and the need to keep
old C-functions in compat.c since those functions are referenced
during updates.

This change greatly simplifies the way update scripts are built,
significantly reducing the size of update scripts (to basically only
the changeset + current code), and removing the need for compat.c.

A few principles of building scripts must be followed going forward,
as discussed in sql/updates/README.md.
2018-02-27 15:36:46 +01:00
Erik Nordström
7bd9437aba Do not generate versioned copies of SQL files
This removes the version suffix from SQL files that are copied from
the source directory to the build directory during the build process.

Versioning the files in this step serves no real purpose and only
tends to clutter up the build dir with extra files every time the
version is bumped, requiring manual cleanup.
2018-02-27 15:36:46 +01:00
Erik Nordström
db39eddf2e Remove unused cache invalidation triggers
The cache invalidation triggers on our catalog tables
aren't used anymore as all modifications to catalog tables
happen using the C API, which doesn't invoke triggers and
has its own cache invalidation functionality.
2018-02-26 20:10:31 +01:00
Matvey Arye
42c2f7b950 Add support for generating update scripts for skipped versions 2018-02-22 22:35:13 +05:30
Matvey Arye
93c76e75e1 Change trigger behavior on upgrades
For multi-version upgrades it is necessary to change the location of
trigger functions before doing anything else in upgrade scripts.
Otherwise, it is possible to trigger an even before you change the
location of the functions, which would load the old shared library
and break the system.

This commit also fixes `/sql/timescaledb--0.8.0--0.9.0.sql` to
come from the release build.
2018-02-22 22:35:13 +05:30
Rob Kiefer
1c03784ceb Release 0.9.0 2018-02-19 12:39:17 -05:00
Erik Nordström
ef744916a8 Migrate table data when creating a hypertable
Tables can now hold existing data, which is optionally migrated from
the main table to chunks when create_hypertable() is called.

The data migration is similar to the COPY path, with the single
difference that the inserted/copied tuples come from an existing table
instead of being read from a file. After the data has been migrated,
the main table is truncated.

One potential downside of this approach is that all of this happens in
a single transaction, which means that the table is blocked while
migration is ongoing, preventing inserts by other transactions.
2018-02-15 23:30:54 +01:00
Matvey Arye
26965826f4 Move index and constraints drop handling to event trigger
This Fixes at least two bugs:

1) A drop of a referenced table used to drop the associated
FK constraint but not the metadata associated with the constraint.
Fixes #43.

2) A drop of a column removed any indexes associated with the column
but not the metadata associated with the index.
2018-02-09 10:15:07 -05:00
Erik Nordström
d6baccb9d7 Improve tablespace handling, including blocks for DROP and REVOKE
This change improves the handling of tablespaces as follows:

- Add if_not_attached / if_attached options to attach_tablespace() and
  detach_tablespace(), respectively
- Block DROP tablespace if it is still attached to a table
- Block REVOKE if it means the table owner no longer has CREATE
  permissions on an attached tablespace
- Make error messages follow the PostgreSQL style guide
2018-02-05 23:16:20 +01:00
Erik Nordström
6adce4cbd8 Handle TRUNCATE without upcall and handle ONLY modifier
This change refactors the handling of TRUNCATE so
that it is performed directly in process utility without
doing an upcall to PL/pgSQL.

It also adds handling for the ONLY modifier to TRUNCATE,
which shouldn't work on a hypertable. TRUNCATE now generates
an error if TRUNCATE ONLY is used on a hypertable.
2018-02-01 10:12:48 +01:00
Erik Nordström
b7ebe06f2e Handle change owner without upcall
Changing the owner of a hypertable is now handled
entirely in the process utility hook without doing
an upcall to PL/pgSQL.
2018-01-31 22:42:37 +01:00
Erik Nordström
71b11240a7 Delete orphaned dimension slices
When chunks are deleted, dimension slices can be orphaned, i.e., there
are no chunks or chunk constraints that reference such slices. This
change ensures that, when chunks are deleted, orphaned slices are also
deleted.
2018-01-26 21:39:12 +01:00
Erik Nordström
fa19a54a88 Handle deletes on metadata objects via native catalog API
Deletes on metadata in the TimescaleDB catalog has so far been a mix
of native deletes using the C-based catalog API and SQL-based DELETE
statements that CASCADEs.

This mixed environment is confusing, and SQL-based DELETEs do not
consistently clean up objects that are related to the deleted
metadata.

This change moves towards A C-based API for deletes that consistently
deletes also the dependent objects (such as indexes, tables and
constraints).  Ideally, we should prohobit direct manipulation of
catalog tables using SQL statements to avoid ending up in a bad state.

Once all catalog manipulations happend via the native API, we can also
remove the cache invalidation triggers on the catalog tables.
2018-01-26 21:39:12 +01:00
Erik Nordström
6e011d12fb Refactor hypertable-related API functions
This is a continuation of prior efforts to refactor API functions in C
to:

- improve usage of proper error codes
- use error messages that better conform with the PostgreSQL standard.
- improve security by avoiding that lots of code run under SECURITY DEFINER
- move towards doing all metadata updates using a consistent catalog API

Most importantly, `create_hypertable()` has been refactored in C,
which simplifies a lot of code that previously required
upcalls/downcalls between C code and plpgsql code, or duplicated
functionality between the two environments.
2018-01-26 18:42:20 +01:00
Erik Nordström
71962b86ec Refactor dimension-related API functions
The functions for adding and updating dimensions have been refactored
in C to:

- improve usage of proper error codes
- make messages that better conform with the PostgreSQL standard.
- improve security by avoiding that lots of code run under SECURITY DEFINER

A new if_not_exists option has also been added to add_dimension() and
a the number of partitions can now be set using the new
set_number_partitions() function.

A bug in the validation of smallint time intervals has been fixed. The
previous code didn't check for intervals > 0 and smallint intervals
accepted values up to UINT16_MAX instead of INT16_MAX.
2018-01-25 19:02:34 +01:00
Matvey Arye
da8cc797a4 Add support for multiple extension version in one pg instance
This PR adds the ability to have multiple different versions of the timescaledb
extension be used by different databases in the same PostgreSQL
instance (server).

This is accomplished by splitting this extension into two .so files.
1) timescaledb.so -- stuff under loader/. Really not a lot of code.
    This code MUST be backwards compatible in the future.
2) timescaledb-version.so (most of our code). Need
   not be backwards compatible.

Timescaledb.so becomes a small stub which is preloaded and whose main
reason for existing is to dynamically load the right
timescaledb-version.so when the time comes.

This change allows either of the above .so to be loaded in
shared_preload_libraries. But timescaledb.so allows for multiple
versions used on different databases in the same instance along
with smoother upgrades. Using timescaledb-version.so allows for
finer-grained control and lock-in and is appropriate in only a few
production environments.

This PR also adds version checking so that a clear failure message
will be displayed if the .so version does not match the SQL extension
version.

To support multi-version functionality we changed the way SQL update
scripts are generated. Previously, the system used a bunch of
intermediate upgrade scripts.  So with 3 versions, you would have an
update script of 1--2, 2--3.  But, this PR changes things so that we
produce direct "shortcut" update files: 1--3, 2--3.
This is done for 2 reasons:
 1) Each of the update files should point to
    $libdir/timescaledb-current_version. Since you cannot guarantee that
    Previous .so for each intermediate version has been installed.
 2) You don't want intermediate version updates installed without the
    .so. For example, if you have versions 1,2,3
    and you are installing version 3, you want the upgrade files 1--3,
    2--3 but not 1--2 because if you have 1--2
    then a user could do ALTER EXTENSION timescaledb UPDATE TO 2. But
    the .so for version 2 may not be installed.

In order to test this functionality, we add a mock extension version .so
that we can test extension loading inside the regression framework.
2018-01-05 12:15:54 -05:00
Erik Nordström
4df8f287a6 Add proper permissions handling for associated (chunk) schemas
A hypertable's associated schema is used to create and store internal
data tables (chunks). A hypertable creates tables in that schema,
typically with full superuser permissions, regardless of whether the
hypertable's owner or the current user have permissions for the schema.
If the schema doesn't exist, the hypertable will create it when
creating the first chunk, even though the user or table owner does
not have permissions to create schemas in the database.

This change adds proper permissions checks to create_hypertable() so
that users cannot create hypertables with a custom associated schema
unless they have the proper permissions on the schema or the database.

Chunks are also no longer created with internal schema permissions if
the associated schema is something different from the internal schema.
2017-12-28 11:24:29 +01:00