mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 18:13:18 +08:00
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:
parent
b2682a7b57
commit
cb90eef350
@ -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
|
||||
|
@ -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();
|
||||
```
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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" (
|
||||
|
@ -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
|
||||
|
@ -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" (
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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" (
|
||||
|
@ -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" (
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user