Re: Does creating readOnly connections, when possible, free up resources in Postgres?

From: Hannes Erven <hannes(at)erven(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Does creating readOnly connections, when possible, free up resources in Postgres?
Date: 2019-01-27 23:21:41
Message-ID: bdf01231-9a5f-1762-1848-b6a7adb4a435@erven.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi David,

> I saw that when you create a JDBC connection, you can specify
> readOnly=true. Would doing so somehow help Postgres manage its other
> connections?

if you know that a certain connection will be ready-only, you could use
a more aggressive pooling strategy.

Usually, a connection pool will return a worker thread to the pool when
the client closes the connection.
pgbouncer for example offers a "statement" pooling strategy, meaning
that a worker connection is returned to the pool after every completed
SQL statement.
That way, a single Postgresql server thread can easily serve many client
connections.
If a specific usecase fits into a single command, you can even use it
for these writes!

Of course, you can't use server-side prepared statements, temporary
tables, ... or anything else that depends on subsequent statements
hitting the same server process.

For an application I'm running, we have dozens of GUI clients keeping a
JDBC connection open all day checking for updates, and with statement
pooling this is handled well by 1-3 server processes (auto-scaled by
pgbouncer).

Best regards,

-hannes

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chuck Martin 2019-01-27 23:50:05 Re: Query help
Previous Message Begin Daniel 2019-01-27 22:45:24 RE: Error message restarting a database