-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slow PostgREST startup with many tables #3733
Comments
That makes it possible to create a simple reproducer: I put this into the test fixtures to create 100k dummy tables: SELECT format($$
CREATE TABLE many_tables_%s (
id int,
a text
);
$$, generate_series(1,100000)) \gexec Then I ran
Result 1: 100k tables with two columns each take me 1,2s to query and about 4 seconds to load overall. Ok, I guess I need more columns then? After adding 51 more text columns, so a total of 53 columns:
Result 2: 100k tables with 53 columns take 12s to query and 1:04 minutes to load overall. Comparing that to your output, the first time the schema cache loaded it took:
That's 5 seconds to query and a whopping 7+ minutes to load overall. So clearly, I need something else in my schema than just columns. Cutting the columns to half and adding a single primary key:
Result 3: 100k tables with 27 columns and a PK take 7 seconds to query and 36 seconds to load overall. There must be something else about those tables in the OP that I can't see immediately. |
The numbers in the OP and my first experiments show that the query itself is fast. It's the Haskell side that's slow.
Are you sure there are no foreign keys on any of those tables, maybe pointing at some other hidden tables, so that they don't show up as relationships? Are there any views in this schema or are all those exposed endpoints coming from tables? How much stuff is in the schema mentioned in |
Hello ! We were actually migrating our Postgres to a server with more resources (with an SSD disk and more RAM). Since the server migration (and without having modified our PostgREST conf), we haven't encountered slow startup. See the latest logs:
|
Environment
Description of issue
We're creating this issue to keep it separated from #3704, but it is similar. Let us know if you would prefer for us to comment on it instead of this issue.
We have a database with a lot of tables (+60K) that keep on increasing. These tables are independent and added by users.
At deployment time, we have a downtime with the error
Could not query the database for the schema cache. Retrying.
for as long as the schema cache is not loaded.Startup logs (see also
Schema cache queried
showing twice):PostgREST also consumes a lot of RAM, probably due to loading the cache schema from what we've understood. To make sure we don't crash, we've requested 5G.
We have also increased some configs on Postgres side since it seemed to us that they were limiting schema cache loading:
Outside of the schema cache loading at startup, we don't experience any performance issue.
We would be interested on having your opinion on using PostgREST with this many tables and ways to mitigate the schema cache loading.
All the tables being independent, we actually don't need features such as Resource Embeddings.
The text was updated successfully, but these errors were encountered: