Issue with PgVectorDb/PostgresDb Initialization - Custom User Not Created on Fresh Volume

Hi Agno Community/Developers,

We’re encountering an issue setting up our local development database using Agno (ag ws up) where the specified custom user is not being created during the initial database setup on a fresh Docker volume.

Our Setup:

  • Agno project with standard workspace/dev_resources.py.
  • Using PgVectorDb resource to define the local database container.
  • Target configuration: User jpsn, Database ai, Password specified.
  • .env file correctly configured for local connections (DB_USER=jpsn, DB_DATABASE=ai, DB_HOST=localhost, etc.).
  • Initially used the default PgVectorDb image (agnohq/pgvector:16), also tested with pgvector/pgvector:pg16.

Configuration in dev_resources.py:

# In jpsn-app/workspace/dev_resources.py
from agno.docker.app.postgres import PgVectorDb 
# (or from agno.docker.app.postgres import PostgresDb if testing that)
# ... other imports ...

dev_db = PgVectorDb( # Or PostgresDb(...) if testing base class
    name="jpsn-app-db",
    # image_name="...", # Tried agnohq/pgvector:16 and pgvector/pgvector:pg16
    # image_tag="...",
    pg_user="jpsn",             # Target user
    pg_password="<our_password>", # Target password
    pg_database="ai",           # Target database
    host_port=5432,
)

# ... rest of dev_resources.py defining container_env using dev_db.get_db_* methods ...

Problem Description:

When we attempt to start the local development environment from a completely clean state (ensuring the database Docker volume is removed), the database container fails to initialize correctly with the specified jpsn user.

Steps Taken (Repeatedly):

  1. Run ag ws down.
  2. Identify the correct database Docker volume (e.g., jpsn-app-db-volume) using docker volume ls.
  3. Successfully remove the volume using docker volume rm <volume_name> (confirmed removal with docker volume ls).
  4. Run ag ws up.

Observed Behavior:

  1. DB Container Logs: Show signs of fresh initialization (e.g., CREATE DATABASE, CREATE EXTENSION, crucially no “Skipping initialization” message). However, there’s no explicit log confirming user jpsn creation.
  2. API/App Container Logs: Often show successful connection (Connected to tcp://jpsn-app-db:5432) and sometimes successful internal Alembic migration checks (likely due to trust authentication within the Docker network).
  3. Host Connection Attempts (psql/PGAdmin/Local Alembic): When trying to connect from the host machine to localhost:5432 as user jpsn to database ai, we consistently get:
    FATAL: role "jpsn" does not exist
  4. Default User Failure: Attempts to connect as the default postgres user (e.g., psql -U postgres -d postgres) also fail with FATAL: role "postgres" does not exist, even after configuring dev_resources.py to use pg_user="postgres" and pg_database="postgres" during initialization.
  5. Container Env Variables Confirmed: Running docker exec <db_container_id> printenv | grep POSTGRES confirms that the database container is being launched with the correct environment variables (POSTGRES_USER=jpsn, POSTGRES_PASSWORD=<our_password>, POSTGRES_DB=ai) based on the dev_resources.py configuration.

Conclusion:

Despite the Agno framework correctly setting the standard POSTGRES_ environment variables for the database container, the initialization scripts within the tested images (agnohq/pgvector:16, pgvector/pgvector:pg16) are failing to create the specified user (jpsn) or even the default postgres user reliably when starting with an empty volume in our Agno setup.

Questions:

  1. Is this a known issue with PgVectorDb/PostgresDb or these specific images within the Agno environment?
  2. Is there a different or additional configuration required in dev_resources.py (e.g., specific env_vars, different parameters) to ensure user creation works correctly during initialization with these images?
  3. What is the recommended approach within Agno to reliably initialize a local PostgreSQL/PgVector database with a custom user and password when starting from a clean volume?

Any insights or suggestions would be greatly appreciated!

Hi @Tristan
thanks for reaching out and supporting Agno!We’ve shared this with the team and are working through requests one by one—we’ll get back to you as soon as we can.We’ve just kicked off the Global Agent Hackathon , so things are a bit busier than usual. If you’re up for it, we’d love for you to join—it’s a great chance to build, win some exciting prizes and connect with the agent community!If it’s urgent, just let us know. Thanks for your patience!

Thank you. We are not able to create any more tables and fields in our localhost db. We have a user (jpsn) that is specified in dev_resources.py and when we try and connect to it using psql, we get: “role jpsn does not exist”. Yet we know the db is created using this user:

  • pg_user=‘jpsn’

  • pg_password=‘XXX’

  • pg_database=‘ai’

Hi @Tristan . Our team is looking into it to be able to replicate this issue and solve it. We will unblock you soon .Thanks

Thank you. Update: I ran the docker exec command: docker exec -it jpsn-app-api alembic -c db/alembic.ini revision --autogenerate -m inside the container and it appears to work. So let’s close this. It was my poor understanding of the solution. Thanks all!