AppSheet with PostgresSQL and pgBouncer

We use a PostgresSQL database in Google Cloud as our data source.

During development, I noticed that AppSheet establishes an (abnormally) high number of connections to the database.

However, a maximum of 20 users work on the app at the same time.

I then added pgBouncer to counteract the problem with the large number of connections.

The problem now is that there are several sync errors every day with the message:

Error: Data table “xyz” is not accessible due to: Exception while reading from stream.

Most of the time, however, the syncs run smoothly.

Does anyone have any idea what the cause of this is? Or even better, a working configuration for pgBouncer?

Regards, Christoph

Adding additional tools to solve a most basic system function - connecting to a database - seems to add extra complexity and potential points of failure that don’t seem to be necessary.

I would first go back to the original problem.

Why is the number of connections a problem?
Why do you think the number was unusually high?

Keep in mind that AppSheet is a distributed system. EVERY user has its own FULL copy of the app and data. AppSheet’s servers may combine some of that functionality but since each user is performing functions at different times to different parts of the app, a set of connections will be basically by user.

If you haven’t already, you might investigate the usage of server caching in tables that do not change often to minimize the back an forth to the database.

2 Likes

I had issues similar to this a few years back when Supabase made a change to their connection pooler. There is a github issue from @SkrOYC.

Long story short, when AppSheet would sync it would open a connection for every table, and those connections would persist for several minutes. This quickly overwhelmed the available db connections.

You mention PgBouncer - this is what Supabase used to use, and I never had any issues with it. That said, if possible I would avoid using poolers for your appsheet <> postgres connection.

2 Likes

Thanks for the link to the GitHub Issue! I was not aware of it and will check it out.

I adjusted the max_connections on Postgres from 20 to 100. And I even reached this limit when I was developing the solution without any other users.

1 Like

Some insights.
Nowadays Supabase uses it’s Supavisor as pooler but when you are a paid customer you can use pgBouncer in your own instances.
That means that paying customers, which has also purchased the IPv4 addon must have no issues at all with AppSheet’s Postgres connection if configured properly

2 Likes