Faz ajustes de tempo entre testes de Proxy e ajusta compose
This commit is contained in:
93
test_connection.py
Normal file
93
test_connection.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""Test database connection and list available databases."""
|
||||
import psycopg2
|
||||
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
|
||||
|
||||
# Connection details
|
||||
HOST = "154.12.229.181"
|
||||
PORT = 5666
|
||||
USER = "leolitas"
|
||||
PASSWORD = "L@l321321321"
|
||||
|
||||
print(f"Testing connection to {HOST}:{PORT}")
|
||||
print(f"User: {USER}")
|
||||
print("-" * 50)
|
||||
|
||||
try:
|
||||
# First, connect to postgres database to list all databases
|
||||
print("\n1. Connecting to 'postgres' database...")
|
||||
conn = psycopg2.connect(
|
||||
host=HOST,
|
||||
port=PORT,
|
||||
database="postgres",
|
||||
user=USER,
|
||||
password=PASSWORD
|
||||
)
|
||||
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
# List all databases
|
||||
print("\n2. Available databases:")
|
||||
cursor.execute("SELECT datname FROM pg_database WHERE datistemplate = false;")
|
||||
databases = cursor.fetchall()
|
||||
for db in databases:
|
||||
print(f" - {db[0]}")
|
||||
|
||||
# Check if 'proxies' database exists
|
||||
cursor.execute("SELECT 1 FROM pg_database WHERE datname = 'proxies';")
|
||||
exists = cursor.fetchone()
|
||||
|
||||
if exists:
|
||||
print("\n✓ Database 'proxies' EXISTS")
|
||||
|
||||
# Try to connect to proxies database
|
||||
print("\n3. Connecting to 'proxies' database...")
|
||||
conn.close()
|
||||
|
||||
conn_proxies = psycopg2.connect(
|
||||
host=HOST,
|
||||
port=PORT,
|
||||
database="proxies",
|
||||
user=USER,
|
||||
password=PASSWORD
|
||||
)
|
||||
cursor_proxies = conn_proxies.cursor()
|
||||
|
||||
# Check if table exists
|
||||
cursor_proxies.execute("""
|
||||
SELECT EXISTS (
|
||||
SELECT FROM information_schema.tables
|
||||
WHERE table_name = 'proxies'
|
||||
);
|
||||
""")
|
||||
table_exists = cursor_proxies.fetchone()[0]
|
||||
|
||||
if table_exists:
|
||||
print("✓ Table 'proxies' EXISTS")
|
||||
|
||||
# Get row count
|
||||
cursor_proxies.execute("SELECT COUNT(*) FROM proxies;")
|
||||
count = cursor_proxies.fetchone()[0]
|
||||
print(f"✓ Table has {count} rows")
|
||||
else:
|
||||
print("✗ Table 'proxies' DOES NOT EXIST")
|
||||
print("\nYou need to run init-db.sql")
|
||||
|
||||
cursor_proxies.close()
|
||||
conn_proxies.close()
|
||||
|
||||
else:
|
||||
print("\n✗ Database 'proxies' DOES NOT EXIST")
|
||||
print("\nTo create it, run:")
|
||||
print(f" CREATE DATABASE proxies;")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("Connection test completed successfully!")
|
||||
|
||||
except psycopg2.OperationalError as e:
|
||||
print(f"\n✗ Connection ERROR: {e}")
|
||||
except Exception as e:
|
||||
print(f"\n✗ Unexpected ERROR: {e}")
|
||||
Reference in New Issue
Block a user