Re: [PATCHES] [HACKERS] pg_freespacemap question
Patch applied. Thanks. --- Mark Kirkwood wrote: > Mark Kirkwood wrote: > > Tom Lane wrote: > > > >> > >> I do notice a rather serious shortcoming of pg_freespacemap in its > >> current incarnation, which is that it *only* shows you the per-page free > >> space data, and not any of the information that would let you determine > >> what the FSM is doing to filter the raw data. The per-relation > >> avgRequest and lastPageCount fields would be interesting for instance. > >> Perhaps there should be a second view with one row per relation to > >> carry the appropriate data. > >> > > > > Ok - I did wonder about 2 views, but was unsure if the per-relation > > stuff was interesting. Given that it looks like it is interesting, I'll > > see about getting a second view going. > > > > This patch implements the second view for FSM relations. I have renamed > the functions and views to be: > > pg_freespacemap_relations > pg_freespacemap_pages > > This patch depends on the previous one (which was called simply > 'pg_freespacemap.patch'). > > Cheers > > Mark [ application/gzip is not supported, skipping... ] > > ---(end of broadcast)--- > TIP 4: Have you searched our list archives? > >http://archives.postgresql.org -- Bruce Momjian http://candle.pha.pa.us EnterpriseDBhttp://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [PATCHES] [HACKERS] pg_freespacemap question
Patch applied. Thanks. --- Mark Kirkwood wrote: > Tom Lane wrote: > > Mark Kirkwood <[EMAIL PROTECTED]> writes: > > > >>>Good points! I had not noticed this test case. Probably NULL is better > > > > > >>Would setting it to 'BLCKSZ - (fixed index header stuff)' be better, > > > > > > No, I don't think so, because that will just make it harder to recognize > > what's what (remember that BLCKSZ isn't really a constant, and the index > > overhead is not the same for all AMs either). The point here is that > > for indexes the FSM tracks whole-page availability, not the amount of > > free space within pages. So I think NULL is a reasonable representation > > of that. Using NULL will make it easy to filter the results if you want > > to see only heap-page data or only index-page data, whereas it will be > > very hard to do that if the view adopts an ultimately-artificial > > convention about the amount of available space on an index page. > > > > Right - after suggesting it I realized that coding the different index > overhead for each possible AM would have been ... difficult :-). A patch > is attached to implement the NULL free bytes and other recommendations: > > 1/ Index free bytes set to NULL > 2/ Comment added to the README briefly mentioning the index business > 3/ Columns reordered more logically > 4/ 'Blockid' column removed > 5/ Free bytes column renamed to just 'bytes' instead of 'blockfreebytes' > > Now 5/ was only hinted at, but seemed worth doing while I was there > (hopefully I haven't made it too terse now). > > cheers > > Mark > > > Index: pg_freespacemap.c > === > RCS file: /projects/cvsroot/pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v > retrieving revision 1.2 > diff -c -r1.2 pg_freespacemap.c > *** pg_freespacemap.c 14 Feb 2006 15:03:59 - 1.2 > --- pg_freespacemap.c 9 Mar 2006 03:38:10 - > *** > *** 12,18 > #include "storage/freespace.h" > #include "utils/relcache.h" > > ! #define NUM_FREESPACE_PAGES_ELEM6 > > #if defined(WIN32) || defined(__CYGWIN__) > /* Need DLLIMPORT for some things that are not so marked in main headers */ > --- 12,18 > #include "storage/freespace.h" > #include "utils/relcache.h" > > ! #define NUM_FREESPACE_PAGES_ELEM5 > > #if defined(WIN32) || defined(__CYGWIN__) > /* Need DLLIMPORT for some things that are not so marked in main headers */ > *** > *** 29,40 > typedef struct > { > > - uint32 blockid; > - uint32 relfilenode; > uint32 reltablespace; > uint32 reldatabase; > uint32 relblocknumber; > ! uint32 blockfreebytes; > > } FreeSpacePagesRec; > > --- 29,40 > typedef struct > { > > uint32 reltablespace; > uint32 reldatabase; > + uint32 relfilenode; > uint32 relblocknumber; > ! uint32 bytes; > ! boolisindex; > > } FreeSpacePagesRec; > > *** > *** 91,107 > > /* Construct a tuple to return. */ > tupledesc = CreateTemplateTupleDesc(NUM_FREESPACE_PAGES_ELEM, > false); > ! TupleDescInitEntry(tupledesc, (AttrNumber) 1, "blockid", > !INT4OID, -1, 0); > ! TupleDescInitEntry(tupledesc, (AttrNumber) 2, "relfilenode", > OIDOID, -1, 0); > ! TupleDescInitEntry(tupledesc, (AttrNumber) 3, "reltablespace", > OIDOID, -1, 0); > ! TupleDescInitEntry(tupledesc, (AttrNumber) 4, "reldatabase", > OIDOID, -1, 0); > ! TupleDescInitEntry(tupledesc, (AttrNumber) 5, "relblocknumber", > INT8OID, -1, 0); > ! TupleDescInitEntry(tupledesc, (AttrNumber) 6, "blockfreebytes", > INT4OID, -1, 0); > > /* Generate attribute metadata needed later to produce tuples */ > --- 91,105 > > /* Construct a tuple to return. */ > tupledesc = CreateTemplateTupleDesc(NUM_FREESPACE_PAGES_ELEM, > false); > ! TupleDescInitEntry(tupledesc, (AttrNumber) 1, "reltablespace", > OIDOID, -1, 0); > ! TupleDescInitEntry(tupledesc, (AttrNumber) 2, "reldatabase", > OIDOID, -1, 0);
Re: [PATCHES] [HACKERS] pg_freespacemap question
Mark Kirkwood wrote: Tom Lane wrote: I do notice a rather serious shortcoming of pg_freespacemap in its current incarnation, which is that it *only* shows you the per-page free space data, and not any of the information that would let you determine what the FSM is doing to filter the raw data. The per-relation avgRequest and lastPageCount fields would be interesting for instance. Perhaps there should be a second view with one row per relation to carry the appropriate data. Ok - I did wonder about 2 views, but was unsure if the per-relation stuff was interesting. Given that it looks like it is interesting, I'll see about getting a second view going. This patch implements the second view for FSM relations. I have renamed the functions and views to be: pg_freespacemap_relations pg_freespacemap_pages This patch depends on the previous one (which was called simply 'pg_freespacemap.patch'). Cheers Mark pg_freespacemap-1.patch.gz Description: application/gzip ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [PATCHES] [HACKERS] pg_freespacemap question
Mark Kirkwood wrote: > Christopher Kings-Lynne wrote: > >>The point here is that if tuples require 50 bytes, and there are 20 > >>bytes free on a page, pgstattuple counts 20 free bytes while FSM > >>ignores the page. Recording that space in the FSM will not improve > >>matters, it'll just risk pushing out FSM records for pages that do > >>have useful amounts of free space. > > > >Maybe an overloaded pgstattuple function that allows you to request FSM > >behavior? > > That's a nice idea - could also do equivalently by adding an extra > column "usable_free_space" or some such, and calculating this using FSM > logic. The current pgstattuple function scans the whole table, so I don't think this is a good idea. Re: the overloaded function, I think the behaviors are different enough to merit a separate function, with a different name. -- Alvaro Herrerahttp://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc. ---(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: [PATCHES] [HACKERS] pg_freespacemap question
Christopher Kings-Lynne wrote: The point here is that if tuples require 50 bytes, and there are 20 bytes free on a page, pgstattuple counts 20 free bytes while FSM ignores the page. Recording that space in the FSM will not improve matters, it'll just risk pushing out FSM records for pages that do have useful amounts of free space. Maybe an overloaded pgstattuple function that allows you to request FSM behavior? That's a nice idea - could also do equivalently by adding an extra column "usable_free_space" or some such, and calculating this using FSM logic. Cheers Mark ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [PATCHES] [HACKERS] pg_freespacemap question
The point here is that if tuples require 50 bytes, and there are 20 bytes free on a page, pgstattuple counts 20 free bytes while FSM ignores the page. Recording that space in the FSM will not improve matters, it'll just risk pushing out FSM records for pages that do have useful amounts of free space. Maybe an overloaded pgstattuple function that allows you to request FSM behavior? Chris ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [PATCHES] [HACKERS] pg_freespacemap question
Tatsuo Ishii <[EMAIL PROTECTED]> writes: > That sounds strange to me. Each record of accounts tables is actually > exactly same, i.e fixed size. So it should be possible that UPDATE > reuses any free spaces made by previous UPDATE. If FSM neglects those > free spaces "because they are uselessly small", then the unrecycled > pages are getting grow even if they are regulary VACUUMed, no? The point here is that if tuples require 50 bytes, and there are 20 bytes free on a page, pgstattuple counts 20 free bytes while FSM ignores the page. Recording that space in the FSM will not improve matters, it'll just risk pushing out FSM records for pages that do have useful amounts of free space. regards, tom lane ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster
Re: [PATCHES] [HACKERS] pg_freespacemap question
> > Tatsuo Ishii wrote: > >> BTW, I noticed difference of outputs from pg_freespacemap and > >> pgstattuple. > >> > >> I ran pgbench and inspected "accounts" table by using these tools. > >> > >> pg_freespacemap: > >> sum of bytes: 250712 > >> > >> pgstattuple: > >> free_space: 354880 > >> > >> Shouldn't they be identical? > > No, because (a) pgbench vacuums at the start of the run not the end, I ran VACUUM after pbench run and still got the differece. > and (b) vacuum/fsm disregard pages with "uselessly small" amounts of > free space (less than the average tuple size, IIRC). That sounds strange to me. Each record of accounts tables is actually exactly same, i.e fixed size. So it should be possible that UPDATE reuses any free spaces made by previous UPDATE. If FSM neglects those free spaces "because they are uselessly small", then the unrecycled pages are getting grow even if they are regulary VACUUMed, no? > I do notice a rather serious shortcoming of pg_freespacemap in its > current incarnation, which is that it *only* shows you the per-page free > space data, and not any of the information that would let you determine > what the FSM is doing to filter the raw data. The per-relation > avgRequest and lastPageCount fields would be interesting for instance. > Perhaps there should be a second view with one row per relation to > carry the appropriate data. -- Tatsuo Ishii SRA OSS, Inc. Japan ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [PATCHES] [HACKERS] pg_freespacemap question
Tom Lane wrote: Tatsuo Ishii wrote: BTW, I noticed difference of outputs from pg_freespacemap and pgstattuple. I ran pgbench and inspected "accounts" table by using these tools. pg_freespacemap: sum of bytes: 250712 pgstattuple: free_space: 354880 Shouldn't they be identical? vacuum/fsm disregard pages with "uselessly small" amounts of free space (less than the average tuple size, IIRC). Ah - that what I was seeing! Thanks. I do notice a rather serious shortcoming of pg_freespacemap in its current incarnation, which is that it *only* shows you the per-page free space data, and not any of the information that would let you determine what the FSM is doing to filter the raw data. The per-relation avgRequest and lastPageCount fields would be interesting for instance. Perhaps there should be a second view with one row per relation to carry the appropriate data. Ok - I did wonder about 2 views, but was unsure if the per-relation stuff was interesting. Given that it looks like it is interesting, I'll see about getting a second view going. Cheers Mark ---(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: [PATCHES] [HACKERS] pg_freespacemap question
> Tatsuo Ishii wrote: >> BTW, I noticed difference of outputs from pg_freespacemap and >> pgstattuple. >> >> I ran pgbench and inspected "accounts" table by using these tools. >> >> pg_freespacemap: >> sum of bytes: 250712 >> >> pgstattuple: >> free_space: 354880 >> >> Shouldn't they be identical? No, because (a) pgbench vacuums at the start of the run not the end, and (b) vacuum/fsm disregard pages with "uselessly small" amounts of free space (less than the average tuple size, IIRC). I do notice a rather serious shortcoming of pg_freespacemap in its current incarnation, which is that it *only* shows you the per-page free space data, and not any of the information that would let you determine what the FSM is doing to filter the raw data. The per-relation avgRequest and lastPageCount fields would be interesting for instance. Perhaps there should be a second view with one row per relation to carry the appropriate data. regards, tom lane ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster
Re: [PATCHES] [HACKERS] pg_freespacemap question
Tatsuo Ishii wrote: BTW, I noticed difference of outputs from pg_freespacemap and pgstattuple. I ran pgbench and inspected "accounts" table by using these tools. pg_freespacemap: sum of bytes: 250712 pgstattuple: free_space: 354880 Shouldn't they be identical? I would have thought so - unless there are not enough pages left in the FSM... pg_freespacemap is reporting on what gets into the FSM - so provided I haven't put a bug in there somewhere (!) - we need to look at how VACUUM reports free space to the FSM cheers Mark ---(end of broadcast)--- TIP 6: explain analyze is your friend
Re: [PATCHES] [HACKERS] pg_freespacemap question
BTW, I noticed difference of outputs from pg_freespacemap and pgstattuple. I ran pgbench and inspected "accounts" table by using these tools. pg_freespacemap: sum of bytes: 250712 pgstattuple: free_space: 354880 Shouldn't they be identical? -- Tatsuo Ishii SRA OSS, Inc. Japan ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings
Re: [PATCHES] [HACKERS] pg_freespacemap question
Mark, I have tried your patches and it worked great. Thanks. -- Tatsuo Ishii SRA OSS, Inc. Japan > Tom Lane wrote: > > Mark Kirkwood <[EMAIL PROTECTED]> writes: > > > >>>Good points! I had not noticed this test case. Probably NULL is better > > > > > >>Would setting it to 'BLCKSZ - (fixed index header stuff)' be better, > > > > > > No, I don't think so, because that will just make it harder to recognize > > what's what (remember that BLCKSZ isn't really a constant, and the index > > overhead is not the same for all AMs either). The point here is that > > for indexes the FSM tracks whole-page availability, not the amount of > > free space within pages. So I think NULL is a reasonable representation > > of that. Using NULL will make it easy to filter the results if you want > > to see only heap-page data or only index-page data, whereas it will be > > very hard to do that if the view adopts an ultimately-artificial > > convention about the amount of available space on an index page. > > > > Right - after suggesting it I realized that coding the different index > overhead for each possible AM would have been ... difficult :-). A patch > is attached to implement the NULL free bytes and other recommendations: > > 1/ Index free bytes set to NULL > 2/ Comment added to the README briefly mentioning the index business > 3/ Columns reordered more logically > 4/ 'Blockid' column removed > 5/ Free bytes column renamed to just 'bytes' instead of 'blockfreebytes' > > Now 5/ was only hinted at, but seemed worth doing while I was there > (hopefully I haven't made it too terse now). > > cheers > > Mark > ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings
Re: [PATCHES] [HACKERS] pg_freespacemap question
Tom Lane wrote: Mark Kirkwood <[EMAIL PROTECTED]> writes: Good points! I had not noticed this test case. Probably NULL is better Would setting it to 'BLCKSZ - (fixed index header stuff)' be better, No, I don't think so, because that will just make it harder to recognize what's what (remember that BLCKSZ isn't really a constant, and the index overhead is not the same for all AMs either). The point here is that for indexes the FSM tracks whole-page availability, not the amount of free space within pages. So I think NULL is a reasonable representation of that. Using NULL will make it easy to filter the results if you want to see only heap-page data or only index-page data, whereas it will be very hard to do that if the view adopts an ultimately-artificial convention about the amount of available space on an index page. Right - after suggesting it I realized that coding the different index overhead for each possible AM would have been ... difficult :-). A patch is attached to implement the NULL free bytes and other recommendations: 1/ Index free bytes set to NULL 2/ Comment added to the README briefly mentioning the index business 3/ Columns reordered more logically 4/ 'Blockid' column removed 5/ Free bytes column renamed to just 'bytes' instead of 'blockfreebytes' Now 5/ was only hinted at, but seemed worth doing while I was there (hopefully I haven't made it too terse now). cheers Mark Index: pg_freespacemap.c === RCS file: /projects/cvsroot/pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v retrieving revision 1.2 diff -c -r1.2 pg_freespacemap.c *** pg_freespacemap.c 14 Feb 2006 15:03:59 - 1.2 --- pg_freespacemap.c 9 Mar 2006 03:38:10 - *** *** 12,18 #include "storage/freespace.h" #include "utils/relcache.h" ! #define NUM_FREESPACE_PAGES_ELEM6 #if defined(WIN32) || defined(__CYGWIN__) /* Need DLLIMPORT for some things that are not so marked in main headers */ --- 12,18 #include "storage/freespace.h" #include "utils/relcache.h" ! #define NUM_FREESPACE_PAGES_ELEM5 #if defined(WIN32) || defined(__CYGWIN__) /* Need DLLIMPORT for some things that are not so marked in main headers */ *** *** 29,40 typedef struct { - uint32 blockid; - uint32 relfilenode; uint32 reltablespace; uint32 reldatabase; uint32 relblocknumber; ! uint32 blockfreebytes; } FreeSpacePagesRec; --- 29,40 typedef struct { uint32 reltablespace; uint32 reldatabase; + uint32 relfilenode; uint32 relblocknumber; ! uint32 bytes; ! boolisindex; } FreeSpacePagesRec; *** *** 91,107 /* Construct a tuple to return. */ tupledesc = CreateTemplateTupleDesc(NUM_FREESPACE_PAGES_ELEM, false); ! TupleDescInitEntry(tupledesc, (AttrNumber) 1, "blockid", ! INT4OID, -1, 0); ! TupleDescInitEntry(tupledesc, (AttrNumber) 2, "relfilenode", OIDOID, -1, 0); ! TupleDescInitEntry(tupledesc, (AttrNumber) 3, "reltablespace", OIDOID, -1, 0); ! TupleDescInitEntry(tupledesc, (AttrNumber) 4, "reldatabase", OIDOID, -1, 0); ! TupleDescInitEntry(tupledesc, (AttrNumber) 5, "relblocknumber", INT8OID, -1, 0); ! TupleDescInitEntry(tupledesc, (AttrNumber) 6, "blockfreebytes", INT4OID, -1, 0); /* Generate attribute metadata needed later to produce tuples */ --- 91,105 /* Construct a tuple to return. */ tupledesc = CreateTemplateTupleDesc(NUM_FREESPACE_PAGES_ELEM, false); ! TupleDescInitEntry(tupledesc, (AttrNumber) 1, "reltablespace", OIDOID, -1, 0); ! TupleDescInitEntry(tupledesc, (AttrNumber) 2, "reldatabase", OIDOID, -1, 0); ! TupleDescInitEntry(tupledesc, (AttrNumber) 3, "relfilenode", OIDOID, -1, 0); ! TupleDescInitEntry(tupledesc, (AttrNumber) 4, "relblocknumber", INT8OID, -1, 0); ! TupleD