Hi List,
I have no Google-fu. This is especially obvious when trying to search for something like I’m asking about.
Does anyone have any info or links to docs, blog posts, etc. that covers how to use connection pools with individual PostgreSQL user logins for a backend REST API?
The reason I ask is I’m using row level security (RLS) like in the example below from the PostgreSQL docs. I’ve only ever used a single application-specific account for accessing the database for all tenants. Now, however, each API key used in an API request will be tied to an account table and will have a PostgreSQL database user created for them so “current_user” works for RLS.
I’d like for requests to complete as fast as possible and I’m guessing there’s a better way than logging in to the database for each request.
The software involved is PostgreSQL 14, SQLAlchemy with asyncpg and FastAPI.
One example uses the DDL and policy:
CREATE TABLE accounts (manager text, company text, contact_email text);
ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;
CREATE POLICY account_managers ON accounts TO managers
USING (manager = current_user);
Thanks for your help.