Skip to content

This library DatabaseSessionService is showing error #3916

Closed

Description

@nazarcoder123

I would like official support and documentation for storing conversations/sessions in PostgreSQL, including:

A documented PostgreSQL-backed session or conversation store

Example schema (tables for sessions, messages, metadata)

Sample code showing:

How to configure ADK to use PostgreSQL

How to store and retrieve conversation history

Support for async DB engines (e.g. asyncpg, SQLAlchemy async)

Ideally, this could be similar to how other storage backends are abstracted, but backed by PostgreSQL for persistence.

Activity

  1. added
    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc
    on Dec 13, 2025
  2. added theissue type on Dec 13, 2025
  3. AlejandroBlanco2001 commented on Dec 15, 2025

    @AlejandroBlanco2001

    Hey @nazarcoder123, I’m currently using PostgreSQL in a production application with ADK handling short-term memory. I followed the resources below:

    Using these two references, you can address the first two bullet points you mentioned. Additionally, if you are building your application as an HTTP server (for example, with FastAPI), you can leverage the ADK-provided endpoints to create and retrieve sessions.

    For a practical overview of the available endpoints, see this Medium post

    Regarding the async engines, I haven't tried those right now, however I know this PR that should allow you to use it right now. I will suggest take a look to both the PR and the original issue

  4. DeanChensj commented on Dec 15, 2025

    @DeanChensj
    Collaborator

    Thanks @AlejandroBlanco2001 for the detailed answer, yes we do support PostgreSQL as session service using DatabaseSessionService.

    @nazarcoder123 let us know if you have more questions, thanks!

  5. self-assigned this
    on Dec 15, 2025
  6. nazarcoder123 commented on Dec 15, 2025

    @nazarcoder123
    Author

    python version 3.11.0 im using here your library DatabaseSessionService is not working???????

    File "E:\post\auto\tool_agent_init_.py", line 1, in
    from . import agent
    File "E:\post\auto\tool_agent\agent.py", line 6, in
    session_service = DatabaseSessionService(db_url=db_url)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "E:\post.venv\Lib\site-packages\google\adk\sessions\database_session_service.py", line 457, in init
    raise ValueError(
    ValueError: Fail to load 'tool_agent' module. Failed to create database engine for URL 'sqlite:///./my_agent_data.db'
    INFO: 127.0.0.1:58838 - "GET /debug/trace/session/da0c91be-9891-4b10-9190-65a5b68a4c94 HTTP/1.1" 200 OK

    Image
  7. changed the title [-]Support PostgreSQL for Conversation / Session Persistence (Documentation & Examples Needed)[/-] [+]This library DatabaseSessionService is showing error[/+] on Dec 15, 2025
  8. nazarcoder123 commented on Dec 15, 2025

    @nazarcoder123
    Author
  9. AlejandroBlanco2001 commented on Dec 15, 2025

    @AlejandroBlanco2001

    @nazarcoder123 Can you share details like the ADK version and if you have already the SQLite driver installed?

  10. nazarcoder123 commented on Dec 16, 2025

    @nazarcoder123
    Author

    I'm using google-adk version == 1.21.0. This library DatabaseSessionService is not working.
    python version == 3.11.0
    Kindly check with this issue
    I have also used different version of python like 3.13.0 , 3.20.0 & 3.12.0
    But same issue library issue is is shown plz kindly resolve this issue

  11. AlejandroBlanco2001 commented on Dec 16, 2025

    @AlejandroBlanco2001

    Hey @nazarcoder123, I did a bit of experimentation around your SQLite issue and revisited my original PostgreSQL setup. In my PostgreSQL configuration, I did not explicitly specify an async dialect (in the url). However, I noticed that using the same approach you are using for SQLite does not work in this case because DatabaseSessionService relies on SQLAlchemy’s create_async_engine.

    You can see the relevant implementation here

    After digging further, it appears that with PostgreSQL, SQLAlchemy can transparently handle async vs. sync usage. In practice, when calling create_async_engine() with a URL such as postgresql+psycopg://..., SQLAlchemy will automatically select the appropriate async implementation. From the documentation:

    Calling create_async_engine() with postgresql+psycopg://... will automatically select the async version.

    Relevant references:

    So, to make it work for SQLite you must do something like:

    from google.adk.sessions import DatabaseSessionService
    
    service = DatabaseSessionService(db_url="sqlite+aiosqlite:///./sessions_management.db") 

    @DeanChensj I think it may be worth reopening the ticket to document this caveat in the DatabaseSessionService, as it could help avoid confusion. I am happy to take care of it.

  12. nazarcoder123 commented on Dec 16, 2025

    @nazarcoder123
    Author

    you are sharing some very complex things to understand I want to make it clear I have used used this before as well
    I have never did so many stuff back. What I am saying is currently in your latest version of google-adk DatabaseSessionService this library is not working. I will share you one link of youtube see that how easily it used to work earlier
    link: https://youtu.be/P4VFL9nIaIA?si=258C90DlV13xv56F
    watch from 1:14:00

  13. AlejandroBlanco2001 commented on Dec 16, 2025

    @AlejandroBlanco2001

    I completely understand the issue. The video you shared is approximately seven months old, and since then this PR — #2889 — changed the implementation to be asynchronous (September 9).

    As a result, your db_urlis not working because it now expects an asynchronous SQLite driver.

    The only change you need to make is to add +aiosqlite to your db_url variable.

    from google.adk.sessions import DatabaseSessionService
    
    service = DatabaseSessionService(db_url="sqlite+aiosqlite:///./your_database_name.db") 
  14. nazarcoder123 commented on Dec 16, 2025

    @nazarcoder123
    Author

    Thanks you it is working.
    do you have any repo for postgresql connection how to connect to postgresql i need th entire project. repository If you help me it will be a lot to me. plz

  15. AlejandroBlanco2001 commented on Dec 16, 2025

    @AlejandroBlanco2001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions