File size: 2,279 Bytes
3718c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

echo "============================================================"
echo "🔍 Quick Test PostgreSQL Connection"
echo "============================================================"
echo ""

HOST="postgres.aliss.io.vn"
PORT="5432"
USER="hue_remote"
PASSWORD="huepass123"
DB="hue_portal"

# Test 1: DNS Resolution
echo "1️⃣  Testing DNS resolution..."
if nslookup "$HOST" > /dev/null 2>&1; then
    IP=$(dig +short "$HOST" | head -1)
    echo -e "${GREEN}✅ DNS OK: $HOST → $IP${NC}"
else
    echo -e "${RED}❌ DNS FAILED${NC}"
    exit 1
fi

# Test 2: Port connectivity (timeout 5s)
echo ""
echo "2️⃣  Testing port connectivity (timeout 5s)..."
if timeout 5 bash -c "cat < /dev/null > /dev/tcp/$HOST/$PORT" 2>/dev/null; then
    echo -e "${GREEN}✅ Port $PORT is open${NC}"
else
    echo -e "${YELLOW}⚠️  Port test failed (có thể do firewall hoặc tunnel chưa ready)${NC}"
fi

# Test 3: PostgreSQL connection
echo ""
echo "3️⃣  Testing PostgreSQL connection (timeout 10s)..."
export PGPASSWORD="$PASSWORD"

if timeout 10 psql -h "$HOST" -p "$PORT" -U "$USER" -d "$DB" -c "SELECT 1 as test;" 2>&1 | grep -q "test"; then
    echo -e "${GREEN}✅ PostgreSQL connection SUCCESS!${NC}"
    echo ""
    echo "📝 DATABASE_URL:"
    echo "postgres://$USER:$PASSWORD@$HOST:$PORT/$DB"
    echo ""
    
    # Quick data check
    echo "4️⃣  Checking database data..."
    COUNT=$(timeout 10 psql -h "$HOST" -p "$PORT" -U "$USER" -d "$DB" -t -c "SELECT COUNT(*) FROM core_legaldocument;" 2>/dev/null | xargs)
    if [ -n "$COUNT" ]; then
        echo -e "${GREEN}✅ Database has $COUNT legal documents${NC}"
    else
        echo -e "${YELLOW}⚠️  Could not check data count${NC}"
    fi
    
    exit 0
else
    echo -e "${RED}❌ PostgreSQL connection FAILED${NC}"
    echo ""
    echo "💡 Troubleshooting:"
    echo "  1. Check tunnel logs on Unraid: docker logs mystifying_bassi --tail 20"
    echo "  2. Verify tunnel config has: postgres.aliss.io.vn → tcp://192.168.1.212:5432"
    echo "  3. Check PostgreSQL is running: docker ps | grep postgres"
    echo "  4. Try restart tunnel: docker restart mystifying_bassi"
    exit 1
fi