Rename setup_db() and fix port for local connections

If a user attempts to setup a database while not connecting using
the network, port is NULL and thus fails constraint checks. Instead,
we now use the default Postgres port of 5432 when this happens.

Also, setup_db() is renamed to setup_timescaledb() for clarity in
the presence of other extensions.
This commit is contained in:
Rob Kiefer 2017-03-21 16:27:54 -04:00
parent b2682a7b57
commit cb90eef350
20 changed files with 38 additions and 31 deletions

View File

@ -92,7 +92,7 @@ CREATE database tutorial;
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
-- Run initialization function
SELECT setup_db();
SELECT setup_timescaledb();
```
For convenience, this can also be done in one step by running a script from

View File

@ -74,12 +74,12 @@ SELECT drop_chunks(interval '3 months', 'foo');
---
### `setup_db()`
### `setup_timescaledb()`
Initializes a Postgres database to fully use TimescaleDB.
**Sample usage**
```sql
SELECT setup_db();
SELECT setup_timescaledb();
```

View File

@ -17,6 +17,6 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
\o /dev/null
\echo 'Set up database...'
select setup_db();
select setup_timescaledb();
\echo 'Success'
EOF

View File

@ -17,6 +17,9 @@ BEGIN
LIMIT 1;
IF meta_row IS NULL THEN
IF port IS NULL THEN
port = 5432;
END IF;
PERFORM add_cluster_user(username, password);
PERFORM _timescaledb_internal.setup_meta();
INSERT INTO _timescaledb_catalog.meta (database_name, hostname, port, server_name)
@ -80,7 +83,7 @@ EXCEPTION
END
$BODY$;
CREATE OR REPLACE FUNCTION setup_db(
CREATE OR REPLACE FUNCTION setup_timescaledb(
database NAME = current_database(),
username TEXT = current_user,
password TEXT = NULL,
@ -97,6 +100,10 @@ BEGIN
FROM _timescaledb_catalog.meta
LIMIT 1;
IF port IS NULL THEN
port = 5432;
END IF;
IF meta_row IS NULL THEN
PERFORM set_meta(hostname, port, database, username, password);
PERFORM _timescaledb_internal.setup_main();

View File

@ -15,9 +15,9 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_db
----------
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_timescaledb
-------------------
(1 row)

View File

@ -12,9 +12,9 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_db
----------
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_timescaledb
-------------------
(1 row)

View File

@ -13,7 +13,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\o
\set ECHO ALL

View File

@ -13,7 +13,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\o
\set ECHO ALL

View File

@ -13,7 +13,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\o
\set ECHO ALL

View File

@ -13,7 +13,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\c single
CREATE TABLE PUBLIC."testNs" (

View File

@ -13,7 +13,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\o
\set ECHO ALL

View File

@ -15,7 +15,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\c single
CREATE TABLE PUBLIC."testNs" (

View File

@ -13,9 +13,9 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_db
----------
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_timescaledb
-------------------
(1 row)

View File

@ -13,9 +13,9 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_db
----------
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_timescaledb
-------------------
(1 row)

View File

@ -15,7 +15,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\c single
CREATE TABLE PUBLIC."testNs" (

View File

@ -13,7 +13,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\c single
CREATE TABLE PUBLIC."testNs" (

View File

@ -11,9 +11,9 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_db
----------
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
setup_timescaledb
-------------------
(1 row)

View File

@ -11,7 +11,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\o
\set ECHO ALL

View File

@ -13,7 +13,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
psql:include/create_single_db.sql:8: NOTICE: installing required extension "dblink"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "postgres_fdw"
psql:include/create_single_db.sql:8: NOTICE: installing required extension "hstore"
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose
\c single
\set ECHO ALL

View File

@ -6,5 +6,5 @@ CREATE DATABASE single;
\c single
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
SELECT setup_db(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
SELECT setup_timescaledb(hostname => 'fakehost'); -- fakehost makes sure there is no network connection
\set VERBOSITY verbose