Function: createServicePrincipalPool()
createServicePrincipalPool(
pgConfig):Promise<Pool>
Build a dedicated service-principal Lakebase pool for Mastra memory from the lakebase plugin’s resolved SP pg config.
The plugin’s exports().pool is a RoutingPool that switches to
the per-user (OBO) pool whenever a query runs inside an asUser
scope - exactly the context the mastra plugin establishes around
every chat turn. Memory (threads / messages + semantic recall) must
instead always act as the app service principal: it owns the
auto-created mastra_* schemas (a per-user role usually can’t
CREATE SCHEMA) and is shared across users, so it cannot inherit a
request’s OBO identity.
pgConfig must be the plugin’s exports().getPgConfig() evaluated
outside any asUser scope (i.e. during setup), so it carries
the SP connection target, OAuth token-refresh password callback,
and any lakebase({ pool }) tuning overrides - all of which this
pool inherits. See the call site in plugin.ts.
Parameters
Section titled “Parameters”pgConfig
Section titled “pgConfig”PoolConfig
Returns
Section titled “Returns”Promise<Pool>