finding a max value

Lists: pgsql-adminpgsql-bugspgsql-performance
From: "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1186: Broken Index?
Date: 2004-07-02 07:50:07
Message-ID: 20040702075007.B448FCF4D52@www.postgresql.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-bugs pgsql-performance


The following bug has been logged online:

Bug reference: 1186
Logged by: Gosen, Hitoshi

Email address: mic-gosen(at)ns(dot)inter-mic(dot)co(dot)jp

PostgreSQL version: 7.4

Operating system: linux 2.4.18

Description: Broken Index?

Details:

Hello All,
We are using PostgreSQL 7.4.2 for our website that handles over 200,000
transactions a day.
About a month ago, the responses from the SELECT queries on the database
became terribly slow.
We tried to anaylze the cause of the problem, searching throught the system
logs and all, but nothing appeared to be out of the ordinary.

What we did to resolve this was to dump the database, delete the database,
recreate the database, and finally restore it. After that, things were back
to normal.

From the above experience, we were able to hypothesize that the fault of the
slow responses was not from a broken data or hardware failures, but from a
broken index, since we were able to recover 100% of the data on the same
machine.

Today, the same problem occured, and the same actions are going to be taken
to temporary resolve it.

Final note: we will also experiment with the 'vacuum full' command to see
if it counters this problem.


From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: "Gosen, Hitoshi" <mic-gosen(at)ns(dot)inter-mic(dot)co(dot)jp>
Cc: pgsql-bugs(at)postgresql(dot)org, pgsql-performance(at)postgresql(dot)org
Subject: Re: BUG #1186: Broken Index?
Date: 2004-07-02 13:12:58
Message-ID: 20040702131258.GB25007@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-bugs pgsql-performance

On Fri, Jul 02, 2004 at 04:50:07 -0300,
PostgreSQL Bugs List <pgsql-bugs(at)postgresql(dot)org> wrote:
>
> The following bug has been logged online:

This doesn't appear to be a bug at this point. It sounds like you have
a self induced performance problem, so I am moving the discussion to
pgsql-performance.

>
> Bug reference: 1186
> Logged by: Gosen, Hitoshi
>
> Email address: mic-gosen(at)ns(dot)inter-mic(dot)co(dot)jp
>
> PostgreSQL version: 7.4
>
> Operating system: linux 2.4.18
>
> Description: Broken Index?
>
> Details:
>
> Hello All,
> We are using PostgreSQL 7.4.2 for our website that handles over 200,000
> transactions a day.
> About a month ago, the responses from the SELECT queries on the database
> became terribly slow.
> We tried to anaylze the cause of the problem, searching throught the system
> logs and all, but nothing appeared to be out of the ordinary.
>
> What we did to resolve this was to dump the database, delete the database,
> recreate the database, and finally restore it. After that, things were back
> to normal.
>
> From the above experience, we were able to hypothesize that the fault of the
> slow responses was not from a broken data or hardware failures, but from a
> broken index, since we were able to recover 100% of the data on the same
> machine.
>
> Today, the same problem occured, and the same actions are going to be taken
> to temporary resolve it.
>
> Final note: we will also experiment with the 'vacuum full' command to see
> if it counters this problem.

It sounds like you aren't properly vacuuming your database. It is possible
that you need a higher FSM setting or to vacuum more frequently.


From: Edoardo Ceccarelli <eddy(at)expot(dot)it>
To: pgsql-performance(at)postgresql(dot)org
Cc: pgsql-admin(at)postgresql(dot)org
Subject: finding a max value
Date: 2004-07-02 18:50:26
Message-ID: 40E5AE72.1080206@expot.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-bugs pgsql-performance

This is the query:
select max(KA) from annuncio

field KA is indexed and is int4,

explaining gives:
explain select max(KA) from annuncio;
QUERY PLAN
-----------------------------------------------------------------------
Aggregate (cost=21173.70..21173.70 rows=1 width=4)
-> Seq Scan on annuncio (cost=0.00..20326.76 rows=338776 width=4)
(2 rows)

wasn't supposed to do an index scan? it takes about 1sec to get the result.


From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1186: Broken Index?
Date: 2004-07-03 14:51:50
Message-ID: cc6h6h$fnu$1@floppy.pyrenet.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-bugs pgsql-performance

PostgreSQL Bugs List wrote:
> Hello All,
> We are using PostgreSQL 7.4.2 for our website that handles over 200,000
> transactions a day.
> About a month ago, the responses from the SELECT queries on the database
> became terribly slow.
> We tried to anaylze the cause of the problem, searching throught the system
> logs and all, but nothing appeared to be out of the ordinary.
>
> What we did to resolve this was to dump the database, delete the database,
> recreate the database, and finally restore it. After that, things were back
> to normal.
>
> From the above experience, we were able to hypothesize that the fault of the
> slow responses was not from a broken data or hardware failures, but from a
> broken index, since we were able to recover 100% of the data on the same
> machine.
>
> Today, the same problem occured, and the same actions are going to be taken
> to temporary resolve it.
>
> Final note: we will also experiment with the 'vacuum full' command to see
> if it counters this problem.

This is not for sure a bug, but a known behaviour if you don't vacuum at all
your db. I bet you don't use the vacuum daemon; use it or schedule a simple
vacuum on the eavily updated table each 10 minutes. I strongly suggest you to use
the autovacuum daemon.

Do not esitate to ask how use it.

Regards
Gaetano Mendola


From: James Antill <james(at)and(dot)org>
To: Edoardo Ceccarelli <eddy(at)expot(dot)it>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: finding a max value
Date: 2004-07-07 19:29:58
Message-ID: m37jtf62fd.fsf@code.and.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-bugs pgsql-performance

Edoardo Ceccarelli <eddy(at)expot(dot)it> writes:

> This is the query:
> select max(KA) from annuncio
>
> field KA is indexed and is int4,
>
> explaining gives:
> explain select max(KA) from annuncio;
> QUERY PLAN
> -----------------------------------------------------------------------
> Aggregate (cost=21173.70..21173.70 rows=1 width=4)
> -> Seq Scan on annuncio (cost=0.00..20326.76 rows=338776 width=4)
> (2 rows)
>
>
> wasn't supposed to do an index scan? it takes about 1sec to get the result.

This is a known misfeature of max() in postgresql, see...

http://archives.postgresql.org/pgsql-performance/2003-12/msg00283.php

--
# James Antill -- james(at)and(dot)org
:0:
* ^From: (dot)*james(at)and\(dot)org
/dev/null


From: Rosser Schwarz <rosser(dot)schwarz(at)gmail(dot)com>
To: Edoardo Ceccarelli <eddy(at)expot(dot)it>
Cc: pgsql-performance(at)postgresql(dot)org, pgsql-admin(at)postgresql(dot)org
Subject: Re: [PERFORM] finding a max value
Date: 2004-07-07 20:27:19
Message-ID: 37d451f704070713271da13629@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin pgsql-bugs pgsql-performance

On Fri, 02 Jul 2004 20:50:26 +0200, Edoardo Ceccarelli <eddy(at)expot(dot)it> wrote:

> This is the query:
> select max(KA) from annuncio

> wasn't supposed to do an index scan? it takes about 1sec to get the result.

> TIP 5: Have you checked our extensive FAQ?

I believe this is a FAQ.

See: http://www.postgresql.org/docs/faqs/FAQ.html#4.8

Try "select KA from annuncio order by KA desc limit 1;"

/rls

--
:wq