Skip to content

Commit fbcd48c

Browse files
committed
Use NullPool and keepalive settings for PostgreSQL
1 parent 6f54556 commit fbcd48c

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

backend/app/database.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
from sqlalchemy import create_engine
22
from sqlalchemy.ext.declarative import declarative_base
33
from sqlalchemy.orm import sessionmaker
4+
from sqlalchemy.pool import NullPool
45
import os
56
import sys
7+
import psycopg2
68

7-
# Force redeploy - testing SSL fix
89
DATABASE_URL = os.environ.get("DATABASE_URL")
910
sys.stderr.write(
10-
f"[DB DEBUG] DATABASE_URL: {DATABASE_URL[:100] if DATABASE_URL else 'None'}\n"
11+
f"[DB DEBUG] DATABASE_URL: {DATABASE_URL[:80] if DATABASE_URL else 'None'}\n"
1112
)
1213
sys.stderr.write(f"[DB DEBUG] DATA_DIR: {os.environ.get('DATA_DIR', 'Not set')}\n")
13-
sys.stderr.write(f"[DB DEBUG] Python version: {sys.version}\n")
1414

15-
# INTENTIONAL ERROR TO TEST IF CODE IS BEING USED
1615
RAILWAY_TEST_VARIABLE = "THIS_SHOULD_APPEAR_IN_LOGS_IF_CODE_IS_LOADED"
1716

1817
if DATABASE_URL:
1918
if DATABASE_URL.startswith("postgresql://"):
20-
sys.stderr.write(
21-
f"[DB DEBUG] Using DATABASE_URL: {DATABASE_URL[:80]}...\n"
22-
)
19+
sys.stderr.write(f"[DB DEBUG] Using PostgreSQL with NullPool\n")
2320
engine = create_engine(
2421
DATABASE_URL,
25-
pool_pre_ping=True,
26-
pool_recycle=300,
22+
poolclass=NullPool,
2723
connect_args={
2824
"connect_timeout": 10,
29-
"sslmode": "require"
30-
}
25+
"sslmode": "require",
26+
"keepalives": 1,
27+
"keepalives_idle": 30,
28+
"keepalives_interval": 10,
29+
"keepalives_count": 5,
30+
},
3131
)
3232
else:
3333
engine = create_engine(DATABASE_URL)
34-
else:
35-
engine = create_engine(DATABASE_URL)
3634
else:
3735
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
3836
DATA_DIR = os.environ.get("DATA_DIR", "/tmp")

0 commit comments

Comments
 (0)