forked from denoland/denokv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-postgres-auth.sh
More file actions
executable file
·87 lines (71 loc) · 2.92 KB
/
fix-postgres-auth.sh
File metadata and controls
executable file
·87 lines (71 loc) · 2.92 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# PostgreSQL Authentication Fix Script for Rocky Linux
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_status() { echo -e "${BLUE}[INFO]${NC} $1"; }
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
echo "🔧 PostgreSQL Authentication Fix Script"
echo "======================================="
echo ""
# Check if PostgreSQL is running
if ! systemctl is-active --quiet postgresql; then
print_status "Starting PostgreSQL service..."
sudo systemctl start postgresql
sleep 2
fi
# Find pg_hba.conf
PG_HBA_PATHS=(
"/var/lib/pgsql/data/pg_hba.conf"
"/var/lib/postgresql/data/pg_hba.conf"
"/etc/postgresql/*/main/pg_hba.conf"
)
PG_HBA_PATH=""
for path in "${PG_HBA_PATHS[@]}"; do
if [ -f "$path" ] || ls $path 2>/dev/null; then
PG_HBA_PATH="$path"
break
fi
done
if [ -z "$PG_HBA_PATH" ]; then
print_error "Could not find pg_hba.conf file"
print_status "Trying to find PostgreSQL data directory..."
sudo -u postgres psql -c "SHOW data_directory;" 2>/dev/null || true
exit 1
fi
print_status "Found pg_hba.conf at: $PG_HBA_PATH"
# Backup the original file
print_status "Creating backup of pg_hba.conf..."
sudo cp "$PG_HBA_PATH" "$PG_HBA_PATH.backup.$(date +%Y%m%d_%H%M%S)"
# Update authentication methods
print_status "Updating authentication methods..."
sudo sed -i 's/local all all ident/local all all md5/g' "$PG_HBA_PATH"
sudo sed -i 's/local all all peer/local all all md5/g' "$PG_HBA_PATH"
sudo sed -i 's/local all all trust/local all all md5/g' "$PG_HBA_PATH"
# Add explicit entry for denokv user if not present
if ! grep -q "denokv" "$PG_HBA_PATH"; then
print_status "Adding explicit entry for denokv user..."
echo "local denokv denokv md5" | sudo tee -a "$PG_HBA_PATH"
fi
# Reload PostgreSQL configuration
print_status "Reloading PostgreSQL configuration..."
sudo systemctl reload postgresql
# Test connection
print_status "Testing database connection..."
if PGPASSWORD='denokv_password' psql -h localhost -U denokv -d denokv -c "SELECT 1;" >/dev/null 2>&1; then
print_success "Database connection test successful!"
else
print_warning "Database connection test failed"
print_status "You may need to restart PostgreSQL: sudo systemctl restart postgresql"
fi
print_success "PostgreSQL authentication fix completed!"
echo ""
print_status "If you still have issues, try:"
echo " sudo systemctl restart postgresql"
echo " ./manage-services.sh restart"