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

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: David Kremer <jkorders(at)gmx(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Does creating readOnly connections, when possible, free up resources in Postgres?
Date: 2019-01-28 09:08:52
Message-ID: 38d212fa217c622ed5abb9a3f11096a229d92393.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Kremer wrote:
> I have an API server and I'm trying to be conscientious managing Postgres's
> resources carefully. On the client side, I have a Hikari Pool.
>
> Usually when I need a connection, I simply create a default read/write connection,
> even if I don't plan to make any updates or inserts or hold any locks.
> But most of my database connections are in fact read-only.
>
> I saw that when you create a JDBC connection, you can specify readOnly=true.
> Would doing so somehow help Postgres manage its other connections? Perhaps Postgres,
> knowing that a connection is readOnly and will never even attempt to do an update,
> will free up some internal resources for other connections. Is this accurate?

It won't free any resources, but it is still a good idea if you use the SERIALIZABLE
isolation level.

https://www.postgresql.org/docs/current/transaction-iso.html#XACT-SERIALIZABLE:

For optimal performance when relying on Serializable transactions for concurrency
control, these issues should be considered:

- Declare transactions as READ ONLY when possible.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Josef Machytka 2019-01-28 09:23:19 error when creating logical replication slot
Previous Message Begin Daniel 2019-01-28 04:23:04 Re: Error message restarting a database