RLS Error Logging

I am trying to figure out a good system for debugging my RLS rules. I am wondering if Supabase supports logging of errors. If I am correct with PGSQL you can use "RAISE" as a print statement. Does this get logged anywhere within Supabase? I am getting one of these: "more than one row returned by a subquery" and I just have no idea which rules or which part of a rule's query is throwing the error. Thanks in advance!
6 Replies
garyaustin
garyaustin8mo ago
You can normally use raise log in plpgsql functions and result is in the Postgres log. I believe you can do that if you RLS is in a function, but you can't just do it in a policy. Usually best to use the SQL editor and impersonation and test individual parts of the query.
Grantly
GrantlyOP8mo ago
In this case, I am most worried about functions, so if I just use "RAISE XYZ" it'll appear in the Postgres log? That is nice! If I run into non-function situations I'll impersonate with queries, that is a great idea.
garyaustin
garyaustin8mo ago
Raise log 'var = %',var;
Grantly
GrantlyOP8mo ago
Oof, now everytime I try and get the logs locally I get this error. I assume I should be able to access logs locally right? { "code": 500, "message": "An error has occurred: fetch failed", "requestId": "71f67dd4-d933-4e3d-8285-2d10889ab1f5" }
garyaustin
garyaustin8mo ago
There is a setting in config.toml to enable analytics.
Grantly
GrantlyOP8mo ago
Oh awesome! Thanks so much!

Did you find this page helpful?