[PERFORM] database bloat, but vacuums are done, and fsm seems to be setup ok

2005-09-28 Thread hubert depesz lubaczewski
hi
setup:
postgresql 8.0.3 put on debian on dual xeon, 8GB ram, hardware raid.

database just after recreation from dump takes 15gigabytes.
after some time (up to 3 weeks) it gets really slow and has to be dump'ed and restored.

as for fsm:
end of vacuum info:
INFO: free space map: 248 relations, 1359140 pages stored; 1361856 total pages needed
DETAIL: Allocated FSM size: 1000 relations + 1000 pages = 58659 kB shared memory.

so it looks i have plenty of space in fsm.

vacuums run constantly.
4 different tasks, 3 of them doing:
while true
vacuum table
sleep 15m
done
with different tables (i have chooses the most updated tables in system).

and the fourth vacuum task does the same, but without specifying table - so it vacuumes whole database.

after last dump/restore cycle i noticed that doing reindex on all
indices in database made it drop in side from 40G to about 20G - so it
might be that i will be using reindex instead of drop/restore.
anyway - i'm not using any special indices - just some (117 to be
exact) indices of btree type. we use simple, multi-column, partial and
multi-column partial indices. we do not have functional indices.

database has quite huge load of updates, but i thought that vacum will
guard me from database bloat, but from what i observed it means that
vacuuming of b-tree indices is somewhat faulty.

any suggestions? what else can i supply you with to help you help me?

best regards

depesz


Re: [HACKERS] [PERFORM] A Better External Sort?

2005-09-28 Thread Ron Peacetree
From: Jeffrey W. Baker [EMAIL PROTECTED]
Sent: Sep 27, 2005 1:26 PM
To: Ron Peacetree [EMAIL PROTECTED]
Subject: Re: [HACKERS] [PERFORM] A Better External Sort?

On Tue, 2005-09-27 at 13:15 -0400, Ron Peacetree wrote:

That Btree can be used to generate a physical reordering of the data
in one pass, but that's the weakest use for it.  The more powerful
uses involve allowing the Btree to persist and using it for more
efficient re-searches or combining it with other such Btrees (either as
a step in task distribution across multiple CPUs or as a more efficient
way to do things like joins by manipulating these Btrees rather than
the actual records.)

Maybe you could describe some concrete use cases.  I can see what
you are getting at, and I can imagine some advantageous uses, but
I'd like to know what you are thinking.

1= In a 4P box, we split the data in RAM into 4 regions and create
a CPU cache friendly Btree using the method I described for each CPU.
The 4 Btrees can be merged in a more time and space efficient manner
than the original records to form a Btree that represents the sorted order
of the entire data set.  Any of these Btrees can be allowed to persist to
lower the cost of doing similar operations in the future (Updating the
Btrees during inserts and deletes is cheaper than updating the original
data files and then redoing the same sort from scratch in the future.)
Both the original sort and future such sorts are made more efficient
than current methods.

2= We use my method to sort two different tables.  We now have these
very efficient representations of a specific ordering on these tables.  A
join operation can now be done using these Btrees rather than the
original data tables that involves less overhead than many current
methods.

3=  We have multiple such Btrees for the same data set representing
sorts done using different fields (and therefore different Keys).
Calculating a sorted order for the data based on a composition of
those Keys is now cheaper than doing the sort based on the composite
Key from scratch.  When some of the Btrees exist and some of them
do not, there is a tradeoff calculation to be made.  Sometimes it will be
cheaper to do the sort from scratch using the composite Key.   


Specifically I'd like to see some cases where this would beat sequential
scan.  I'm thinking that in your example of a terabyte table with a
column having only two values, all the queries I can think of would be
better served with a sequential scan.

In my original example, a sequential scan of the 1TB of 2KB or 4KB
records, = 250M or 500M records of data, being sorted on a binary
value key will take ~1000x more time than reading in the ~1GB Btree
I described that used a Key+RID (plus node pointers) representation
of the data.
 
Just to clarify the point further,
1TB of 1B records = 2^40 records of at most 256 distinct values.
1TB of 2B records = 2^39 records of at most 2^16 distinct values.
1TB of 4B records = 2^38 records of at most 2^32 distinct values.
1TB of 5B records = 200B records of at most 200B distinct values.
From here on, the number of possible distinct values is limited by the
number of records.
100B records are used in the Indy version of Jim Gray's sorting 
contests, so 1TB = 10B records.
2KB-4KB is the most common record size I've seen in enterprise
class DBMS (so I used this value to make my initial example more
realistic).

Therefore the vast majority of the time representing a data set by Key
will use less space that the original record.  Less space used means
less IO to scan the data set, which means faster scan times.

This is why index files work in the first place, right?


Perhaps I believe this because you can now buy as much sequential I/O
as you want.  Random I/O is the only real savings.

1= No, you can not buy as much sequential IO as you want.  Even if
with an infinite budget, there are physical and engineering limits.  Long
before you reach those limits, you will pay exponentially increasing costs
for linearly increasing performance gains.  So even if you _can_ buy a
certain level of sequential IO, it may not be the most efficient way to
spend money.

2= Most RW IT professionals have far from an infinite budget.  Just traffic
on these lists shows how severe the typical cost constraints usually are.
OTOH, if you have an inifinite IT budget, care to help a few less fortunate
than yourself?  After all, a even a large constant substracted from infinity
is still infinity... ;-)

3= No matter how fast you can do IO, IO remains the most expensive
part of the performance equation.  The fastest and cheapest IO you can
do is _no_ IO.  As long as we trade cheaper RAM and even cheaoer CPU
operations for IO correctly, more space efficient data representations will
always be a Win because of this.

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining 

Re: [PERFORM] Monitoring Postgresql performance

2005-09-28 Thread Dan Harris


On Sep 28, 2005, at 8:32 AM, Arnau wrote:


Hi all,

  I have been googling a bit searching info about a way to  
monitor postgresql (CPU  Memory, num processes, ... )


You didn't mention your platform, but I have an xterm open pretty  
much continuously for my DB server that runs plain old top.  I have  
customized my settings enough that I can pretty much see anything I  
need to from there.


-Dan


---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


Re: [PERFORM] Monitoring Postgresql performance

2005-09-28 Thread Alex Stapleton


On 28 Sep 2005, at 15:32, Arnau wrote:



Hi all,

  I have been googling a bit searching info about a way to  
monitor postgresql (CPU  Memory, num processes, ... ) and I  
haven't found anything relevant. I'm using munin to monitor others  
parameters of my servers and I'd like to include postgresql or have  
a similar tool. Any of you is using anything like that? all kind of  
hints are welcome :-)


Cheers!



Have you looked at SNMP? It's a bit complex but there's lots of tools  
for monitoring system data / sending alerts based on SNMP already.



---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [PERFORM] Slow concurrent update of same row in a given table

2005-09-28 Thread Gavin Sherry
On Wed, 28 Sep 2005, Rajesh Kumar Mallah wrote:

   Number of Copies | Update perl Sec
  
   1  -- 119
   2  --- 59
   3  ---  38
   4  --- 28
   5 -- 22
   6 -- 19
   7 -- 16
   8 -- 14
   9 -- 11
   10 -- 11
   11 -- 10
 
  So, 11 instances result in 10 updated rows per second, database wide or
  per instance? If it is per instance, then 11 * 10 is close to the
  performance for one connection.


 Sorry do not understand the difference between database wide
 and per instance

Per instance.


 
  That being said, when you've got 10 connections fighting over one row, I
  wouldn't be surprised if you had bad performance.
 
  Also, at 119 updates a second, you're more than doubling the table's
  initial size (dead tuples) each second. How often are you vacuuming and
  are you using vacuum or vacuum full?


 Yes I realize the obvious phenomenon now, (and the uselessness of the script)
  , we should not consider it a performance degradation.

 I am having performance issue in my live database thats why i tried to
 simulate the situation(may the the script was overstresser).

 My original problem is  that i send 100 000s of emails carrying a
 beacon for tracking readership every tuesday and on wednesday i see
 lot of the said query in pg_stat_activity each of these query update
 the SAME row that corresponds to the dispatch of last day and it is
 then i face the performance problem.

 I think i can only post further details next wednesday , please lemme
 know how should i be dealing with the situation if each the updates takes
 100times more time that normal update duration.

I see. These problems regularly come up in database design. The best thing
you can do is modify your database design/application such that instead of
incrementing a count in a single row, you insert a row into a table,
recording the 'dispatch_id'. Counting the number of rows for a given
dispatch id will give you your count.

Thanks,

Gavin

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [PERFORM] Logarithmic change (decrease) in performance

2005-09-28 Thread Ron Peacetree
From: Matthew Nuzum [EMAIL PROTECTED]
Sent: Sep 28, 2005 4:02 PM
Subject: [PERFORM] Logarithmic change (decrease) in performance

Small nit-pick:  A logarithmic decrease in performance would be
a relatively good thing, being better than either a linear or
exponential decrease in performance.  What you are describing is
the worst kind: an _exponential_ decrease in performance.

Something interesting is going on. I wish I could show you the graphs,
but I'm sure this will not be a surprise to the seasoned veterans.

A particular application server I have has been running for over a
year now. I've been logging cpu load since mid-april.

It took 8 months or more to fall from excellent performance to
acceptable. Then, over the course of about 5 weeks it fell from
acceptable to so-so. Then, in the last four weeks it's gone from
so-so to alarming.

I've been working on this performance drop since Friday but it wasn't
until I replied to Arnau's post earlier today that I remembered I'd
been logging the server load. I grabbed the data and charted it in
Excel and to my surprise, the graph of the server's load average looks
kind of like the graph of y=x^2.

I've got to make a recomendation for a solution to the PHB and my
analysis is showing that as the dataset becomes larger, the amount of
time the disk spends seeking is increasing. This causes processes to
take longer to finish, which causes more processes to pile up, which
causes processes to take longer to finish, which causes more processes
to pile up etc. It is this growing dataset that seems to be the source
of the sharp decrease in performance.

I knew this day would come, but I'm actually quite surprised that when
it came, there was little time between the warning and the grande
finale. I guess this message is being sent to the list to serve as a
warning to other data warehouse admins that when you reach your
capacity, the downward spiral happens rather quickly.

Yep, definitely been where you are.  Bottom line: you have to reduce
the sequential seeking behavior of the system to within an acceptable
window and then keep it there.

1= keep more of the data set in RAM
2= increase the size of your HD IO buffers
3= make your RAID sets wider (more parallel vs sequential IO)
4= reduce the atomic latency of your RAID sets
(time for Fibre Channel 15Krpm HD's vs 7.2Krpm SATA ones?)
5= make sure your data is as unfragmented as possible
6= change you DB schema to minimize the problem
a= overall good schema design
b= partitioning the data so that the system only has to manipulate a
reasonable chunk of it at a time.

In many cases, there's a number of ways to accomplish the above.
Unfortunately, most of them require CapEx.

Also, ITRW world such systems tend to have this as a chronic
problem.  This is not a fix it once and it goes away forever.  This
is a part of the regular maintenance and upgrade plan(s). 

Good Luck,
Ron 

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [HACKERS] [PERFORM] A Better External Sort?

2005-09-28 Thread Ron Peacetree
In the interest of efficiency and not reinventing the wheel, does anyone know
where I can find C or C++ source code for a Btree variant with the following
properties:

A= Data elements (RIDs) are only stored in the leaves, Keys (actually
KeyPrefixes; see D below) and Node pointers are only stored in the internal
nodes of the Btree.

B= Element redistribution is done as an alternative to node splitting in 
overflow
conditions during Inserts whenever possible.

C= Variable length Keys are supported.

D= Node buffering with a reasonable replacement policy is supported.

E= Since we will know beforehand exactly how many RID's will be stored, we
will know apriori how much space will be needed for leaves, and will know the
worst case for how much space will be required for the Btree internal nodes
as well.  This implies that we may be able to use an array, rather than linked
list, implementation of the Btree.  Less pointer chasing at the expense of more
CPU calculations, but that's a trade-off in the correct direction. 

Such source would be a big help in getting a prototype together.

Thanks in advance for any pointers or source,
Ron

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [PERFORM] Slow concurrent update of same row in a given table

2005-09-28 Thread Gavin Sherry
On Thu, 29 Sep 2005, Rajesh Kumar Mallah wrote:

 On 9/29/05, Gavin Sherry [EMAIL PROTECTED] wrote:
  On Wed, 28 Sep 2005, Rajesh Kumar Mallah wrote:
 
 Number of Copies | Update perl Sec

 1  -- 119
 2  --- 59
 3  ---  38
 4  --- 28
 5 -- 22
 6 -- 19
 7 -- 16
 8 -- 14
 9 -- 11
 10 -- 11
 11 -- 10
   
So, 11 instances result in 10 updated rows per second, database wide or
per instance? If it is per instance, then 11 * 10 is close to the
performance for one connection.
  
  
   Sorry do not understand the difference between database wide
   and per instance
 
  Per instance.
 
  
   
That being said, when you've got 10 connections fighting over one row, I
wouldn't be surprised if you had bad performance.
   
Also, at 119 updates a second, you're more than doubling the table's
initial size (dead tuples) each second. How often are you vacuuming and
are you using vacuum or vacuum full?
  
  
   Yes I realize the obvious phenomenon now, (and the uselessness of the 
   script)
, we should not consider it a performance degradation.
  
   I am having performance issue in my live database thats why i tried to
   simulate the situation(may the the script was overstresser).
  
   My original problem is  that i send 100 000s of emails carrying a
   beacon for tracking readership every tuesday and on wednesday i see
   lot of the said query in pg_stat_activity each of these query update
   the SAME row that corresponds to the dispatch of last day and it is
   then i face the performance problem.
  
   I think i can only post further details next wednesday , please lemme
   know how should i be dealing with the situation if each the updates takes
   100times more time that normal update duration.
 
  I see. These problems regularly come up in database design. The best thing
  you can do is modify your database design/application such that instead of
  incrementing a count in a single row, you insert a row into a table,
  recording the 'dispatch_id'. Counting the number of rows for a given
  dispatch id will give you your count.
 

 sorry i will be accumulating huge amount of rows in seperate table
 with no extra info when i really want just the count. Do you have
 a better database design in mind?

 Also i encounter same problem in implementing read count of
 articles in sites and in counting banner impressions where same
 row get updated by multiple processes frequently.

As I said in private email, accumulating large numbers of rows is not a
problem. In your current application, you are write bound, not read bound.
I've designed many similar systems which have hundred of millions of rows.
It takes a while to generate the count, but you just do it periodically in
non-busy periods.

With 8.1, constraint exclusion will give you significantly better
performance with this system, as well.

Thanks,

Gavin

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


[PERFORM] Comparative performance

2005-09-28 Thread Joe
I'm converting a relatively small database (2 MB) from MySQL to PostgreSQL.  It 
is used to generate web pages using PHP.  Although the actual website runs under 
Linux, the development is done under XP.  I've completed most of the data 
conversion and rewrite of the PHP scripts, so now I'm comparing relative 
performance.


It appears that PostgreSQL is two to three times slower than MySQL.  For 
example, some pages that have some 30,000 characters (when saved as HTML) take 1 
to 1 1/2 seconds with MySQL but 3 to 4 seconds with PostgreSQL.  I had read that 
the former was generally faster than the latter, particularly for simple web 
applications but I was hoping that Postgres' performance would not be that 
noticeably slower.


I'm trying to determine if the difference can be attributed to anything that 
I've done or missed.  I've run VACUUM ANALYZE on the two main tables and I'm 
looking at the results of EXPLAIN on the query that drives the retrieval of 
probably 80% of the data for the pages in question.


Before I post the EXPLAIN and the table schema I'd appreciate confirmation that 
this list is the appropriate forum.  I'm a relative newcomer to PostgreSQL (but 
not to relational databases), so I'm not sure if this belongs in the novice or 
general lists.


Joe


---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match


Re: [PERFORM] Comparative performance

2005-09-28 Thread Gavin Sherry
On Wed, 28 Sep 2005, Joe wrote:

 I'm converting a relatively small database (2 MB) from MySQL to PostgreSQL.  
 It
 is used to generate web pages using PHP.  Although the actual website runs 
 under
 Linux, the development is done under XP.  I've completed most of the data
 conversion and rewrite of the PHP scripts, so now I'm comparing relative
 performance.

 It appears that PostgreSQL is two to three times slower than MySQL.  For
 example, some pages that have some 30,000 characters (when saved as HTML) 
 take 1
 to 1 1/2 seconds with MySQL but 3 to 4 seconds with PostgreSQL.  I had read 
 that
 the former was generally faster than the latter, particularly for simple web
 applications but I was hoping that Postgres' performance would not be that
 noticeably slower.

Are you comparing PostgreSQL on XP to MySQL on XP or PostgreSQL on Linux
to MySQL on Linux? Our performance on XP is not great. Also, which version
of PostgreSQL are you using?


 I'm trying to determine if the difference can be attributed to anything that
 I've done or missed.  I've run VACUUM ANALYZE on the two main tables and I'm
 looking at the results of EXPLAIN on the query that drives the retrieval of
 probably 80% of the data for the pages in question.

Good.


 Before I post the EXPLAIN and the table schema I'd appreciate confirmation 
 that
 this list is the appropriate forum.  I'm a relative newcomer to PostgreSQL 
 (but
 not to relational databases), so I'm not sure if this belongs in the novice or
 general lists.

You can post the results of EXPLAIN ANALYZE here. Please including schema
definitions and the query string(s) themselves.

Thanks,

Gavin

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [PERFORM] Comparative performance

2005-09-28 Thread Dennis Bjorklund
On Wed, 28 Sep 2005, Joe wrote:

 Before I post the EXPLAIN and the table schema I'd appreciate
 confirmation that this list is the appropriate forum. 

It is and and useful things to show are

 * the slow query
 * EXPLAIN ANALYZE of the query
 * the output of \d for each table involved in the query
 * the output of SHOW ALL;
 * The amount of memory the machine have

The settings that are the most important to tune in postgresql.conf for
performance is in my opinion; shared_buffers, effective_cache_size and
(to a lesser extent) work_mem.

-- 
/Dennis Björklund


---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org