Re: Memory Usage Question

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Chris Hoover <revoohc(at)gmail(dot)com>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Memory Usage Question
Date: 2006-01-09 20:35:58
Message-ID: 20060109203558.GO3902@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-performance

On Mon, Jan 09, 2006 at 01:54:48PM -0500, Chris Hoover wrote:
> Question, if I have a 4GB+ index for a table on a server with 4GB ram, and I
> submit a query that does an index scan, does Postgres read the entire index,
> or just read the index until it finds the matching value (our extra large
> indexes are primary keys).

Well, the idea behind an index is that if you need a specific value from
it, you can get there very quickly, reading a minimum of data along the
way. So basically, PostgreSQL won't normally read an entire index.

> I am looking for real number to give to my boss the say either having a
> primary key larger than our memory is bad (and how to clearly justfify it),
> or it is ok.
>
> If it is ok, what are the trade offs in performance?\
>
> Obviously, I want more memory, but I have to prove the need to my boss since
> it raises the cost of the servers a fair amount.

Well, if you add a sleep to the following code, you can tie up some
amount of memory, which would allow you to simulate having less memory
available. Though over time I think the kernel might decide to page that
memory out, so it's not perfect.

int main(int argc, char *argv[]) {
if (!calloc(atoi(argv[1]), 1024*1024)) { printf("Error allocating memory.\n"); }
}

In a nutshell, PostgreSQL and the OS will generally work together to
only cache data that is being used fairly often. In the case of a large
PK index, if you're not actually reading a large distribution of the
values in the index you probably aren't even caching the entire index
even now. There may be some kind of linux tool that would show you what
portion of a file is currently cached, which would help answer that
question (but remember that hopefully whatever parts of the index are
cached by PostgreSQL itself won't also be cached by the OS as well).
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jim C. Nasby 2006-01-09 22:20:37 Re: windows install not as a service
Previous Message Jim C. Nasby 2006-01-09 20:26:26 Re: preventing deadlocks

Browse pgsql-performance by date

  From Date Subject
Next Message peter royal 2006-01-09 20:59:39 Re: help tuning queries on large database
Previous Message Luke Lonergan 2006-01-09 19:01:43 Re: help tuning queries on large database