mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 10:33:27 +08:00
Misc usability fixes
This commit is contained in:
parent
a86bb7e9d0
commit
97205a7cec
2
Makefile
2
Makefile
@ -39,6 +39,6 @@ test-docker: build-docker start-test-docker test-all stop-test-docker
|
||||
|
||||
# Setting up a single node database
|
||||
setup-single-node-db:
|
||||
PGDATABASE=test ./scripts/run_sql.sh setup_single_node_db.psql
|
||||
@PGDATABASE=postgres ./scripts/run_sql.sh setup_single_node_db.psql
|
||||
|
||||
.PHONY: build-docker start-docker stop-docker test-regression test-unit test-all test all setup-single-node-db
|
||||
|
13
README.md
13
README.md
@ -1,8 +1,11 @@
|
||||
### Prerequisites
|
||||
|
||||
You'll need to install [Docker](https://docs.docker.com/engine/installation/),
|
||||
You'll need to install and run [Docker](https://docs.docker.com/engine/installation/),
|
||||
which is the current way to run the database.
|
||||
|
||||
You need to install the [Postgres client](https://wiki.postgresql.org/wiki/Detailed_installation_guides)(psql).
|
||||
|
||||
|
||||
### Building and running in Docker
|
||||
|
||||
The `Makefile` included in this repo has convenient commands for building,
|
||||
@ -10,7 +13,7 @@ starting, and stopping a Docker image of **iobeamdb**:
|
||||
```bash
|
||||
# To build the image
|
||||
make build-docker
|
||||
# To start the image using docker run.
|
||||
# To start the image using docker run.
|
||||
# This creates a docker container named `iobeamdb`
|
||||
# with a data volume mount inside the `data` subdirectory.
|
||||
make docker-run
|
||||
@ -48,7 +51,7 @@ temperature and humidity across a collection of devices over time.
|
||||
First, create a regular SQL table:
|
||||
```sql
|
||||
CREATE TABLE conditions (
|
||||
time BIGINT NOT NULL,
|
||||
time TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
device_id TEXT NOT NULL,
|
||||
temperature DOUBLE PRECISION NULL,
|
||||
humidity DOUBLE PRECISION NULL
|
||||
@ -58,7 +61,7 @@ CREATE TABLE conditions (
|
||||
Next, convert it into a hypertable using the provided function
|
||||
`create_hypertable()`:
|
||||
```sql
|
||||
SELECT name FROM create_hypertable('"conditions"', 'time', 'device_id');
|
||||
SELECT create_hypertable('"conditions"', 'time', 'device_id');
|
||||
```
|
||||
|
||||
Now, a hypertable that is partitioned on time (using the values in the
|
||||
@ -77,7 +80,7 @@ Inserting data into the hypertable is done via normal SQL INSERT commands,
|
||||
e.g. using millisecond timestamps:
|
||||
```sql
|
||||
INSERT INTO conditions(time,device_id,temperature,humidity)
|
||||
VALUES(1484850291000, 'office', 70.0, 50.0);
|
||||
VALUES(NOW(), 'office', 70.0, 50.0);
|
||||
```
|
||||
|
||||
Similarly, querying data is done via normal SQL SELECT commands. Updating
|
||||
|
@ -22,7 +22,7 @@ CREATE OR REPLACE FUNCTION create_hypertable(
|
||||
placement chunk_placement_type = 'STICKY',
|
||||
chunk_size_bytes BIGINT = 1073741824 -- 1 GB
|
||||
)
|
||||
RETURNS _iobeamdb_catalog.hypertable LANGUAGE PLPGSQL VOLATILE AS
|
||||
RETURNS VOID LANGUAGE PLPGSQL VOLATILE AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
hypertable_row _iobeamdb_catalog.hypertable;
|
||||
@ -89,7 +89,7 @@ BEGIN
|
||||
);
|
||||
EXCEPTION
|
||||
WHEN unique_violation THEN
|
||||
RAISE EXCEPTION 'hypertable already exists: %', hypertable_name
|
||||
RAISE EXCEPTION 'hypertable % already exists', main_table
|
||||
USING ERRCODE = 'IO110';
|
||||
END;
|
||||
|
||||
@ -111,8 +111,6 @@ BEGIN
|
||||
_iobeamdb_internal.get_general_index_definition(indexrelid, indrelid)
|
||||
)
|
||||
WHERE indrelid = main_table;
|
||||
|
||||
RETURN hypertable_row;
|
||||
END
|
||||
$BODY$;
|
||||
|
||||
|
@ -39,5 +39,6 @@ DELETE FROM PUBLIC."Hypertable_1" ;
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'time', 'Device_id');
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'time', 'Device_id');
|
||||
SELECT set_is_distinct_flag('"public"."Hypertable_1_misspelled"', 'mispelled', true);
|
||||
SELECT set_is_distinct_flag('"public"."Hypertable_1"', 'mispelled', true);
|
||||
|
@ -90,20 +90,20 @@ LOCATION: truncate_identifier, scansup.c:205
|
||||
psql:cluster.sql:39: NOTICE: 42622: identifier "really_long_column_goes_on_and_on_and_on_and_on_and_on_and_on_and_on_and_on" will be truncated to "really_long_column_goes_on_and_on_and_on_and_on_and_on_and_on_a"
|
||||
LOCATION: truncate_identifier, scansup.c:205
|
||||
SELECT * FROM create_hypertable('"public"."testNs"', 'time', 'Device_id', hypertable_name=>'testNs');
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
--------+------------------+-----------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
testNs | public | testNs | _iobeamdb_internal | _hyper_1 | _iobeamdb_internal | _hyper_1_root | _iobeamdb_internal | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1 | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."testNs"', 'time', 'Device_id', hypertable_name=>'testNs');
|
||||
psql:cluster.sql:45: ERROR: IO110: hypertable already exists: testNs
|
||||
psql:cluster.sql:45: ERROR: IO110: hypertable "testNs" already exists
|
||||
LOCATION: exec_stmt_raise, pl_exec.c:3165
|
||||
\set ON_ERROR_STOP 1
|
||||
SELECT * FROM create_hypertable('"public"."testNs2"', 'time', 'Device_id', hypertable_name=>'testNs2');
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
---------+------------------+-----------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
testNs2 | public | testNs2 | _iobeamdb_internal | _hyper_3 | _iobeamdb_internal | _hyper_3_root | _iobeamdb_internal | _hyper_3_distinct | 1 | STICKY | time | bigint | Test1 | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT set_is_distinct_flag('"public"."testNs"', 'Device_id', TRUE);
|
||||
|
@ -67,9 +67,9 @@ create table test_schema.test_table(time bigint, temp float8, device_id text);
|
||||
(1 row)
|
||||
|
||||
select * from create_hypertable('test_schema.test_table', 'time', 'device_id');
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
------------------------+------------------+-----------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
test_schema.test_table | test_schema | test_table | _iobeamdb_internal | _hyper_1 | _iobeamdb_internal | _hyper_1_root | _iobeamdb_internal | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1 | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\C test2
|
||||
|
@ -55,9 +55,9 @@ CREATE TABLE PUBLIC."Hypertable_1" (
|
||||
);
|
||||
CREATE INDEX ON PUBLIC."Hypertable_1" (time, "Device_id");
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'time', 'Device_id');
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
-----------------------+------------------+-----------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
public."Hypertable_1" | public | Hypertable_1 | _iobeamdb_internal | _hyper_1 | _iobeamdb_internal | _hyper_1_root | _iobeamdb_internal | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1 | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM _iobeamdb_catalog.hypertable;
|
||||
|
@ -70,17 +70,20 @@ LOCATION: exec_stmt_raise, pl_exec.c:3165
|
||||
DELETE FROM PUBLIC."Hypertable_1" ;
|
||||
\set ON_ERROR_STOP 1
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'time', 'Device_id');
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
-----------------------+------------------+-----------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
public."Hypertable_1" | public | Hypertable_1 | _iobeamdb_internal | _hyper_1 | _iobeamdb_internal | _hyper_1_root | _iobeamdb_internal | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1 | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'time', 'Device_id');
|
||||
psql:ddl_errors.sql:42: ERROR: IO110: hypertable "Hypertable_1" already exists
|
||||
LOCATION: exec_stmt_raise, pl_exec.c:3165
|
||||
SELECT set_is_distinct_flag('"public"."Hypertable_1_misspelled"', 'mispelled', true);
|
||||
psql:ddl_errors.sql:42: ERROR: 42P01: relation "public.Hypertable_1_misspelled" does not exist
|
||||
psql:ddl_errors.sql:43: ERROR: 42P01: relation "public.Hypertable_1_misspelled" does not exist
|
||||
LINE 1: SELECT set_is_distinct_flag('"public"."Hypertable_1_misspell...
|
||||
^
|
||||
LOCATION: RangeVarGetRelidExtended, namespace.c:415
|
||||
SELECT set_is_distinct_flag('"public"."Hypertable_1"', 'mispelled', true);
|
||||
psql:ddl_errors.sql:43: ERROR: IO100: column "mispelled" does not exist
|
||||
psql:ddl_errors.sql:44: ERROR: IO100: column "mispelled" does not exist
|
||||
LOCATION: exec_stmt_raise, pl_exec.c:3165
|
||||
|
@ -36,9 +36,9 @@ CREATE TABLE PUBLIC."Hypertable_1" (
|
||||
);
|
||||
CREATE INDEX ON PUBLIC."Hypertable_1" (time, "Device_id");
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'time', 'Device_id');
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
-----------------------+------------------+-----------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
public."Hypertable_1" | public | Hypertable_1 | _iobeamdb_internal | _hyper_1 | _iobeamdb_internal | _hyper_1_root | _iobeamdb_internal | _hyper_1_distinct | 1 | STICKY | time | bigint | single | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM _iobeamdb_catalog.hypertable;
|
||||
|
@ -45,15 +45,15 @@ SELECT add_node('test2' :: NAME, 'localhost');
|
||||
CREATE TABLE drop_chunk_test1(time bigint, temp float8, device_id text);
|
||||
CREATE TABLE drop_chunk_test2(time bigint, temp float8, device_id text);
|
||||
SELECT create_hypertable('drop_chunk_test1', 'time', 'device_id', chunk_size_bytes => 10000);
|
||||
create_hypertable
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
(public.drop_chunk_test1,public,drop_chunk_test1,_iobeamdb_internal,_hyper_1,_iobeamdb_internal,_hyper_1_root,_iobeamdb_internal,_hyper_1_distinct,1,STICKY,time,bigint,Test1,10000)
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT create_hypertable('drop_chunk_test2', 'time', 'device_id', chunk_size_bytes => 10000);
|
||||
create_hypertable
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
(public.drop_chunk_test2,public,drop_chunk_test2,_iobeamdb_internal,_hyper_2,_iobeamdb_internal,_hyper_2_root,_iobeamdb_internal,_hyper_2_distinct,1,STICKY,time,bigint,Test1,10000)
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT c.id AS chunk_id, pr.partition_id, pr.hypertable_name, crn.schema_name AS chunk_schema, crn.table_name AS chunk_table, c.start_time, c.end_time
|
||||
|
@ -82,9 +82,9 @@ CREATE INDEX ON PUBLIC."testNs" ("timeCustom" DESC NULLS LAST, series_1) WHERE
|
||||
CREATE INDEX ON PUBLIC."testNs" ("timeCustom" DESC NULLS LAST, series_2) WHERE series_2 IS NOT NULL;
|
||||
CREATE INDEX ON PUBLIC."testNs" ("timeCustom" DESC NULLS LAST, series_bool) WHERE series_bool IS NOT NULL;
|
||||
SELECT * FROM create_hypertable('"public"."testNs"', 'timeCustom', 'device_id', hypertable_name=>'testNs', associated_schema_name=>'_iobeamdb_internal' );
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
--------+------------------+-----------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
testNs | public | testNs | _iobeamdb_internal | _hyper_1 | _iobeamdb_internal | _hyper_1_root | _iobeamdb_internal | _hyper_1_distinct | 1 | STICKY | timeCustom | bigint | Test1 | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT set_is_distinct_flag('"public"."testNs"', 'device_id', TRUE);
|
||||
@ -122,9 +122,9 @@ CREATE TABLE chunk_closing_test(
|
||||
);
|
||||
-- Test chunk closing/creation
|
||||
SELECT * FROM create_hypertable('chunk_closing_test', 'time', 'device_id', chunk_size_bytes => 10000);
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
---------------------------+------------------+--------------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
public.chunk_closing_test | public | chunk_closing_test | _iobeamdb_internal | _hyper_2 | _iobeamdb_internal | _hyper_2_root | _iobeamdb_internal | _hyper_2_distinct | 1 | STICKY | time | bigint | Test1 | 10000
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
INSERT INTO chunk_closing_test VALUES(1, 1, 'dev1');
|
||||
|
@ -56,9 +56,9 @@ CREATE INDEX ON PUBLIC."testNs" ("timeCustom" DESC NULLS LAST, series_1) WHERE
|
||||
CREATE INDEX ON PUBLIC."testNs" ("timeCustom" DESC NULLS LAST, series_2) WHERE series_2 IS NOT NULL;
|
||||
CREATE INDEX ON PUBLIC."testNs" ("timeCustom" DESC NULLS LAST, series_bool) WHERE series_bool IS NOT NULL;
|
||||
SELECT * FROM create_hypertable('"public"."testNs"', 'timeCustom', 'device_id', hypertable_name=>'testNs', associated_schema_name=>'testNs' );
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
testNs | public | testNs | testNs | _hyper_1 | testNs | _hyper_1_root | testNs | _hyper_1_distinct | 1 | STICKY | timeCustom | bigint | single | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT set_is_distinct_flag('"public"."testNs"', 'device_id', TRUE);
|
||||
@ -92,9 +92,9 @@ CREATE TABLE chunk_closing_test(
|
||||
);
|
||||
-- Test chunk closing/creation
|
||||
SELECT * FROM create_hypertable('chunk_closing_test', 'time', 'device_id', chunk_size_bytes => 10000);
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
---------------------------+------------------+--------------------+------------------------+-------------------------+--------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+------------------+------------+------------------
|
||||
public.chunk_closing_test | public | chunk_closing_test | _iobeamdb_internal | _hyper_2 | _iobeamdb_internal | _hyper_2_root | _iobeamdb_internal | _hyper_2_distinct | 1 | STICKY | time | bigint | single | 10000
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
INSERT INTO chunk_closing_test VALUES(1, 1, 'dev1');
|
||||
|
@ -54,9 +54,9 @@ CREATE TABLE PUBLIC."testNs" (
|
||||
);
|
||||
CREATE INDEX ON PUBLIC."testNs" (device_id, "timeCustom" DESC NULLS LAST) WHERE device_id IS NOT NULL;
|
||||
SELECT * FROM create_hypertable('"public"."testNs"', 'timeCustom', 'device_id', hypertable_name=>'testNs', associated_schema_name=>'testNs' );
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_column_name | time_column_type | created_on | chunk_size_bytes
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+------------------+-----------------------------+------------+------------------
|
||||
testNs | public | testNs | testNs | _hyper_1 | testNs | _hyper_1_root | testNs | _hyper_1_distinct | 1 | STICKY | timeCustom | timestamp without time zone | Test1 | 1073741824
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT set_is_distinct_flag('"public"."testNs"', 'device_id', TRUE);
|
||||
|
@ -3,7 +3,6 @@
|
||||
# To avoid pw writing, add localhost:5432:*:postgres:test to ~/.pgpass
|
||||
set -u
|
||||
set -e
|
||||
set -x
|
||||
|
||||
PWD=`pwd`
|
||||
DIR=`dirname $0`
|
||||
@ -12,4 +11,4 @@ export PGUSER=${PGUSER:-postgres}
|
||||
export PGHOST=${PGHOST:-localhost}
|
||||
export PGDATABASE=${PGDATABASE:-iobeam}
|
||||
|
||||
psql -v ON_ERROR_STOP=1 -f $DIR/sql/$1
|
||||
psql -v ON_ERROR_STOP=1 -q -X -f $DIR/sql/$1
|
||||
|
@ -2,9 +2,17 @@ CREATE DATABASE iobeam;
|
||||
|
||||
\c iobeam
|
||||
CREATE EXTENSION IF NOT EXISTS iobeamdb CASCADE;
|
||||
|
||||
\o /dev/null
|
||||
\echo 'Set up database as meta node...'
|
||||
select setup_meta();
|
||||
\echo 'Set up database as data node...'
|
||||
select setup_main();
|
||||
|
||||
SELECT add_cluster_user('postgres', NULL);
|
||||
|
||||
\echo 'Adding database to the single-node cluster...'
|
||||
SELECT set_meta('iobeam' :: NAME, 'localhost');
|
||||
SELECT add_node('iobeam' :: NAME, 'localhost');
|
||||
|
||||
\echo 'Success'
|
||||
|
Loading…
x
Reference in New Issue
Block a user