[postgis-users] query tuning

Paragon Corporation lr at pcorp.us
Thu Jul 31 13:46:50 PDT 2008

It would probably help if you clustered on the gist index.
ALTER TABLE users CLUSTER ON users_locbbox;
CLUSTER users;
Also what kind of processors and on board ram do you have?
Hope that helps,


From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of marc2112
Sent: Thursday, July 31, 2008 3:31 PM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] query tuning

Hi Folks,

I've got a slow running query.  When I break it down to just the spatial
constraint on one table, I find that the query takes 8s.  I need my broader
query to take < 1s so have a long way to go on just the spatial part.
Hopefully you guys will have some ideas for me...

Here's what I've got:

SELECT u.username,u.locbbox, y(u.locpoint) AS latitude, x(u.locpoint) AS
FROM users u
WHERE u.locbbox && SetSrid( 'BOX(-73.795166015625
9.42738628387451,-69.49951171875 11.813588142395)'::box2d, 4326 ) 

Explain Analyze:
"Bitmap Heap Scan on users u  (cost=741.34..43666.77 rows=15789 width=486)
(actual time=29.730..7321.358 rows=10687 loops=1)"
"  Filter: (locbbox &&
"  ->  Bitmap Index Scan on users_locbbox  (cost=0.00..737.39 rows=15789
width=0) (actual time=26.981..26.981 rows=10703 loops=1)"
"        Index Cond: (locbbox &&
"Total runtime: 7328.359 ms"

CREATE INDEX users_locbbox
  ON users
  USING gist

Some Stats (let me know what else would be helpful):
Rows in users table: 1.85mm
Table Size: ~4GB
users_locbbox index size: 190MB

Tuning done:
shared_buffers = 100MB
work_mem = 100MB
max_fsm_pages = 153600
random_page_cost = 3.0
cpu_tuple_cost = 0.1
effective_cache_size = 8GB
default_statistics_target = 100

Tables in the query are vacuum/analyzed daily.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080731/8d1aab88/attachment.html>

More information about the postgis-users mailing list