[HACKERS] [PATCH] Add --ordered option to pg_dump

2010-04-15 Thread Bob Lunney
I needed a way to run diffs on two
database dumps to see what data developers put in their
local databases versus the initial database load.  The
pg_dump utility with --inserts works well for this, but
since the order in which the data is returned of the server
is not guaranteed I hacked this patch to make life
simpler.  

Using --ordered will order the data by primary key or
unique index, if one exists, and use the smallest ordering
(i.e. least number of columns required for a unique
order).  

Note that --ordered could crush your database server if you
try to order very large tables, so use judiciously.

This is my first patch submission, so I hope I've followed
protocol.  If not, please be gentle!

Regards,

Bob Lunney
bob_lunney dot yahoo dot com


diff -cNr src/bin/pg_dump/pg_dump.c.orig
src/bin/pg_dump/pg_dump.c
*** src/bin/pg_dump/pg_dump.c.orig      2010-04-06
11:21:48.0 -0400                       
            
--- src/bin/pg_dump/pg_dump.c   2010-04-15
10:28:49.0 -0400                       
                    
***                             
                                       
                          
*** 111,116                            
                                       
                           
--- 111,117                            
                                       
                           
  static int    disable_dollar_quoting = 0;       
                                       
                    
  static int    dump_inserts = 0;               
                                       
                      
  static int    column_inserts = 0;             
                                       
                      
+ static int      ordered = 0;                 
                                       
                       
                                       
                                       
                               
                                       
                                       
                               
  static void help(const char *progname);           
                                       
                  
***                             
                                       
                          
*** 275,280                            
                                       
                           
--- 276,282                            
                                       
                           
                {inserts, no_argument,
dump_inserts, 1},                         
                          
                {lock-wait-timeout,
required_argument, NULL, 2},                     
                       
                {no-tablespaces, no_argument,
outputNoTablespaces, 1},                   
                  
+               {ordered, no_argument,
ordered, 1},                           
                             
                {role, required_argument, NULL,
3},                                     
                    
                {use-set-session-authorization,
no_argument, use_setsessauth, 1},             
             
                                       
                                       
                               
***                             
                                       
                          
*** 493,498                            
                                       
                           
--- 495,506                            
                                       
                           
                exit(1);                 
                                       
                             
        }                             
                                       
                                
                                       
                                       
                               
+       if (!dump_inserts  ordered)     
                                       
                            
+       {                             
                                       
                                
+               write_msg(NULL, option --ordered
cannot be used without --inserts or --column_inserts\n); 
  
+               exit(1);                 
                                       
                             
+       }                             
                                       
                                
+                                     
                                       
                                
        /* open the output file */             
                                       
                       
        if (pg_strcasecmp(format, a) == 0 ||
pg_strcasecmp(format, append) == 0)               
           
        {
***
*** 822,827 
--- 830,836 
        printf(_(  --disable-dollar-quoting   
disable dollar quoting, use SQL standard quoting\n

Re: [HACKERS] [PATCH] Add --ordered option to pg_dump

2010-04-15 Thread Bob Lunney
Thanks for the suggestion, Peter.  It looks like pg_comparator is for comparing 
the contents of two different servers.  I need to compare the contents of two 
dump files from the same server separated by time and busy developers.

Regards,

Bob Lunney

--- On Thu, 4/15/10, Peter Eisentraut pete...@gmx.net wrote:

 From: Peter Eisentraut pete...@gmx.net
 Subject: Re: [HACKERS] [PATCH] Add --ordered option to pg_dump
 To: Bob Lunney bob_lun...@yahoo.com
 Cc: pgsql-hackers@postgresql.org
 Date: Thursday, April 15, 2010, 4:36 PM
 On tor, 2010-04-15 at 10:48 -0700,
 Bob Lunney wrote:
  I needed a way to run diffs on two
  database dumps to see what data developers put in
 their
  local databases versus the initial database load.
 
 Maybe pg_comparator would help you?
 
 
 -- 
 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
 To make changes to your subscription:
 http://www.postgresql.org/mailpref/pgsql-hackers
 


  

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