© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4mo ago•
5 replies
Deprecated Dev

RLS not working when connecting using Database connection string with Drizzle ORM

I have this
connection.ts
connection.ts

const connectionString = serverEnv.SUPABASE_DATABASE_URL;

const pool = postgres(connectionString, { max: 1 });
export const connection = pool;
export const db: PostgresJsDatabase<typeof schema> = drizzle(pool, { schema });

(async () => {
  try {
    const result = await pool`
      SELECT current_user, session_user, inet_client_addr(), rolname, rolsuper, rolreplication, rolbypassrls 
      FROM pg_roles 
      WHERE rolname = current_user;
    `;
    console.log("DB connection user info:", result[0]);
  } catch (err) {
    console.error("Failed to query user info:", err);
  }
})();
const connectionString = serverEnv.SUPABASE_DATABASE_URL;

const pool = postgres(connectionString, { max: 1 });
export const connection = pool;
export const db: PostgresJsDatabase<typeof schema> = drizzle(pool, { schema });

(async () => {
  try {
    const result = await pool`
      SELECT current_user, session_user, inet_client_addr(), rolname, rolsuper, rolreplication, rolbypassrls 
      FROM pg_roles 
      WHERE rolname = current_user;
    `;
    console.log("DB connection user info:", result[0]);
  } catch (err) {
    console.error("Failed to query user info:", err);
  }
})();

It outputs the user details that is used to connect to the database. It has
current_user: 'postgres', rolname: 'postgres', rolbypassrls: true
current_user: 'postgres', rolname: 'postgres', rolbypassrls: true
. How can i connect using some other user that respects RLS policies?
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Connecting with connection string
SupabaseSSupabase / help-and-questions
4y ago
rls is bypassed when connecting to supabase using the connection string with postgres library
SupabaseSSupabase / help-and-questions
8mo ago
ORM RLS Support
SupabaseSSupabase / help-and-questions
4y ago
Connection string clarity when using Prisma
SupabaseSSupabase / help-and-questions
7mo ago