Currently, the ai_vdb_provider_postgres module always establishes a separate connection to the Postgres database using pg_connect(). This can cause issues in environments where Drupal connects to the database via a UNIX socket or when the database is only accessible from Drupal's main connection.
Proposed enhancement:
Add a configuration option in the module settings to allow using Drupal’s default database connection instead of a separate pg_connect().
Update the PostgresPgvectorClient service so that its getConnection() method uses \Drupal::database() if this option is enabled.
Benefits:
Reuses the existing Drupal database connection, avoiding extra TCP connections and IP restrictions.
Works in environments where Drupal uses UNIX sockets.
Simplifies configuration in multi-environment setups (e.g., dev, staging, production).
Reduces duplication of credentials and potential configuration mistakes.
Improves consistency with Drupal’s standard database handling practices.
Implementation notes:
Add a checkbox in the module configuration form labeled "Use Drupal database connection".
When enabled, disable the host, port, username, password, and default database fields in the form.
Update the module schema to include the new configuration option so it is exported with configuration management.
The PostgresPgvectorClient::getConnection() service method should detect the checkbox and return the Drupal database connection when appropriate.
This feature improves flexibility, simplifies configuration, and resolves connection issues in environments where a direct TCP connection is not ideal or feasible.
Issue fork ai_vdb_provider_postgres-3562422
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments