mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-19 12:13:24 +08:00
Add bash script for setting up single-node cluster with user-defined DB name
This commit is contained in:
parent
d3a3670aa6
commit
574d6202cd
@ -33,12 +33,12 @@ make -f docker test
|
|||||||
### Setting up a local single node database
|
### Setting up a local single node database
|
||||||
After starting the Docker image or local PostgreSQL server, you can initiate a local single node database:
|
After starting the Docker image or local PostgreSQL server, you can initiate a local single node database:
|
||||||
```bash
|
```bash
|
||||||
psql -U postgres -h localhost < scripts/sql/setup_single_node_db.psql
|
DB_NAME=iobeamdb ./scripts/setup-db.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
This will set up a database named `iobeamdb` which can be accessed with:
|
This will set up a database named `iobeamdb` which can be accessed with:
|
||||||
```bash
|
```bash
|
||||||
psql -U postgres -h localhost -d iobeamdb
|
psql -U postgres -d iobeamdb
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Creating a table
|
#### Creating a table
|
||||||
|
31
scripts/setup-db.sh
Executable file
31
scripts/setup-db.sh
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [[ -z "$DB_NAME" ]]; then
|
||||||
|
echo "The DB_NAME must be set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create data directories for tablespaces tests
|
||||||
|
psql -U postgres -v ON_ERROR_STOP=1 << EOF
|
||||||
|
\echo 'Creating database: ${DB_NAME}'
|
||||||
|
CREATE DATABASE ${DB_NAME};
|
||||||
|
|
||||||
|
\c ${DB_NAME}
|
||||||
|
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 iobeam to the single-node cluster...'
|
||||||
|
SELECT set_meta('${DB_NAME}' :: NAME, 'localhost');
|
||||||
|
SELECT add_node('${DB_NAME}' :: NAME, 'localhost');
|
||||||
|
|
||||||
|
\echo 'Success'
|
||||||
|
EOF
|
@ -1,19 +0,0 @@
|
|||||||
\set ON_ERROR_STOP 1
|
|
||||||
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 iobeam 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