In our application, we check at startup,
if a postgresql table exists if it doesn't, we create it, and then enable row level security
If it does exist, we still aren't certain if row level security is true or not
So, we always need to check if row level security is enabled, and if not, we need to enable it.
Now there are two ways of doing about this (there could be more, but these are the two ways we could think of):
ALTER TABLE <tname> enable row level security;
Or, we can do
SELECT rowsecurity FROM pg_tables WHERE tablename = <tname>and only if that returns
false, run the
ALTER TABLEfrom (1).
The question we have is, is option (2) more performant than option (1) or is it just making things more complicated without improving the performance for subsequent startups?
This check will happen upon every application startup.