influitive / apartment

Database multi-tenancy for Rack (and Rails) applications
2.66k stars 464 forks source link

How to configure use_schema_cache_dump with apartment gem? #683

Closed rohangrg closed 1 month ago

rohangrg commented 1 month ago

We are using apartment gem, and recently we changed our passenger config to restart a process whenever it hits request count of 400.

SELECT a.attname
FROM (  SELECT indrelid, indkey, generate_subscripts(  indkey, $1) idx
    FROM pg_index
    WHERE indrelid  = $2::regclass
AND  indisprimary  ) i  JOIN  pg_attribute a  ON a.attrelid  = i.indrelid  AND a.attnum =  i.indkey[i.idx]  ORDER BY i.idx

Due to which, the above query is getting called multiple times, which is called whenever the process is started/restarted.

I read some post online Issue URL and found out that this can be avoided if enabled use_schema_cache_dump in my rails application. Solution they suggested Solution

But will it work with apartment gem? Since each tenant can have different schema.