-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathpostgres.sh
More file actions
executable file
·49 lines (42 loc) · 1.63 KB
/
Copy pathpostgres.sh
File metadata and controls
executable file
·49 lines (42 loc) · 1.63 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
set -Eeu
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
# shellcheck source=../.env
. "$SCRIPT_DIR/../.env"
DOCKER="docker"
CONTAINER="${1:-peerdb-postgres}"
# select per-instance vars based on container name
case "$CONTAINER" in
peerdb-postgres2)
PG_INSTANCE_USER="$PG2_USER"
PG_INSTANCE_DATABASE="$PG2_DATABASE"
PG_INSTANCE_HOST="$PG2_HOST"
PG_INSTANCE_PORT="$PG2_PORT"
;;
*)
PG_INSTANCE_USER="$PG_USER"
PG_INSTANCE_DATABASE="$PG_DATABASE"
PG_INSTANCE_HOST="$PG_HOST"
PG_INSTANCE_PORT="$PG_PORT"
;;
esac
echo "install pgvector extension"
if ! $DOCKER exec "$CONTAINER" test -d /tmp/pgvector; then
$DOCKER exec "$CONTAINER" apk add --no-cache build-base git
$DOCKER exec "$CONTAINER" git clone --branch v0.8.1 https://github.com/pgvector/pgvector.git /tmp/pgvector
$DOCKER exec "$CONTAINER" sh -c 'cd /tmp/pgvector && make with_llvm=no && make with_llvm=no install'
fi
echo "create extensions and configure replication"
$DOCKER exec "$CONTAINER" psql -U "$PG_INSTANCE_USER" -d "$PG_INSTANCE_DATABASE" \
-c "CREATE EXTENSION IF NOT EXISTS hstore;" \
-c "CREATE EXTENSION IF NOT EXISTS vector;" \
-c "ALTER SYSTEM SET wal_level=logical;" \
-c "ALTER SYSTEM SET max_replication_slots=192;" \
-c "ALTER SYSTEM SET max_wal_senders=256;" \
-c "ALTER SYSTEM SET max_connections=2048;"
echo "restart postgres to apply config changes"
CURRENT_WAL=$($DOCKER exec "$CONTAINER" psql -U "$PG_INSTANCE_USER" -d "$PG_INSTANCE_DATABASE" -tAc "SHOW wal_level;")
if [ "$CURRENT_WAL" != "logical" ]; then
$DOCKER restart "$CONTAINER"
fi
echo "PostgreSQL is ready at ${PG_INSTANCE_HOST}:${PG_INSTANCE_PORT}"