Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-21 Thread Jeff Davis
On Wed, 2013-07-17 at 13:43 -0400, Alvaro Herrera wrote:
 Tom Lane escribió:
 
  My feeling about this code is that the reason we print the infomask in
  hex is so you can see exactly which bits are set if you care, and that
  the rest of the line ought to be designed to interpret the bits in as
  reader-friendly a way as possible.  So I don't buy the notion that we
  should just print out a name for each bit that's set.  I'd rather
  replace individual bit names with items like LOCKED_FOR_KEY_SHARE,
  LOCKED_FOR_SHARE, etc in cases where you have to combine multiple
  bits to understand the meaning.
 
 Okay, that's what I've been saying all along so I cannot but agree.  I
 haven't reviewed Jeff's patch lately; Jeff, does Tom's suggestion need
 some more new code, and if so are you open to doing this work, or shall
 I?

At first glance it seems like a pretty trivial change. I'm going on
vacation tomorrow and unfortunately I haven't had a chance to look at
this. Pgfoundry CVS is down, so I can't see whether it's already been
committed or not.

Regards,
Jeff Davis




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-17 Thread Alvaro Herrera
Tom Lane escribió:
 Alvaro Herrera alvhe...@2ndquadrant.com writes:
  Well, Tom opined in
  http://www.postgresql.org/message-id/23249.1370878...@sss.pgh.pa.us that
  the current patch is okay.  I have a mild opinion that it should instead
  print only SHR_LOCK when both bits are set, and one of the others when
  only one of them is set.  But I don't have a strong opinion about this,
  and since Tom disagrees with me, feel free to exercise your own (Jeff's)
  judgement.
 
 FWIW, I think that's exactly what I did in the preliminary 9.3 patch
 that I committed to pg_filedump a few weeks ago.  Could you take a look
 at what's there now and see if that's what you meant?

Here's sample output (-i) from the new code, i.e. this commit:
revision 1.7
date: 2013/06/06 18:33:17;  author: tgl;  state: Exp;  lines: +14 -10
Preliminary updates for Postgres 9.3.


Data -- 
 Item   1 -- Length:   28  Offset: 8160 (0x1fe0)  Flags: NORMAL
  XMIN: 692  XMAX: 693  CID|XVAC: 0
  Block Id: 0  linp Index: 1   Attributes: 1   Size: 24
  infomask: 0x0190 (XMAX_KEYSHR_LOCK|XMAX_LOCK_ONLY|XMIN_COMMITTED) 

 Item   2 -- Length:   28  Offset: 8128 (0x1fc0)  Flags: NORMAL
  XMIN: 692  XMAX: 694  CID|XVAC: 0
  Block Id: 0  linp Index: 2   Attributes: 1   Size: 24
  infomask: 0x01d0 
(XMAX_KEYSHR_LOCK|XMAX_EXCL_LOCK|XMAX_LOCK_ONLY|XMIN_COMMITTED) 

 Item   3 -- Length:   28  Offset: 8096 (0x1fa0)  Flags: NORMAL
  XMIN: 692  XMAX: 695  CID|XVAC: 0
  Block Id: 0  linp Index: 3   Attributes: 1   Size: 24
  infomask: 0x01c0 (XMAX_EXCL_LOCK|XMAX_LOCK_ONLY|XMIN_COMMITTED) 

 Item   4 -- Length:   28  Offset: 8064 (0x1f80)  Flags: NORMAL
  XMIN: 696  XMAX: 697  CID|XVAC: 0
  Block Id: 0  linp Index: 4   Attributes: 1   Size: 24
  infomask: 0x01c0 (XMAX_EXCL_LOCK|XMAX_LOCK_ONLY|XMIN_COMMITTED|KEYS_UPDATED) 

Item 1 has SELECT FOR KEY SHARE
Item 2 has SELECT FOR SHARE
Item 3 has SELECT FOR NO KEY UPDATE
Item 4 has SELECT FOR UPDATE

The one I was talking about is the second case, which prints
KEYSHR_LOCK|EXCL_LOCK to mean that there's a FOR SHARE lock.  I have no
problem reading it this way, but I fear that someone unfamiliar with
these bits might be confused.  On the other hand, trying to be nice and
interpret these bits (i.e. translate presence of both into something
like SHR_LOCK) might also be confusing, because that bit doesn't really
exist.  And one already needs to be careful while interpreting what do
KEYS_UPDATED and XMAX_LOCK_ONLY, or lack thereof, mean.

Perhaps it would be sensible to provide one more output line per tuple,
with interpretation of the flags, so it would tell you whether the tuple
has been locked or updated, and what kind of each it is.  I'd propose
something like

  status: locked (FOR {KEY SHARE,SHARE,NO KEY UPDATE,UPDATE}) [MultiXact: nnn]
  status: [HOT] updated (KEYS UPDATED/KEYS NOT UPDATED) [MultiXact: nnn]  To: 
blk/off
  status: deleted [MultiXact: nnn]

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-17 Thread Tom Lane
Alvaro Herrera alvhe...@2ndquadrant.com writes:
 The one I was talking about is the second case, which prints
 KEYSHR_LOCK|EXCL_LOCK to mean that there's a FOR SHARE lock.  I have no
 problem reading it this way, but I fear that someone unfamiliar with
 these bits might be confused.  On the other hand, trying to be nice and
 interpret these bits (i.e. translate presence of both into something
 like SHR_LOCK) might also be confusing, because that bit doesn't really
 exist.  And one already needs to be careful while interpreting what do
 KEYS_UPDATED and XMAX_LOCK_ONLY, or lack thereof, mean.

 Perhaps it would be sensible to provide one more output line per tuple,
 with interpretation of the flags, so it would tell you whether the tuple
 has been locked or updated, and what kind of each it is.  I'd propose
 something like

   status: locked (FOR {KEY SHARE,SHARE,NO KEY UPDATE,UPDATE}) [MultiXact: nnn]
   status: [HOT] updated (KEYS UPDATED/KEYS NOT UPDATED) [MultiXact: nnn]  To: 
 blk/off
   status: deleted [MultiXact: nnn]

Hm.  I'm loath to add another output line per tuple, just for space
reasons.

My feeling about this code is that the reason we print the infomask in
hex is so you can see exactly which bits are set if you care, and that
the rest of the line ought to be designed to interpret the bits in as
reader-friendly a way as possible.  So I don't buy the notion that we
should just print out a name for each bit that's set.  I'd rather
replace individual bit names with items like LOCKED_FOR_KEY_SHARE,
LOCKED_FOR_SHARE, etc in cases where you have to combine multiple
bits to understand the meaning.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-17 Thread Alvaro Herrera
Tom Lane escribió:

 My feeling about this code is that the reason we print the infomask in
 hex is so you can see exactly which bits are set if you care, and that
 the rest of the line ought to be designed to interpret the bits in as
 reader-friendly a way as possible.  So I don't buy the notion that we
 should just print out a name for each bit that's set.  I'd rather
 replace individual bit names with items like LOCKED_FOR_KEY_SHARE,
 LOCKED_FOR_SHARE, etc in cases where you have to combine multiple
 bits to understand the meaning.

Okay, that's what I've been saying all along so I cannot but agree.  I
haven't reviewed Jeff's patch lately; Jeff, does Tom's suggestion need
some more new code, and if so are you open to doing this work, or shall
I?

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-16 Thread Josh Berkus
On 07/08/2013 04:59 PM, Tom Lane wrote:
 Alvaro Herrera alvhe...@2ndquadrant.com writes:
 Well, Tom opined in
 http://www.postgresql.org/message-id/23249.1370878...@sss.pgh.pa.us that
 the current patch is okay.  I have a mild opinion that it should instead
 print only SHR_LOCK when both bits are set, and one of the others when
 only one of them is set.  But I don't have a strong opinion about this,
 and since Tom disagrees with me, feel free to exercise your own (Jeff's)
 judgement.
 
 FWIW, I think that's exactly what I did in the preliminary 9.3 patch
 that I committed to pg_filedump a few weeks ago.  Could you take a look
 at what's there now and see if that's what you meant?

So, is this getting committed today, or do we bounce it?

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-16 Thread Tom Lane
Josh Berkus j...@agliodbs.com writes:
 On 07/08/2013 04:59 PM, Tom Lane wrote:
 FWIW, I think that's exactly what I did in the preliminary 9.3 patch
 that I committed to pg_filedump a few weeks ago.  Could you take a look
 at what's there now and see if that's what you meant?

 So, is this getting committed today, or do we bounce it?

I was hoping for a comment from Alvaro, but wouldn't have gotten to
committing it today in any case.  IMO this patch doesn't really belong
in the commitfest queue, since pg_filedump isn't part of the community
distribution.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-08 Thread Jeff Davis
On Fri, 2013-07-05 at 22:43 -0700, Jeff Davis wrote:
 On Sat, 2013-07-06 at 10:30 +0900, Satoshi Nagayasu wrote:
  Hi,
  
  It looks fine, but I have one question here.
  
  When I run pg_filedump with -k against a database cluster which
  does not support checksums, pg_filedump produced checksum error as
  following. Is this expected or acceptable?
 
 Thank you for taking a look. That is expected, because there is not a
 good way to determine whether the file was created with checksums or
 not. So, we rely on the user to supply (or not) the -k flag.

I see this patch is still waiting on author in the CF. Is there
something else needed from me, or should we move this to ready for
committer?

Regards,
Jeff Davis




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-08 Thread Peter Geoghegan
On Mon, Jul 8, 2013 at 10:28 AM, Jeff Davis pg...@j-davis.com wrote:
 I see this patch is still waiting on author in the CF. Is there
 something else needed from me, or should we move this to ready for
 committer?

Well, obviously someone still needs to think through the handling of
the infoMask bits.

Alvaro?

-- 
Peter Geoghegan


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-08 Thread Alvaro Herrera
Peter Geoghegan escribió:
 On Mon, Jul 8, 2013 at 10:28 AM, Jeff Davis pg...@j-davis.com wrote:
  I see this patch is still waiting on author in the CF. Is there
  something else needed from me, or should we move this to ready for
  committer?
 
 Well, obviously someone still needs to think through the handling of
 the infoMask bits.

Well, Tom opined in
http://www.postgresql.org/message-id/23249.1370878...@sss.pgh.pa.us that
the current patch is okay.  I have a mild opinion that it should instead
print only SHR_LOCK when both bits are set, and one of the others when
only one of them is set.  But I don't have a strong opinion about this,
and since Tom disagrees with me, feel free to exercise your own (Jeff's)
judgement.

Tom's the only available committer in this case anyway.  [Actually,
pgfoundry.org says it's a zero-people team in the pgfiledump project
right now, but I'm hoping that's just a temporary glitch.]

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-08 Thread Peter Geoghegan
On Mon, Jul 8, 2013 at 11:52 AM, Alvaro Herrera
alvhe...@2ndquadrant.com wrote:
 Well, Tom opined in
 http://www.postgresql.org/message-id/23249.1370878...@sss.pgh.pa.us that
 the current patch is okay.  I have a mild opinion that it should instead
 print only SHR_LOCK when both bits are set, and one of the others when
 only one of them is set.  But I don't have a strong opinion about this,
 and since Tom disagrees with me, feel free to exercise your own (Jeff's)
 judgement.

I'm inclined to agree with you here, but I suppose it isn't all that important.


-- 
Peter Geoghegan


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-08 Thread Tom Lane
Alvaro Herrera alvhe...@2ndquadrant.com writes:
 Well, Tom opined in
 http://www.postgresql.org/message-id/23249.1370878...@sss.pgh.pa.us that
 the current patch is okay.  I have a mild opinion that it should instead
 print only SHR_LOCK when both bits are set, and one of the others when
 only one of them is set.  But I don't have a strong opinion about this,
 and since Tom disagrees with me, feel free to exercise your own (Jeff's)
 judgement.

FWIW, I think that's exactly what I did in the preliminary 9.3 patch
that I committed to pg_filedump a few weeks ago.  Could you take a look
at what's there now and see if that's what you meant?

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-05 Thread Satoshi Nagayasu

Hi,

I have reviewed this patch as a CF reviewer.

(2013/06/27 4:07), Jeff Davis wrote:

On Mon, 2013-06-24 at 20:34 -0400, Josh Kupershmidt wrote:

This patch is in the current CommitFest, does it still need to be
reviewed? If so, I notice that the version in pgfoundry's CVS is
rather different than the version the patch seems to have been built
against (presumably the pg_filedump-9.2.0.tar.gz release), and
conflicts in several places with cvs tip.


Rebased against CVS tip; attached.


It looks fine, but I have one question here.

When I run pg_filedump with -k against a database cluster which
does not support checksums, pg_filedump produced checksum error as
following. Is this expected or acceptable?

-
***
* PostgreSQL File/Block Formatted Dump Utility - Version 9.3.0
*
* File: /tmp/pgsql/data/base/16384/16397
* Options used: -k
*
* Dump created on: Sat Jul  6 10:32:15 2013
***

Block0 
Header -
 Block Offset: 0x Offsets: Lower 268 (0x010c)
 Block: Size 8192  Version4Upper 384 (0x0180)
 LSN:  logid  0 recoff 0x  Special  8192 (0x2000)
 Items:   61  Free Space:  116
 Checksum: 0x  Prune XID: 0x  Flags: 0x ()
 Length (including item array): 268

 Error: checksum failure: calculated 0xf797.

Data --
 Item   1 -- Length:  121  Offset: 8064 (0x1f80)  Flags: NORMAL
 Item   2 -- Length:  121  Offset: 7936 (0x1f00)  Flags: NORMAL
 Item   3 -- Length:  121  Offset: 7808 (0x1e80)  Flags: NORMAL
-

Please check attached script to reproduce it.

Also, I have update the help message and README.
Please check attached patch.

Regards,
--
Satoshi Nagayasu sn...@uptime.jp
Uptime Technologies, LLC. http://www.uptime.jp
PGHOME=/tmp/pgsql
PGPORT=15433

function build_check {
echo make PGSQL_INCLUDE_DIR=...
make PGSQL_INCLUDE_DIR=../../src/include clean
make PGSQL_INCLUDE_DIR=../../src/include all
make PGSQL_INCLUDE_DIR=../../src/include install
make PGSQL_INCLUDE_DIR=../../src/include clean

echo make -f Makefile.contrib...
make -f Makefile.contrib clean
make -f Makefile.contrib all
make -f Makefile.contrib install
make -f Makefile.contrib clean

echo make -f Makefile.contrib USE_PGXS=1...
PATH=${PGHOME}/bin:$PATH
make -f Makefile.contrib USE_PGXS=1 clean
make -f Makefile.contrib USE_PGXS=1 all
make -f Makefile.contrib USE_PGXS=1 install
make -f Makefile.contrib USE_PGXS=1 clean
}

function do_builddb {
INITDB_OPTS=$1
killall -9 postmaster postgres
rm -rf ${PGHOME}/data

initdb ${INITDB_OPTS} --no-locale -D ${PGHOME}/data
pg_ctl -w -D ${PGHOME}/data start -o -p ${PGPORT}
createdb -p ${PGPORT} testdb
pgbench -p ${PGPORT} -i testdb

psql -A -t -p ${PGPORT} testdbEOF  file
select '${PGHOME}/data/' || pg_relation_filepath(oid) from pg_class where 
relname like 'pgbench%';
EOF
}

function builddb_checksum_enabled {
do_builddb -k
}

function builddb_checksum_disabled {
do_builddb 
}

function test_not_verify_checksum {
LOG=$1
sed 's/^/pg_filedump /'  file  _test.sh
sh _test.sh  $LOG
}

function test_verify_checksum {
LOG=$1
sed 's/^/pg_filedump -k /'  file  _test.sh
sh _test.sh  $LOG
}

build_check

builddb_checksum_enabled
test_not_verify_checksum test_enabled_not_verify.log
test_verify_checksum test_enabled_verify.log

builddb_checksum_disabled
test_not_verify_checksum test_disabled_not_verify.log
test_verify_checksum test_disabled_verify.log
diff --git a/contrib/pg_filedump/README.pg_filedump 
b/contrib/pg_filedump/README.pg_filedump
index 63d086f..b3050cd 100644
--- a/contrib/pg_filedump/README.pg_filedump
+++ b/contrib/pg_filedump/README.pg_filedump
@@ -2,7 +2,7 @@ pg_filedump - Display formatted contents of a PostgreSQL heap, 
index,
   or control file.
 
 Copyright (c) 2002-2010 Red Hat, Inc.
-Copyright (c) 2011-2012, PostgreSQL Global Development Group
+Copyright (c) 2011-2013, PostgreSQL Global Development Group
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -59,10 +59,10 @@ not require any manual adjustments of the Makefile.
 
 Invocation:
 
-pg_filedump [-abcdfhixy] [-R startblock [endblock]] [-S blocksize] file
+pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-S blocksize] file
 
-Defaults are: relative addressing, range of the entire file, block size
-  as listed on block 0 in the file
+Defaults are: relative addressing, range of the entire file, block
+   

Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-07-05 Thread Jeff Davis
On Sat, 2013-07-06 at 10:30 +0900, Satoshi Nagayasu wrote:
 Hi,
 
 It looks fine, but I have one question here.
 
 When I run pg_filedump with -k against a database cluster which
 does not support checksums, pg_filedump produced checksum error as
 following. Is this expected or acceptable?

Thank you for taking a look. That is expected, because there is not a
good way to determine whether the file was created with checksums or
not. So, we rely on the user to supply (or not) the -k flag.

Regards,
Jeff Davis




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-28 Thread Jeff Davis
On Thu, 2013-06-27 at 15:59 +0200, Andres Freund wrote:
 Maybe the trick is to add a recovery.conf option to make postgres replay
 to the first restartpoint and then shutdown. At that point you can be
 sure there aren't any torn pages anymore (bugs aside).
 In fact that sounds like a rather useful pg_basebackup extension...

+1

Jeff Davis




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-27 Thread Andres Freund
On 2013-06-26 21:18:49 -0700, Peter Geoghegan wrote:
 On Wed, Jun 26, 2013 at 8:27 PM, Tom Lane t...@sss.pgh.pa.us wrote:
  TBH, I've always been annoyed that pg_filedump is GPL and so there's no
  way for us to just ship it in contrib.  (That stems from Red Hat
  corporate policy of a dozen years ago, but the conflict is real anyway.)
  If somebody is sufficiently excited about this topic to do something
  that's largely new anyway, I'd be in favor of starting from scratch so
  it could be put under the usual Postgres license.
 
 Heroku are interested in online verification of basebackups (i.e.
 using checksums to verify the integrity of heap files as they are
 backed up, with a view to relying less and less on logical backups). I
 am very glad that you made the page checksums stuff available to
 external utilities in commit f04216341dd1cc235e975f93ac806d9d3729a344.
 
 In the last couple of days, I haven't been able to figure out a way to
 solve the problem of torn pages in a way that isn't a complete kludge
 (with a hopefully-acceptable risk of false positives), so I've been
 operating under the assumption that anything I produce here won't be
 up to the standards of contrib.

Why not do this from a function/background worker in the backend where
you can go via the buffer manager to avoid torn pages et al. If you use
a buffer strategy the cache poisoning et al should be controlleable.

Greetings,

Andres Freund

-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-27 Thread Peter Geoghegan
On Wed, Jun 26, 2013 at 11:27 PM, Andres Freund and...@2ndquadrant.com wrote:
 Why not do this from a function/background worker in the backend where
 you can go via the buffer manager to avoid torn pages et al. If you use
 a buffer strategy the cache poisoning et al should be controlleable.

I had considered that, but thought it might be a little bit
aggressive, even with a strategy of BAS_BULKREAD. Maybe the kludge I
have in mind might not end up being that bad in practice, and would
certainly perform better than an approach that used the buffer
manager. But then, going through shared_buffers could be worth the
overhead, if only for the peace of mind of not relying on something
that is subtly broken.


-- 
Peter Geoghegan


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-27 Thread Andres Freund
On 2013-06-26 23:42:55 -0700, Peter Geoghegan wrote:
 On Wed, Jun 26, 2013 at 11:27 PM, Andres Freund and...@2ndquadrant.com 
 wrote:
  Why not do this from a function/background worker in the backend where
  you can go via the buffer manager to avoid torn pages et al. If you use
  a buffer strategy the cache poisoning et al should be controlleable.
 
 I had considered that, but thought it might be a little bit
 aggressive, even with a strategy of BAS_BULKREAD.

Well, you can influence the pacing yourself, you don't need to rely on
the strategy for that. I'd only use it because of the ringbuffer logic
it has to avoid trashing the cache.

 Maybe the kludge I
 have in mind might not end up being that bad in practice, and would
 certainly perform better than an approach that used the buffer
 manager.

What do you have in mind then?

 But then, going through shared_buffers could be worth the
 overhead, if only for the peace of mind of not relying on something
 that is subtly broken.

Spurious alarms quickly lead to people ignoring them, consciously or
not, so trying to take care not to go there sounds like a good idea.

Greetings,

Andres Freund

-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-27 Thread Peter Geoghegan
On Tue, Jun 18, 2013 at 9:42 AM, Jeff Davis pg...@j-davis.com wrote:
 I'm not sure what the resolution of Alvaro's concern was, so I left the
 flag reporting the same as the previous patch.

Alvaro's concern was that the new flags added (those added by the
foreign key locks patch) do something cute with re-using multiple
other bits in an otherwise nonsensical combination to represent a
distinct state. So as written, the infoMask if statements will result
in spurious reporting of information stored in t_infomask. If you AND
some integer with HEAP_XMAX_SHR_LOCK and get something non-zero,
you'll surely also get a non-zero result with HEAP_LOCK_MASK, because
the latter flag has all the same bits set as the former (plus others,
obviously).


-- 
Peter Geoghegan


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-27 Thread Peter Geoghegan
On Thu, Jun 27, 2013 at 12:07 AM, Peter Geoghegan p...@heroku.com wrote:
 I'm not sure what the resolution of Alvaro's concern was, so I left the
 flag reporting the same as the previous patch.

 Alvaro's concern was that the new flags added (those added by the
 foreign key locks patch) do something cute with re-using multiple
 other bits in an otherwise nonsensical combination to represent a
 distinct state.

I just realized that it wasn't that you didn't understand the nature
of the problem, but that you weren't sure of a resolution. Sorry for
the noise.

-- 
Peter Geoghegan


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-27 Thread Andres Freund
On 2013-06-27 09:51:07 -0400, Tom Lane wrote:
 Andres Freund and...@2ndquadrant.com writes:
  On 2013-06-26 21:18:49 -0700, Peter Geoghegan wrote:
  Heroku are interested in online verification of basebackups (i.e.
  using checksums to verify the integrity of heap files as they are
  backed up, with a view to relying less and less on logical backups).
 
  Why not do this from a function/background worker in the backend where
  you can go via the buffer manager to avoid torn pages et al. If you use
  a buffer strategy the cache poisoning et al should be controlleable.
 
 That would require having a functioning postmaster environment, which
 seems like it would make such a tool much less flexible.

I personally wouldn't trust online backups that aren't proven to be
replayable into a runnable state very much. I have seen too many cases
where that failed.

Maybe the trick is to add a recovery.conf option to make postgres replay
to the first restartpoint and then shutdown. At that point you can be
sure there aren't any torn pages anymore (bugs aside).
In fact that sounds like a rather useful pg_basebackup extension...

Greetings,

Andres Freund

-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-27 Thread Tom Lane
Andres Freund and...@2ndquadrant.com writes:
 On 2013-06-26 21:18:49 -0700, Peter Geoghegan wrote:
 Heroku are interested in online verification of basebackups (i.e.
 using checksums to verify the integrity of heap files as they are
 backed up, with a view to relying less and less on logical backups).

 Why not do this from a function/background worker in the backend where
 you can go via the buffer manager to avoid torn pages et al. If you use
 a buffer strategy the cache poisoning et al should be controlleable.

That would require having a functioning postmaster environment, which
seems like it would make such a tool much less flexible.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-26 Thread Jeff Davis
On Mon, 2013-06-24 at 20:34 -0400, Josh Kupershmidt wrote:
 This patch is in the current CommitFest, does it still need to be
 reviewed? If so, I notice that the version in pgfoundry's CVS is
 rather different than the version the patch seems to have been built
 against (presumably the pg_filedump-9.2.0.tar.gz release), and
 conflicts in several places with cvs tip.

Rebased against CVS tip; attached.

 Also, would anyone be willing to convert this repository to git and
 post it on github or similar? pgfoundry is becoming increasingly
 difficult to use, for instance the 'Browse CVS Repository' link for
 pg_filedump and other projects is broken[1] and apparently has been
 for months[2], not to mention the general crumminess of using CVS [3].

Eventually, it would be nice to have a more full-featured offline
checker utility. Do we want to try to turn this utility into that, or
make a new one?

Regards,
Jeff Davis

Only in pg_filedump.checksums/: .deps
Only in pg_filedump.checksums/: pg_filedump
diff -rc pg_filedump/pg_filedump.c pg_filedump.checksums/pg_filedump.c
*** pg_filedump/pg_filedump.c	2013-06-06 11:33:17.0 -0700
--- pg_filedump.checksums/pg_filedump.c	2013-06-26 11:53:45.780117294 -0700
***
*** 26,31 
--- 26,38 
  
  #include utils/pg_crc_tables.h
  
+ // checksum_impl.h uses Assert, which doesn't work outside the server
+ #undef Assert
+ #define Assert(X)
+ 
+ #include storage/checksum.h
+ #include storage/checksum_impl.h
+ 
  // Global variables for ease of use mostly
  static FILE *fp = NULL;		// File to dump or format
  static char *fileName = NULL;	// File name for display
***
*** 40,51 
  static void DisplayOptions (unsigned int validOptions);
  static unsigned int ConsumeOptions (int numOptions, char **options);
  static int GetOptionValue (char *optionString);
! static void FormatBlock ();
  static unsigned int GetBlockSize ();
  static unsigned int GetSpecialSectionType (Page page);
  static bool IsBtreeMetaPage(Page page);
  static void CreateDumpFileHeader (int numOptions, char **options);
! static int FormatHeader (Page page);
  static void FormatItemBlock (Page page);
  static void FormatItem (unsigned int numBytes, unsigned int startIndex,
  			unsigned int formatAs);
--- 47,58 
  static void DisplayOptions (unsigned int validOptions);
  static unsigned int ConsumeOptions (int numOptions, char **options);
  static int GetOptionValue (char *optionString);
! static void FormatBlock (BlockNumber blkno);
  static unsigned int GetBlockSize ();
  static unsigned int GetSpecialSectionType (Page page);
  static bool IsBtreeMetaPage(Page page);
  static void CreateDumpFileHeader (int numOptions, char **options);
! static int FormatHeader (Page page, BlockNumber blkno);
  static void FormatItemBlock (Page page);
  static void FormatItem (unsigned int numBytes, unsigned int startIndex,
  			unsigned int formatAs);
***
*** 288,293 
--- 295,305 
  		  SET_OPTION (itemOptions, ITEM_DETAIL, 'i');
  		  break;
  
+ 		  // Verify block checksums
+ 		case 'k':
+ 		  SET_OPTION (blockOptions, BLOCK_CHECKSUMS, 'k');
+ 		  break;
+ 
  		  // Interpret items as standard index values
  		case 'x':
  		  SET_OPTION (itemOptions, ITEM_INDEX, 'x');
***
*** 555,561 
  
  // Dump out a formatted block header for the requested block
  static int
! FormatHeader (Page page)
  {
int rc = 0;
unsigned int headerBytes;
--- 567,573 
  
  // Dump out a formatted block header for the requested block
  static int
! FormatHeader (Page page, BlockNumber blkno)
  {
int rc = 0;
unsigned int headerBytes;
***
*** 647,652 
--- 659,672 
  	  || (pageHeader-pd_upper  pageHeader-pd_lower)
  	  || (pageHeader-pd_special  blockSize))
  	printf ( Error: Invalid header information.\n\n);
+ 
+   if (blockOptions  BLOCK_CHECKSUMS)
+ 	{
+ 	  uint16 calc_checksum = pg_checksum_page(page, blkno);
+ 	  if (calc_checksum != pageHeader-pd_checksum)
+ 	printf( Error: checksum failure: calculated 0x%04x.\n\n,
+ 		   calc_checksum);
+ 	}
  }
  
// If we have reached the end of file while interpreting the header, let
***
*** 1208,1214 
  
  // For each block, dump out formatted header and content information
  static void
! FormatBlock ()
  {
Page page = (Page) buffer;
pageOffset = blockSize * currentBlock;
--- 1228,1234 
  
  // For each block, dump out formatted header and content information
  static void
! FormatBlock (BlockNumber blkno)
  {
Page page = (Page) buffer;
pageOffset = blockSize * currentBlock;
***
*** 1228,1234 
int rc;
// Every block contains a header, items and possibly a special
// section.  Beware of partial block reads though
!   rc = FormatHeader (page);
  
// If we didn't encounter a partial read in the header, carry on...
if (rc != EOF_ENCOUNTERED)
--- 1248,1254 
int rc;
  

Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-26 Thread Tom Lane
Jeff Davis pg...@j-davis.com writes:
 On Mon, 2013-06-24 at 20:34 -0400, Josh Kupershmidt wrote:
 This patch is in the current CommitFest, does it still need to be
 reviewed? If so, I notice that the version in pgfoundry's CVS is
 rather different than the version the patch seems to have been built
 against (presumably the pg_filedump-9.2.0.tar.gz release), and
 conflicts in several places with cvs tip.

 Rebased against CVS tip; attached.

Thanks.  I'm feeling pretty overworked these days but will try to push
this into pgfoundry in a timely fashion.

 Eventually, it would be nice to have a more full-featured offline
 checker utility. Do we want to try to turn this utility into that, or
 make a new one?

TBH, I've always been annoyed that pg_filedump is GPL and so there's no
way for us to just ship it in contrib.  (That stems from Red Hat
corporate policy of a dozen years ago, but the conflict is real anyway.)
If somebody is sufficiently excited about this topic to do something
that's largely new anyway, I'd be in favor of starting from scratch so
it could be put under the usual Postgres license.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-26 Thread Peter Geoghegan
On Wed, Jun 26, 2013 at 8:27 PM, Tom Lane t...@sss.pgh.pa.us wrote:
 TBH, I've always been annoyed that pg_filedump is GPL and so there's no
 way for us to just ship it in contrib.  (That stems from Red Hat
 corporate policy of a dozen years ago, but the conflict is real anyway.)
 If somebody is sufficiently excited about this topic to do something
 that's largely new anyway, I'd be in favor of starting from scratch so
 it could be put under the usual Postgres license.

Heroku are interested in online verification of basebackups (i.e.
using checksums to verify the integrity of heap files as they are
backed up, with a view to relying less and less on logical backups). I
am very glad that you made the page checksums stuff available to
external utilities in commit f04216341dd1cc235e975f93ac806d9d3729a344.

In the last couple of days, I haven't been able to figure out a way to
solve the problem of torn pages in a way that isn't a complete kludge
(with a hopefully-acceptable risk of false positives), so I've been
operating under the assumption that anything I produce here won't be
up to the standards of contrib. I had intended to release whatever
results as an open source project anyway. However, if we can figure
out a way to solve the torn pages problem, or at least produce
something acceptable, I think I'd certainly be able to find the time
to work on a contrib module that is mainly concerned with verifying
basebackups, but also offers some pg_filedump-like functionality.
That's something largely new.

-- 
Peter Geoghegan


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-25 Thread Jeff Davis
On Mon, 2013-06-24 at 20:34 -0400, Josh Kupershmidt wrote:
 This patch is in the current CommitFest, does it still need to be
 reviewed? If so, I notice that the version in pgfoundry's CVS is
 rather different than the version the patch seems to have been built
 against (presumably the pg_filedump-9.2.0.tar.gz release), and
 conflicts in several places with cvs tip.

Oh, thank you. After browsing the CVS repo failed, I just made the diff
against 9.2.0. I'll rebase it.

Regards,
Jeff Davis




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-24 Thread Josh Kupershmidt
On Tue, Jun 18, 2013 at 12:42 PM, Jeff Davis pg...@j-davis.com wrote:
 Attached a new diff for pg_filedump that makes use of the above change.

 I'm not sure what the resolution of Alvaro's concern was, so I left the
 flag reporting the same as the previous patch.

This patch is in the current CommitFest, does it still need to be
reviewed? If so, I notice that the version in pgfoundry's CVS is
rather different than the version the patch seems to have been built
against (presumably the pg_filedump-9.2.0.tar.gz release), and
conflicts in several places with cvs tip.

Also, would anyone be willing to convert this repository to git and
post it on github or similar? pgfoundry is becoming increasingly
difficult to use, for instance the 'Browse CVS Repository' link for
pg_filedump and other projects is broken[1] and apparently has been
for months[2], not to mention the general crumminess of using CVS [3].

Josh

[1] http://pgfoundry.org/scm/browser.php?group_id=1000541
[2] 
http://pgfoundry.org/forum/forum.php?thread_id=15554forum_id=44group_id=113
[3] Since the pgfoundry cvs server apparently doesn't support the 'ls'
command, you might need to know this to know which module name to
check out: cvs -d
:pserver:anonym...@cvs.pgfoundry.org:/cvsroot/pgfiledump checkout
pg_filedump


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-24 Thread Tom Lane
Josh Kupershmidt schmi...@gmail.com writes:
 This patch is in the current CommitFest, does it still need to be
 reviewed? If so, I notice that the version in pgfoundry's CVS is
 rather different than the version the patch seems to have been built
 against (presumably the pg_filedump-9.2.0.tar.gz release), and
 conflicts in several places with cvs tip.

Yeah, I pushed some basic 9.3 compatibility fixes into pg_filedump CVS
a few weeks back.  If someone could rebase the patch against that,
I'd appreciate it.

 Also, would anyone be willing to convert this repository to git and
 post it on github or similar?

I know it's time to get off of pgfoundry, but doing so for pg_filedump
is way down the priority list ...

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-18 Thread Jeff Davis
On Thu, 2013-06-13 at 20:09 -0400, Tom Lane wrote:
 What I propose we do about this is reduce backend/storage/page/checksum.c
 to something like
 
 #include postgres.h
 #include storage/checksum.h
 #include storage/checksum_impl.h

Attached a new diff for pg_filedump that makes use of the above change.

I'm not sure what the resolution of Alvaro's concern was, so I left the
flag reporting the same as the previous patch.

Regards,
Jeff Davis

Common subdirectories: pg_filedump-9.2.0/.deps and pg_filedump-9.3.0j/.deps
diff -Nc pg_filedump-9.2.0/Makefile pg_filedump-9.3.0j/Makefile
*** pg_filedump-9.2.0/Makefile	2012-03-12 09:02:44.0 -0700
--- pg_filedump-9.3.0j/Makefile	2013-06-18 09:14:42.442220848 -0700
***
*** 1,7 
  # View README.pg_filedump first
  
  # note this must match version macros in pg_filedump.h
! FD_VERSION=9.2.0
  
  CC=gcc
  CFLAGS=-g -O -Wall -Wmissing-prototypes -Wmissing-declarations
--- 1,7 
  # View README.pg_filedump first
  
  # note this must match version macros in pg_filedump.h
! FD_VERSION=9.3.0
  
  CC=gcc
  CFLAGS=-g -O -Wall -Wmissing-prototypes -Wmissing-declarations
diff -Nc pg_filedump-9.2.0/pg_filedump.c pg_filedump-9.3.0j/pg_filedump.c
*** pg_filedump-9.2.0/pg_filedump.c	2012-03-12 08:58:31.0 -0700
--- pg_filedump-9.3.0j/pg_filedump.c	2013-06-18 09:25:42.438208300 -0700
***
*** 26,31 
--- 26,37 
  
  #include utils/pg_crc_tables.h
  
+ // checksum_impl.h uses Assert, which doesn't work outside the server
+ #undef Assert
+ #define Assert(X)
+ 
+ #include storage/checksum_impl.h
+ 
  // Global variables for ease of use mostly
  static FILE *fp = NULL;		// File to dump or format
  static char *fileName = NULL;	// File name for display
***
*** 40,51 
  static void DisplayOptions (unsigned int validOptions);
  static unsigned int ConsumeOptions (int numOptions, char **options);
  static int GetOptionValue (char *optionString);
! static void FormatBlock ();
  static unsigned int GetBlockSize ();
  static unsigned int GetSpecialSectionType (Page page);
  static bool IsBtreeMetaPage(Page page);
  static void CreateDumpFileHeader (int numOptions, char **options);
! static int FormatHeader (Page page);
  static void FormatItemBlock (Page page);
  static void FormatItem (unsigned int numBytes, unsigned int startIndex,
  			unsigned int formatAs);
--- 46,57 
  static void DisplayOptions (unsigned int validOptions);
  static unsigned int ConsumeOptions (int numOptions, char **options);
  static int GetOptionValue (char *optionString);
! static void FormatBlock (BlockNumber blkno);
  static unsigned int GetBlockSize ();
  static unsigned int GetSpecialSectionType (Page page);
  static bool IsBtreeMetaPage(Page page);
  static void CreateDumpFileHeader (int numOptions, char **options);
! static int FormatHeader (Page page, BlockNumber blkno);
  static void FormatItemBlock (Page page);
  static void FormatItem (unsigned int numBytes, unsigned int startIndex,
  			unsigned int formatAs);
***
*** 288,293 
--- 294,304 
  		  SET_OPTION (itemOptions, ITEM_DETAIL, 'i');
  		  break;
  
+ 		  // Verify block checksums
+ 		case 'k':
+ 		  SET_OPTION (blockOptions, BLOCK_CHECKSUMS, 'k');
+ 		  break;
+ 
  		  // Interpret items as standard index values
  		case 'x':
  		  SET_OPTION (itemOptions, ITEM_INDEX, 'x');
***
*** 555,561 
  
  // Dump out a formatted block header for the requested block
  static int
! FormatHeader (Page page)
  {
int rc = 0;
unsigned int headerBytes;
--- 566,572 
  
  // Dump out a formatted block header for the requested block
  static int
! FormatHeader (Page page, BlockNumber blkno)
  {
int rc = 0;
unsigned int headerBytes;
***
*** 609,623 
  	  Block: Size %4d  Version %4uUpper%4u (0x%04hx)\n
  	  LSN:  logid %6d recoff 0x%08x  Special  %4u (0x%04hx)\n
  	  Items: %4d  Free Space: %4u\n
! 	  TLI: 0x%04x  Prune XID: 0x%08x  Flags: 0x%04x (%s)\n
  	  Length (including item array): %u\n\n,
  	 pageOffset, pageHeader-pd_lower, pageHeader-pd_lower,
  	 (int) PageGetPageSize (page), blockVersion,
  	 pageHeader-pd_upper, pageHeader-pd_upper,
! 	 pageLSN.xlogid, pageLSN.xrecoff,
  	 pageHeader-pd_special, pageHeader-pd_special,
  	 maxOffset, pageHeader-pd_upper - pageHeader-pd_lower,
! 	 pageHeader-pd_tli, pageHeader-pd_prune_xid,
  	 pageHeader-pd_flags, flagString,
  	 headerBytes);
  
--- 620,634 
  	  Block: Size %4d  Version %4uUpper%4u (0x%04hx)\n
  	  LSN:  logid %6d recoff 0x%08x  Special  %4u (0x%04hx)\n
  	  Items: %4d  Free Space: %4u\n
! 	  Checksum: %05hu  Prune XID: 0x%08x  Flags: 0x%04x (%s)\n
  	  Length (including item array): %u\n\n,
  	 pageOffset, pageHeader-pd_lower, pageHeader-pd_lower,
  	 (int) PageGetPageSize (page), blockVersion,
  	 pageHeader-pd_upper, pageHeader-pd_upper,
! 	 (uint32) (pageLSN  32), 

Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-14 Thread Jeff Davis
On Thu, 2013-06-13 at 20:09 -0400, Tom Lane wrote:
 What I propose we do about this is reduce backend/storage/page/checksum.c
 to something like
 
 #include postgres.h
 #include storage/checksum.h
 #include storage/checksum_impl.h
 
 moving all the code currently in the file into a new .h file.  Then,
 any external programs such as pg_filedump can use the checksum code
 by including checksum_impl.h.  This is essentially the same thing we
 did with the CRC support functionality some time ago.

Thank you for taking care of that. After seeing that it needed to be in
a header file, I was going to try doing it all as macros.

I have a question about the commit though: shouldn't both functions be
static if they are in a .h file? Otherwise, it could lead to naming
conflicts. I suppose it's wrong to include the implementation file
twice, but it still might be confusing if someone tries. Two ideas that
come to mind are:
  * make both static and then have a trivial wrapper in checksum.c
  * export one or both functions, but use #ifndef CHECKSUM_IMPL_H to
prevent redefinition

 Also, we have the cut-point between checksum.c and bufpage.c at the
 wrong place.  IMO we should move PageCalcChecksum16 in toto into
 checksum.c (or really now into checksum_impl.h), because that and not
 just checksum_block() is the functionality that is wanted.

Agreed.

Regards,
Jeff Davis




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-14 Thread Tom Lane
Jeff Davis pg...@j-davis.com writes:
 I have a question about the commit though: shouldn't both functions be
 static if they are in a .h file? Otherwise, it could lead to naming
 conflicts. I suppose it's wrong to include the implementation file
 twice, but it still might be confusing if someone tries. Two ideas that
 come to mind are:
   * make both static and then have a trivial wrapper in checksum.c
   * export one or both functions, but use #ifndef CHECKSUM_IMPL_H to
 prevent redefinition

Ah, you are right, I forgot the #ifndef CHECKSUM_IMPL_H dance.  Will fix
in a bit.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-14 Thread Andres Freund
On 2013-06-14 11:59:04 -0400, Tom Lane wrote:
 Jeff Davis pg...@j-davis.com writes:
  I have a question about the commit though: shouldn't both functions be
  static if they are in a .h file? Otherwise, it could lead to naming
  conflicts. I suppose it's wrong to include the implementation file
  twice, but it still might be confusing if someone tries. Two ideas that
  come to mind are:
* make both static and then have a trivial wrapper in checksum.c
* export one or both functions, but use #ifndef CHECKSUM_IMPL_H to
  prevent redefinition
 
 Ah, you are right, I forgot the #ifndef CHECKSUM_IMPL_H dance.  Will fix
 in a bit.

That won't help against errors if it's included in two different
files/translation units though. I don't really see a valid case where it
could be validly be included multiple times in one TU?
If anything we should #error in that case, but I am not sure it's worth
bothering.
E.g. in rmgrlist.h we have the following comment:
/* there is deliberately not an #ifndef RMGRLIST_H here */
and I think the reasoning behind that comment applies here as well.

Greetings,

Andres Freund

-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-14 Thread Tom Lane
Andres Freund and...@2ndquadrant.com writes:
 On 2013-06-14 11:59:04 -0400, Tom Lane wrote:
 Ah, you are right, I forgot the #ifndef CHECKSUM_IMPL_H dance.  Will fix
 in a bit.

 That won't help against errors if it's included in two different
 files/translation units though.

Good point, but there's not any real reason to do that --- only
checksum.h should ever be #include'd in more than one file.  Any program
using this stuff is expected to #include checksum_impl.h in exactly one
place.  So maybe it's fine as-is.

 E.g. in rmgrlist.h we have the following comment:
 /* there is deliberately not an #ifndef RMGRLIST_H here */
 and I think the reasoning behind that comment applies here as well.

Well, that's a different case: there, and also in kwlist.h, there's an
idea that it could actually be useful to #include the file more than
once, redefining the PG_RMGR() macro each time.  There's no such use
case that I can see for checksum_impl.h.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-13 Thread Tom Lane
Jeff Davis pg...@j-davis.com writes:
 The patch is a bit ugly: I had to copy some code, and copy the entire
 checksum.c file (minus some Asserts, which don't work in an external
 program). Suggestions welcome.

What I propose we do about this is reduce backend/storage/page/checksum.c
to something like

#include postgres.h
#include storage/checksum.h
#include storage/checksum_impl.h

moving all the code currently in the file into a new .h file.  Then,
any external programs such as pg_filedump can use the checksum code
by including checksum_impl.h.  This is essentially the same thing we
did with the CRC support functionality some time ago.

Also, we have the cut-point between checksum.c and bufpage.c at the
wrong place.  IMO we should move PageCalcChecksum16 in toto into
checksum.c (or really now into checksum_impl.h), because that and not
just checksum_block() is the functionality that is wanted.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-10 Thread Jeff Davis
On Mon, 2013-06-10 at 01:28 -0400, Alvaro Herrera wrote:
 Hm, note that XMAX_SHR_LOCK is two bits, so when that flag is present
 you will get the three lock modes displayed with the above code, which is
 probably going to be misleading.  htup_details.h does this:
 
 /*
  * Use these to test whether a particular lock is applied to a tuple
  */
 #define HEAP_XMAX_IS_SHR_LOCKED(infomask) \
   (((infomask)  HEAP_LOCK_MASK) == HEAP_XMAX_SHR_LOCK)
 #define HEAP_XMAX_IS_EXCL_LOCKED(infomask) \
   (((infomask)  HEAP_LOCK_MASK) == HEAP_XMAX_EXCL_LOCK)
 #define HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) \
   (((infomask)  HEAP_LOCK_MASK) == HEAP_XMAX_KEYSHR_LOCK)
 
 Presumably it'd be better to do something similar.

I was hesitant to do too much interpretation of the bits. Do you think
it would be better to just remove the test for XMAX_SHR_LOCK?

Regards,
Jeff Davis




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-10 Thread Alvaro Herrera
Jeff Davis wrote:

 I was hesitant to do too much interpretation of the bits. Do you think
 it would be better to just remove the test for XMAX_SHR_LOCK?

I don't know, but then I'm biased because I know what that specific bit
combination means.  I guess someone that doesn't know is going to be
surprised by seeing both lock strength bits together .. but maybe
they're just going to have a look at htup_details.h and instantly
understand what's going on.  Not sure how likely that is.

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-10 Thread Tom Lane
Alvaro Herrera alvhe...@2ndquadrant.com writes:
 Jeff Davis wrote:
 I was hesitant to do too much interpretation of the bits. Do you think
 it would be better to just remove the test for XMAX_SHR_LOCK?

 I don't know, but then I'm biased because I know what that specific bit
 combination means.  I guess someone that doesn't know is going to be
 surprised by seeing both lock strength bits together .. but maybe
 they're just going to have a look at htup_details.h and instantly
 understand what's going on.  Not sure how likely that is.

I think it's all right because there are only 4 combinations of the two
bits and all 4 will be printed sensibly if we do it this way.  It would
be bad if pg_filedump could print invalid flag combinations in a
misleading way --- but I don't see such a risk here.  So we might as
well go for readability.

The thing I'm not too happy about is having to copy the checksum code
into pg_filedump.  We just got rid of the need to do that for the CRC
code, and here it is coming back again.  Can't we rearrange the core
checksum code similarly to what we did for the CRC stuff recently,
so that you only need access to a .h file for it?

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-10 Thread Jeff Davis
On Mon, 2013-06-10 at 11:38 -0400, Tom Lane wrote:
 The thing I'm not too happy about is having to copy the checksum code
 into pg_filedump.  We just got rid of the need to do that for the CRC
 code, and here it is coming back again.  Can't we rearrange the core
 checksum code similarly to what we did for the CRC stuff recently,
 so that you only need access to a .h file for it?

The CRC implementation is entirely in header files. Do you think we need
to go that far, or is it fine to just put it in libpgport and link that
to pg_filedump?

Regards,
Jeff Davis




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-10 Thread Alvaro Herrera
Jeff Davis wrote:
 On Mon, 2013-06-10 at 11:38 -0400, Tom Lane wrote:
  The thing I'm not too happy about is having to copy the checksum code
  into pg_filedump.  We just got rid of the need to do that for the CRC
  code, and here it is coming back again.  Can't we rearrange the core
  checksum code similarly to what we did for the CRC stuff recently,
  so that you only need access to a .h file for it?
 
 The CRC implementation is entirely in header files. Do you think we need
 to go that far, or is it fine to just put it in libpgport and link that
 to pg_filedump?

If a lib is okay, use libpgcommon please, not libpgport.  But I think a
.h would be better, because there'd be no need to have a built source
tree to build pg_filedump, only the headers installed.

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-10 Thread Tom Lane
Alvaro Herrera alvhe...@2ndquadrant.com writes:
 Jeff Davis wrote:
 The CRC implementation is entirely in header files. Do you think we need
 to go that far, or is it fine to just put it in libpgport and link that
 to pg_filedump?

 If a lib is okay, use libpgcommon please, not libpgport.  But I think a
 .h would be better, because there'd be no need to have a built source
 tree to build pg_filedump, only the headers installed.

Neither lib would provide a useful solution so far as Red Hat's
packaging is concerned, because those libs are not exposed to other
packages (and never will be, unless we start supplying them as .so's)

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_filedump 9.3: checksums (and a few other fixes)

2013-06-09 Thread Alvaro Herrera
Jeff Davis wrote:

 --- 1000,1015 
   strcat (flagString, HASEXTERNAL|);
 if (infoMask  HEAP_HASOID)
   strcat (flagString, HASOID|);
 +   if (infoMask  HEAP_XMAX_KEYSHR_LOCK)
 + strcat (flagString, XMAX_KEYSHR_LOCK|);
 if (infoMask  HEAP_COMBOCID)
   strcat (flagString, COMBOCID|);
 if (infoMask  HEAP_XMAX_EXCL_LOCK)
   strcat (flagString, XMAX_EXCL_LOCK|);
 !   if (infoMask  HEAP_XMAX_SHR_LOCK)
 ! strcat (flagString, XMAX_SHR_LOCK|);
 !   if (infoMask  HEAP_XMAX_LOCK_ONLY)
 ! strcat (flagString, XMAX_LOCK_ONLY|);
 if (infoMask  HEAP_XMIN_COMMITTED)
   strcat (flagString, XMIN_COMMITTED|);
 if (infoMask  HEAP_XMIN_INVALID)

Hm, note that XMAX_SHR_LOCK is two bits, so when that flag is present
you will get the three lock modes displayed with the above code, which is
probably going to be misleading.  htup_details.h does this:

/*
 * Use these to test whether a particular lock is applied to a tuple
 */
#define HEAP_XMAX_IS_SHR_LOCKED(infomask) \
(((infomask)  HEAP_LOCK_MASK) == HEAP_XMAX_SHR_LOCK)
#define HEAP_XMAX_IS_EXCL_LOCKED(infomask) \
(((infomask)  HEAP_LOCK_MASK) == HEAP_XMAX_EXCL_LOCK)
#define HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) \
(((infomask)  HEAP_LOCK_MASK) == HEAP_XMAX_KEYSHR_LOCK)

Presumably it'd be better to do something similar.

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers