hue-portal-backend / test_postgres_quick.sh
Davidtran99
chore: sync with main repo
3718c84
#!/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