SupabaseVectorStore connection (FastAPI backend on Render) failing with "OperationalError... Network is unreachable"

I have a Python backend for my LlamaIndex application (using FastAPI + Render) that uses “SupabaseVectorStore” to set up the connection with my Supabase DB. It works 100% fine locally on localhost, but when I host it in Render, I suddenly get this error:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at “db.[USER_HERE].supabase.co”, port [PORT_NUMBER] failed: Network is unreachable

Is the server running on that host and accepting TCP/IP connections?

The code where the Supabase DB connection is setup is:

import logging
import os

from llama_index.core.indices import VectorStoreIndex
from llama_index.vector_stores.pinecone import PineconeVectorStore
from llama_index.vector_stores.supabase import SupabaseVectorStore
from llama_index.core import StorageContext

logger = logging.getLogger("uvicorn")


def get_index():
    logger.info("Connecting to index from Supabase...")
    vector_store = SupabaseVectorStore(
        postgres_connection_string=f"postgresql://{os.environ['SUPABASE_DB_URL']}",
        collection_name="daily_notes",
    )
    storage_context = StorageContext.from_defaults(vector_store=vector_store)
    index = VectorStoreIndex(nodes=[], storage_context=storage_context)

    logger.info("Finished connecting to index from Supabase.")
    return index

where:

SUPABASE_DB_URL = postgresql://postgres:[YOUR-PASSWORD]@db.[USER].supabase.co:[PORT]/postgres

FYI, I am using the direct connection (postgresql://) version of the connection string, but also have tried connection pooling (postgres://) - with no success. All community docs on Render point me to use “postgresql://”.

Anyone have any idea how to fix this? I’ve been grappling with this for HOURS and am completely lost… :sob:

Hi Jae,

On the Render side, for troubleshooting purposes, you could try logging your Postgres connection string to make sure it’s what you expect (you might want to change your password after doing this).

Otherwise, I would check on your Supabase instance to ensure there are no access controls you need to set up (i.e. IP address allow lists, etc.).

Regards,

Matt