Re: [PATCHES] Diagnostic functions

2007-05-17 Thread Bruce Momjian

Applied.  I also updated /contrib/README.  Thanks.

---

Heikki Linnakangas wrote:
> Bruce Momjian wrote:
> > Heikki Linnakangas wrote:
>  We already played the name game on hackers. My original suggestion was
>  "pgforensics". "pgdiagfuncs" and "pginspect" were also suggested, among
>  others. I'm still open to suggestions, though. Have any?
> >>> Something involving "page" would at least explain what you can diagnose.
> >> Well, how about "pageinspect" then?
> > 
> > Sounds good to me.
> 
> Ok, here's an updated patch. It's the same as the last one, except for 
> the name.
> 
> -- 
>Heikki Linnakangas
>EnterpriseDB   http://www.enterprisedb.com


-- 
  Bruce Momjian  <[EMAIL PROTECTED]>  http://momjian.us
  EnterpriseDB   http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

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


Re: [PATCHES] Diagnostic functions

2007-05-17 Thread Heikki Linnakangas

Bruce Momjian wrote:

Heikki Linnakangas wrote:

We already played the name game on hackers. My original suggestion was
"pgforensics". "pgdiagfuncs" and "pginspect" were also suggested, among
others. I'm still open to suggestions, though. Have any?

Something involving "page" would at least explain what you can diagnose.

Well, how about "pageinspect" then?


Sounds good to me.


Ok, here's an updated patch. It's the same as the last one, except for 
the name.


--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com
Index: contrib/Makefile
===
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/contrib/Makefile,v
retrieving revision 1.75
diff -c -r1.75 Makefile
*** contrib/Makefile	21 Apr 2007 17:26:17 -	1.75
--- contrib/Makefile	17 May 2007 16:54:43 -
***
*** 19,24 
--- 19,25 
  		lo		\
  		ltree		\
  		oid2name	\
+ 		pageinspect	\
  		pg_buffercache	\
  		pg_freespacemap \
  		pg_standby	\
Index: contrib/pageinspect/Makefile
===
RCS file: contrib/pageinspect/Makefile
diff -N contrib/pageinspect/Makefile
*** /dev/null	1 Jan 1970 00:00:00 -
--- contrib/pageinspect/Makefile	17 May 2007 16:52:43 -
***
*** 0 
--- 1,24 
+ #-
+ #
+ # pageinspect Makefile
+ #
+ # $PostgreSQL$
+ #
+ #-
+ 
+ MODULE_big	= pageinspect
+ OBJS		= rawpage.o heapfuncs.o btreefuncs.o
+ DOCS		= README.pageinspect
+ DATA_built	= pageinspect.sql
+ DATA  	= uninstall_pageinspect.sql
+ 
+ ifdef USE_PGXS
+ PGXS := $(shell pg_config --pgxs)
+ include $(PGXS)
+ else
+ subdir = contrib/pageinspect
+ top_builddir = ../..
+ include $(top_builddir)/src/Makefile.global
+ include $(top_srcdir)/contrib/contrib-global.mk
+ endif
+ 
Index: contrib/pageinspect/README.pageinspect
===
RCS file: contrib/pageinspect/README.pageinspect
diff -N contrib/pageinspect/README.pageinspect
*** /dev/null	1 Jan 1970 00:00:00 -
--- contrib/pageinspect/README.pageinspect	17 May 2007 16:53:18 -
***
*** 0 
--- 1,94 
+ The functions in this module allow you to inspect the contents of data pages
+ at a low level, for debugging purposes.
+ 
+ 1. Installation
+ 
+ $ make
+ $ make install
+ $ psql -e -f /usr/local/pgsql/share/contrib/pageinspect.sql test
+ 
+ 2. Functions included:
+ 
+ get_raw_page
+ 
+ get_raw_page reads one block of the named table and returns a copy as a
+ bytea field. This allows a single time-consistent copy of the block to be
+ made. Use of this functions is restricted to superusers.
+ 
+ page_header
+ ---
+ page_header shows fields which are common to all PostgreSQL heap and index
+ pages. Use of this function is restricted to superusers.
+ 
+ A page image obtained with get_raw_page should be passed as argument:
+ 
+ test=# SELECT * FROM page_header(get_raw_page('pg_class',0));
+lsn| tli | flags | lower | upper | special | pagesize | version
+ --+-+---+---+---+-+--+-
+  0/3C5614 |   1 | 1 |   216 |   256 |8192 | 8192 |   4
+ (1 row)
+ 
+ The returned columns correspond to the fields in the PageHeaderData-struct,
+ see src/include/storage/bufpage.h for more details.
+ 
+ heap_page_items
+ ---
+ heap_page_items shows all line pointers on a heap page.  For those line
+ pointers that are in use, tuple headers are also shown. All tuples are
+ shown, whether or not the tuples were visible to an MVCC snapshot at the
+ time the raw page was copied. Use of this function is restricted to
+ superusers.
+ 
+ A heap page image obtained with get_raw_page should be passed as argument:
+ 
+ test=# SELECT * FROM heap_page_items(get_raw_page('pg_class',0));
+ 
+ See src/include/storage/itemid.h and src/include/access/htup.h for
+ explanations of the fields returned.
+ 
+ bt_metap
+ 
+ bt_metap() returns information about the btree index metapage:
+ 
+ test=> SELECT * FROM bt_metap('pg_cast_oid_index');
+ -[ RECORD 1 ]-
+ magic | 340322
+ version   | 2
+ root  | 1
+ level | 0
+ fastroot  | 1
+ fastlevel | 0
+ 
+ bt_page_stats
+ -
+ bt_page_stats() shows information about single btree pages:
+ 
+ test=> SELECT * FROM bt_page_stats('pg_cast_oid_index', 1);
+ -[ RECORD 1 ]-+-
+ blkno | 1
+ type  | l
+ live_items| 256
+ dead_items| 0
+ avg_item_size | 12
+ page_size | 8192
+ free_

Re: [PATCHES] Diagnostic functions

2007-05-11 Thread Bruce Momjian
Heikki Linnakangas wrote:
> >> We already played the name game on hackers. My original suggestion was
> >> "pgforensics". "pgdiagfuncs" and "pginspect" were also suggested, among
> >> others. I'm still open to suggestions, though. Have any?
> > 
> > Something involving "page" would at least explain what you can diagnose.
> 
> Well, how about "pageinspect" then?

Sounds good to me.

-- 
  Bruce Momjian  <[EMAIL PROTECTED]>  http://momjian.us
  EnterpriseDB   http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

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


Re: [PATCHES] Diagnostic functions

2007-05-07 Thread Heikki Linnakangas

Peter Eisentraut wrote:

Am Montag, 7. Mai 2007 11:49 schrieb Heikki Linnakangas:

It's handy to be able to inspect pages from within a live database.


How reliable is it to inspect pages from within a database if you presumably 
suspect that database to be broken?


As long as the page header is valid, the functions should be able to 
deal with it (as in not crashing).


I found them extremely useful when I was developing the MVCC-safe 
CLUSTER patch. The index functions in pgstattuple were very useful when 
I worked on clustered indexes. In fact I reinvented the wheel and wrote 
a function of my own that did essentially the same thing as 
bt_page_items, before Bruce pointed out that such a thing already exists.



We already played the name game on hackers. My original suggestion was
"pgforensics". "pgdiagfuncs" and "pginspect" were also suggested, among
others. I'm still open to suggestions, though. Have any?


Something involving "page" would at least explain what you can diagnose.


Well, how about "pageinspect" then?

--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

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

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


Re: [PATCHES] Diagnostic functions

2007-05-07 Thread Peter Eisentraut
Am Montag, 7. Mai 2007 11:49 schrieb Heikki Linnakangas:
> It's handy to be able to inspect pages from within a live database.

How reliable is it to inspect pages from within a database if you presumably 
suspect that database to be broken?

> We already played the name game on hackers. My original suggestion was
> "pgforensics". "pgdiagfuncs" and "pginspect" were also suggested, among
> others. I'm still open to suggestions, though. Have any?

Something involving "page" would at least explain what you can diagnose.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/

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

   http://archives.postgresql.org


Re: [PATCHES] Diagnostic functions

2007-05-07 Thread Heikki Linnakangas

Peter Eisentraut wrote:

Heikki Linnakangas wrote:

Here's an update of Simon's Heap Page Diagnostic Functions. I now
consider it ready to commit.


How is this better than pg_filedump?


It's handy to be able to inspect pages from within a live database. The 
new functions work through shared_buffers, so you can see changes 
without having to issue a checkpoint to flush them to disk. pg_filedump 
takes a filename as argument, the new function takes relation name.


Having them as functions also allows you to do more advanced queries 
like "... WHERE (t_infomask & 1) <> 0 " to show tuples with a null bitmap.



"diagnostics" is an awfully general name, too.


We already played the name game on hackers. My original suggestion was 
"pgforensics". "pgdiagfuncs" and "pginspect" were also suggested, among 
others. I'm still open to suggestions, though. Have any?


--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

---(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] Diagnostic functions

2007-05-05 Thread Peter Eisentraut
Heikki Linnakangas wrote:
> Here's an update of Simon's Heap Page Diagnostic Functions. I now
> consider it ready to commit.

How is this better than pg_filedump?

"diagnostics" is an awfully general name, too.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/

---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate