Files
hotels/check_db.py
Фёдор 0cf3297290 Проект аудита отелей: основные скрипты и документация
- Краулеры: smart_crawler.py, regional_crawler.py
- Аудит: audit_orel_to_excel.py, audit_chukotka_to_excel.py
- РКН проверка: check_rkn_registry.py, recheck_unclear_rkn.py
- Отчёты: create_orel_horizontal_report.py
- Обработка: process_all_hotels_embeddings.py
- Документация: README.md, DB_SCHEMA_REFERENCE.md
2025-10-16 10:52:09 +03:00

101 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""Безопасная проверка структуры базы данных"""
import psycopg2
from urllib.parse import unquote
# Параметры подключения
DB_HOST = "147.45.189.234"
DB_PORT = 5432
DB_NAME = "default_db"
DB_USER = "gen_user"
DB_PASSWORD = unquote("2~~9_%5EkVsU%3F2%5CS")
print("Подключаюсь к базе данных...")
print(f"Host: {DB_HOST}")
print(f"Database: {DB_NAME}")
print(f"User: {DB_USER}")
print()
try:
conn = psycopg2.connect(
host=DB_HOST,
port=DB_PORT,
database=DB_NAME,
user=DB_USER,
password=DB_PASSWORD
)
cur = conn.cursor()
# Проверяем версию PostgreSQL
cur.execute("SELECT version();")
version = cur.fetchone()[0]
print(f"PostgreSQL версия: {version.split(',')[0]}")
print()
# Проверяем размер базы
cur.execute("""
SELECT pg_size_pretty(pg_database_size(current_database()));
""")
db_size = cur.fetchone()[0]
print(f"Размер базы: {db_size}")
print()
# Проверяем существующие таблицы
cur.execute("""
SELECT schemaname, tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) as size
FROM pg_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC
LIMIT 20;
""")
tables = cur.fetchall()
print("=== Существующие таблицы (топ 20 по размеру) ===")
if tables:
for schema, table, size in tables:
print(f" {schema}.{table} - {size}")
else:
print(" Пользовательских таблиц не найдено")
print()
# Проверяем есть ли таблицы с префиксом hotel
cur.execute("""
SELECT tablename
FROM pg_tables
WHERE schemaname = 'public' AND tablename LIKE 'hotel%';
""")
hotel_tables = cur.fetchall()
if hotel_tables:
print("=== Таблицы с префиксом 'hotel' ===")
for (table,) in hotel_tables:
print(f" {table}")
print()
# Проверяем лимиты подключений
cur.execute("""
SELECT setting FROM pg_settings WHERE name = 'max_connections';
""")
max_conn = cur.fetchone()[0]
print(f"Максимум подключений: {max_conn}")
cur.execute("""
SELECT count(*) FROM pg_stat_activity;
""")
active_conn = cur.fetchone()[0]
print(f"Активных подключений: {active_conn}")
print()
print("✓ Подключение успешно! База в порядке.")
cur.close()
conn.close()
except Exception as e:
print(f"✗ Ошибка подключения: {e}")
exit(1)