pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Vadim Nevorotin <nevorotin@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: First query on each connection is too slow
Date: Wed, 13 Jun 2018 10:49:39 -0400
Message-ID: <29035.1528901379@sss.pgh.pa.us> (raw)
In-Reply-To: <20180613144054.v7bi6dwnq5wywgpd@alap3.anarazel.de>
References: <CAF=tNg_eEVo79iAYrs_MqLQc_qWnOv8dtf_Vz+_0o=icKfkntw@mail.gmail.com>
	<20180613144054.v7bi6dwnq5wywgpd@alap3.anarazel.de>

Andres Freund <andres@anarazel.de> writes:
> On 2018-06-13 12:55:27 +0300, Vadim Nevorotin wrote:
>> I have a very strange problem. I'm using PostgreSQL 9.6 with PostGIS 2.3
>> (both from Debian Strecth repos) to store DB for OSM server (but actually
>> it doesn't matter). And I've noticed, that on each new connection to DB
>> first query is much slower (10x) than all others. E.g.:
>> test_gis=# SELECT srid FROM geometry_columns WHERE
>> f_table_name='planet_osm_polygon' AND f_geometry_column='way';

> What you're seeing is likely a mix of
> a) Operating system overhead of doing copy-on-write the first time
>    memory is touched. This can be reduced to some degree by configuring
>    huge pages.
> b) Postgres' caches over catalog contents (i.e. how your tables look
>    like) having to be filled on the first access.  There's not really
>    much you can do about it.

Seeing that this query seems to involve PostGIS, I suspect that there
might be a third cause: time to load the PostGIS shared library.
If so, you could probably alleviate the issue by adding postgis
to shared_preload_libraries.

If that doesn't fix it, (b) could perhaps be alleviated by adopting
connection pooling, though that has costs of its own.

			regards, tom lane




view thread (11+ messages)  latest in thread

Message-ID: <29035.1528901379@sss.pgh.pa.us>
Permalink:  ../29035.1528901379@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29035.1528901379@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, nevorotin@gmail.com
  Subject: Re: First query on each connection is too slow
  In-Reply-To: <29035.1528901379@sss.pgh.pa.us>
  References: <CAF=tNg_eEVo79iAYrs_MqLQc_qWnOv8dtf_Vz+_0o=icKfkntw@mail.gmail.com> <20180613144054.v7bi6dwnq5wywgpd@alap3.anarazel.de> <29035.1528901379@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox