This repository was archived by the owner on Mar 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathpostgres-setup
More file actions
executable file
·64 lines (55 loc) · 1.76 KB
/
Copy pathpostgres-setup
File metadata and controls
executable file
·64 lines (55 loc) · 1.76 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
source "$HOME/.local/share/dotfiles/bin/lib/helpers.sh"
set -e
log_header "PostgreSQL Setup"
# Check if running as root
if [ "$EUID" -eq 0 ]; then
log_error "Don't run this script as root/sudo"
exit 1
fi
# Install PostgreSQL
log_step "Installing PostgreSQL..."
sudo pacman -S --needed postgresql
# Initialize the database cluster
log_step "Initializing database cluster..."
if [ ! -d "/var/lib/postgres/data/PG_VERSION" ]; then
sudo -u postgres initdb -D /var/lib/postgres/data \
--locale=C.UTF-8 \
--auth-local=peer \
--auth-host=scram-sha-256
log_success "Database cluster initialized"
else
log_info "Database cluster already exists, skipping initialization"
fi
# Enable and start PostgreSQL service
log_step "Enabling and starting PostgreSQL service..."
sudo systemctl enable postgresql
sudo systemctl start postgresql
# Test connection
log_step "Testing connection..."
if sudo -u postgres psql -c '\l' &>/dev/null; then
log_success "PostgreSQL is running and accessible"
else
log_error "Could not connect to PostgreSQL"
fi
# Create user role
log_step "Creating PostgreSQL role for $USER..."
if sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$USER'" | grep -q 1; then
log_info "Role '$USER' already exists"
else
sudo -u postgres createuser -s "$USER"
log_success "Role '$USER' created with superuser privileges"
fi
# Install Beekeeper Studio
log_step "Installing Beekeeper Studio..."
if ! command -v yay &>/dev/null; then
log_info "yay not installed, skipping Beekeeper Studio"
else
if yay -S --noconfirm beekeeper-studio-bin 2>/dev/null; then
log_success "Beekeeper Studio installed"
else
log_error "Could not install Beekeeper Studio"
log_detail "Install manually: yay -S beekeeper-studio-bin"
fi
fi
show_done