001project_wildgrowth/backend/deploy/check-database.sh

52 lines
1.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 数据库配置检查脚本
# 用于诊断数据库连接问题
echo "🔍 开始检查数据库配置..."
echo ""
# 1. 检查 PostgreSQL 服务状态
echo "1⃣ 检查 PostgreSQL 服务状态:"
systemctl status postgresql --no-pager | head -5
echo ""
# 2. 检查数据库连接
echo "2⃣ 测试数据库连接:"
PGPASSWORD=yangyichenYANGYICHENkaifa859 psql -h localhost -U postgres -d wildgrowth_app -c "SELECT version();" 2>&1
echo ""
# 3. 检查后端 .env 文件
echo "3⃣ 检查后端 .env 文件:"
if [ -f "/var/www/wildgrowth-backend/backend/.env" ]; then
echo "✅ .env 文件存在"
echo "DATABASE_URL 配置:"
grep "DATABASE_URL" /var/www/wildgrowth-backend/backend/.env | sed 's/:[^@]*@/:***@/g'
else
echo "❌ .env 文件不存在!"
fi
echo ""
# 4. 检查 PM2 服务状态
echo "4⃣ 检查 PM2 服务状态:"
pm2 status wildgrowth-api
echo ""
# 5. 检查后端日志(最近 20 行)
echo "5⃣ 检查后端日志(最近 20 行):"
if [ -f "/var/www/wildgrowth-backend/backend/logs/error.log" ]; then
echo "错误日志:"
tail -20 /var/www/wildgrowth-backend/backend/logs/error.log
else
echo "❌ 错误日志文件不存在"
fi
echo ""
# 6. 检查数据库是否存在
echo "6⃣ 检查数据库是否存在:"
PGPASSWORD=yangyichenYANGYICHENkaifa859 psql -h localhost -U postgres -lqt | cut -d \| -f 1 | grep -qw wildgrowth_app && echo "✅ 数据库 wildgrowth_app 存在" || echo "❌ 数据库 wildgrowth_app 不存在"
echo ""
echo "✅ 检查完成!"