summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartinko2013-02-12 07:37:04 +0000
committermartinko2013-02-12 07:37:04 +0000
commitd8bedca15dc52e84603dbdc455b020195cbf0f23 (patch)
tree9302f920091d467ffd9a2b28efe39412ec7e102b
parent73141259ea1530b6379e25c3a86f88d8b1b89674 (diff)
londiste: added --count-only to compare command
For quickly checking whether tables have same number of rows, without comparing tables' contents (data).
-rwxr-xr-xpython/londiste.py3
-rw-r--r--python/londiste/compare.py14
2 files changed, 14 insertions, 3 deletions
diff --git a/python/londiste.py b/python/londiste.py
index fb230f23..e95fa25d 100755
--- a/python/londiste.py
+++ b/python/londiste.py
@@ -154,6 +154,8 @@ class Londiste(skytools.DBScript):
help = "add: ignore table differences, repair: ignore lag")
g.add_option("--apply", action = "store_true",
help="repair: apply fixes automatically")
+ p.add_option("--count-only", action="store_true",
+ help="compare: just count rows, do not compare data")
p.add_option_group(g)
return p
@@ -161,4 +163,3 @@ class Londiste(skytools.DBScript):
if __name__ == '__main__':
script = Londiste(sys.argv[1:])
script.start()
-
diff --git a/python/londiste/compare.py b/python/londiste/compare.py
index a92ae513..83dac2e4 100644
--- a/python/londiste/compare.py
+++ b/python/londiste/compare.py
@@ -35,7 +35,9 @@ class Comparator(Syncer):
# get sane query
v1 = src_db.server_version
v2 = dst_db.server_version
- if v1 < 80300 or v2 < 80300:
+ if self.options.count_only:
+ q = "select count(1) as cnt from only _TABLE_"
+ elif v1 < 80300 or v2 < 80300:
# 8.2- does not have record to text and text to bit casts, so we need to use a bit of evil hackery
q = "select count(1) as cnt, sum(bit_in(textout('x'||substr(md5(textin(record_out(_COLS_))),1,16)), 0, 64)::bigint) as chksum from only _TABLE_"
elif (v1 < 80400 or v2 < 80400) and v1 != v2:
@@ -54,7 +56,9 @@ class Comparator(Syncer):
if dst_where:
dst_q = dst_q + " WHERE " + dst_where
- f = "%(cnt)d rows, checksum=%(chksum)s"
+ f = "%(cnt)d rows"
+ if not self.options.count_only:
+ f += ", checksum=%(chksum)s"
f = self.cf.get('compare_fmt', f)
self.log.debug("srcdb: " + src_q)
@@ -111,6 +115,12 @@ class Comparator(Syncer):
return common
+ def init_optparse(self, p=None):
+ """Initialize cmdline switches."""
+ p = super(Comparator, self).init_optparse(p)
+ p.add_option("--count-only", action="store_true", help="just count rows, do not compare data")
+ return p
+
if __name__ == '__main__':
script = Comparator(sys.argv[1:])
script.start()