forked from melissa-hale/initPostgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_db.sh
28 lines (23 loc) · 908 Bytes
/
configure_db.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
set -e
# Check current wal_level setting
WAL_LEVEL=$(psql -t -c "SHOW wal_level;" --username "$POSTGRES_USER" --dbname "$POSTGRES_DB")
if [[ $WAL_LEVEL != "logical" ]]; then
# Drop timescaledb if exists and adjust parameters
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
DROP EXTENSION IF EXISTS timescaledb;
EOSQL
# Use ALTER SYSTEM commands outside of transaction block
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
ALTER SYSTEM SET wal_level = logical;
ALTER SYSTEM SET max_replication_slots = 20;
ALTER SYSTEM SET wal_keep_size = 2048;
EOSQL
# Reload the configuration
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
SELECT pg_reload_conf();
EOSQL
echo "All done please restart the database and delete this service."
else
echo "DB is already configured"
fi