This error occurs when the database URL format is invalid. SQLAlchemy requires a specific URL format.
postgresql://username:password@host:port/database
postgresql+psycopg2://username:password@host:port/database
❌ Wrong:
localhost:5432/adk_db
postgres:postgres@localhost:5432/adk_db
✅ Correct:
postgresql://postgres:postgres@localhost:5432/adk_db
If your password contains special characters like @, #, %, etc., they need to be URL-encoded.
Example:
- Password:
my@pass#123 - URL-encoded:
my%40pass%23123 - Full URL:
postgresql://user:my%40pass%23123@localhost:5432/db
Or use environment variables:
export DBUSER="user"
export DBPASSWORD="my@pass#123"
export DBURL="localhost:5432/db"Make sure the environment variable is actually set:
# Check if set
echo $DATABASE_URL
# Set it
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/adk_db"The URL is automatically trimmed, but check for hidden characters:
# Good
export DATABASE_URL="postgresql://user:pass@host/db"
# Bad (extra spaces)
export DATABASE_URL=" postgresql://user:pass@host/db "Use the test script to validate your URL:
python test_db_url.pyOr test manually:
from sqlalchemy import create_engine
db_url = "postgresql://postgres:postgres@localhost:5432/adk_db"
engine = create_engine(db_url)
print("✅ URL is valid!")export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/adk_db"export DATABASE_URL="postgresql://postgres:postgres@localhost/adk_db"
# Port 5432 is assumedexport DATABASE_URL="postgresql://user:pass@db.example.com:5432/mydb"export DATABASE_URL="postgresql://user:pass@host:5432/db?sslmode=require"-
Check environment variable:
echo $DATABASE_URL
-
Test URL format:
python test_db_url.py
-
Check PostgreSQL is running:
psql -U postgres -h localhost -c "SELECT version();" -
Try connecting manually:
psql "postgresql://postgres:postgres@localhost:5432/adk_db" -
Check server logs: The server will log the database URL (first 50 chars) if there's an error.
If you're getting the error, try:
-
Set a simple test URL:
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/adk_db"
-
Verify it works:
python test_db_url.py
-
Run the server:
python -m google.adk.server.postgres_app_server --port 8000