-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-postgres.sh
More file actions
executable file
·29 lines (21 loc) · 1.17 KB
/
init-postgres.sh
File metadata and controls
executable file
·29 lines (21 loc) · 1.17 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
#!/bin/bash
# Initialize PostgreSQL in the combined container
set -e
# Initialize PostgreSQL if data directory is empty
if [ ! -f /var/lib/postgresql/data/PG_VERSION ]; then
echo "Initializing PostgreSQL database..."
su - postgres -c "/usr/lib/postgresql/14/bin/initdb -D /var/lib/postgresql/data"
# Start PostgreSQL temporarily to create database and user
su - postgres -c "/usr/lib/postgresql/14/bin/pg_ctl -D /var/lib/postgresql/data -l /var/lib/postgresql/data/logfile start"
# Wait for PostgreSQL to be ready
sleep 5
# Create database and user
su - postgres -c "psql -c \"CREATE USER ${POSTGRES_USER:-nexus} WITH PASSWORD '${POSTGRES_PASSWORD:-nexus}';\""
su - postgres -c "psql -c \"CREATE DATABASE ${POSTGRES_DB:-nexus} OWNER ${POSTGRES_USER:-nexus};\""
su - postgres -c "psql -d ${POSTGRES_DB:-nexus} -c \"CREATE EXTENSION IF NOT EXISTS vector;\""
# Stop PostgreSQL (supervisor will start it)
su - postgres -c "/usr/lib/postgresql/14/bin/pg_ctl -D /var/lib/postgresql/data stop"
echo "PostgreSQL initialized successfully"
else
echo "PostgreSQL data directory already exists, skipping initialization"
fi