Re: problems with set_config, work_mem, maintenance_work_mem, and sorting

From: Kääriäinen Anssi <anssi(dot)kaariainen(at)thl(dot)fi>
To: Jon Nelson <jnelson+pgsql(at)jamponi(dot)net>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: problems with set_config, work_mem, maintenance_work_mem, and sorting
Date: 2012-02-28 21:48:52
Message-ID: BC19EF15D84DC143A22D6A8F2590F0A78A9846AA59@EXMAIL.stakes.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Quoting Jon Nelson:
"""
The config shows 128MB for work_mem and 2GB for maintenance_work_mem.
Why does PostgreSQL /sometimes/ use the globally-configured values and
sometimes use the values that come from the connection?
Am I wrong in misunderstanding what 'session' variables are? I thought
that session (versus transaction) config items were set for /all/
transactions in a given backend, until changed or until that backend
terminates. Is that not so?
"""

Could it be that the transaction which does the set_config is rolled back? If that is
the case, the set_config is rolled back, too. However, if the transaction commits,
then the set_config should be in effect for the whole session. It seems this is not
documented at all for set_config, just for SET SQL command.

I think it would be nice to have a way to force the connection to use the provided
settings even if the transaction in which they are done is rolled back. In single statement
if possible. Otherwise you might be forced to do a transaction just to be sure the SET
is actually in effect for the connection's life-time.

Django was bitten by this for example, it is now fixed by using this:
https://github.com/django/django/blob/master/django/db/backends/postgresql_psycopg2/base.py#L189

- Anssi

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2012-02-28 21:54:43 Re: problems with set_config, work_mem, maintenance_work_mem, and sorting
Previous Message Jon Nelson 2012-02-28 21:38:12 Re: problems with set_config, work_mem, maintenance_work_mem, and sorting