提交 b6bfe266 编写于 作者: M Melanie Plageman 提交者: Melanie

Remove gpbitmapreindex

* Removing deprecated utility. This was utility was used in 3.3 -> 4.0
  upgrade partition.
Signed-off-by: NMarbin Tan <mtan@pivotal.io>
上级 9044351d
......@@ -810,7 +810,6 @@ pvk : gccVersionCheck version GPROOTDEP
SET_VERSION_SCRIPTS = \
bin/gpactivatestandby \
bin/gpaddmirrors \
bin/gpbitmapreindex \
bin/gpcheckperf \
bin/gpcrondump \
bin/gpdbrestore \
......
......@@ -9,7 +9,6 @@ include $(top_builddir)/gpMgmt/Makefile.behave
SET_VERSION_SCRIPTS = \
bin/gpactivatestandby \
bin/gpaddmirrors \
bin/gpbitmapreindex \
bin/gpcheckperf \
bin/gpcrondump \
bin/gpdbrestore \
......
#!/usr/bin/env python
#
# Copyright (c) Greenplum Inc 2008. All Rights Reserved.
#
try:
import signal
import sys
from optparse import OptionGroup
from gppylib.gpparseopts import OptParser, OptChecker
from gppylib.gplog import *
from gppylib.db import dbconn
from gppylib.db import catalog
from gppylib.commands.unix import *
from gppylib.commands.base import *
from gppylib.userinput import *
from pygresql.pg import DatabaseError
except ImportError, e:
sys.exit('ERROR: Cannot import modules. Please check ' \
'that you have sourced greenplum_path.sh. Detail: ' + str(e))
_description = ("""Reindexes all bitmap indexes in a Greenplum Database.""")
_help = ['']
EXECNAME = os.path.split(__file__)[-1]
MAX_PARALLEL_REINDEX=16
GET_BITMAP_INDEXES_SQL="""
SELECT pg_class.oid, relname
FROM pg_class, pg_am
WHERE pg_class.relam = pg_am.oid
AND pg_am.amname = 'bitmap'
"""
GET_BITMAP_INDEX_DEF_SQL="""
SELECT pg_get_indexdef(%s)
"""
REINDEX_SQL="""
REINDEX INDEX "%s"
"""
DROP_INDEX_SQL="""
DROP INDEX "%s"
"""
class DropIndexCommand(SQLCommand):
"""This command issues a DROP INDEX SQL statement to a Greenplum database."""
def __init__(self,name,hostname, port, db_name, idx_name):
self.db_name = db_name
self.idx_name = idx_name
self.hostname = hostname
self.port = port
# The cmdStr isn't actually used except for logging in this class
self.cmdStr = DROP_INDEX_SQL % idx_name
SQLCommand.__init__(self,name)
pass
def run(self,validateAfter=False):
dburl = dbconn.DbURL(hostname=self.hostname, port=self.port,
dbname=self.db_name)
try:
conn = dbconn.connect(dburl)
# Have to set this so SQLCommand can cancel if needed.
self.cancel_conn = conn
except DatabaseError, ex:
logger.error('Failed to connect to database %s' % self.db_name)
if options.verbose:
logger.exception(ex)
logger.error('Drop of index %s in database %s failed' % (self.idx_name, self.db_name))
return
try:
logger.info('Dropping index %s in database %s...' %
(self.idx_name, self.db_name))
# do the actual reindex
dbconn.execSQL(conn, DROP_INDEX_SQL % self.idx_name)
conn.commit()
except Exception, ex:
logger.error('Failed to drop index %s in database %s' %
(self.idx_name, self.db_name))
finally:
conn.close()
class ReindexCommand(SQLCommand):
"""This command issues a REINDEX SQL statement to a Greenplum database."""
def __init__(self,name,hostname, port, db_name, idx_name):
self.db_name = db_name
self.idx_name = idx_name
self.hostname = hostname
self.port = port
# The cmdStr isn't actually used except for logging in this class
self.cmdStr = REINDEX_SQL % idx_name
SQLCommand.__init__(self,name)
pass
def run(self,validateAfter=False):
dburl = dbconn.DbURL(hostname=self.hostname, port=self.port,
dbname=self.db_name)
try:
conn = dbconn.connect(dburl)
# Have to set this so SQLCommand can cancel if needed.
self.cancel_conn = conn
except DatabaseError, ex:
logger.error('Failed to connect to database %s' % self.db_name)
if options.verbose:
logger.exception(ex)
logger.error('Reindex of %s in database %s failed' % (self.idx_name, self.db_name))
return
try:
logger.info('Reindexing %s in database %s...' %
(self.idx_name, self.db_name))
# do the actual reindex
dbconn.execSQL(conn, REINDEX_SQL % self.idx_name)
conn.commit()
except Exception, ex:
logger.error('Failed to reindex %s in database %s' %
(self.idx_name, self.db_name))
finally:
conn.close()
def parseargs():
"""Parses command line options and validates them."""
parser = OptParser(option_class=OptChecker,
description=' '.join(_description.split()),
version='%prog version $Revision$')
parser.setHelp(_help)
parser.remove_option('-h')
optgrp = OptionGroup(parser, 'Database Options')
optgrp.add_option('-h', '--hostname', type='string', default='localhost',
help='Master hostname.')
optgrp.add_option('-p', '--port', type='int', default='0',
help='Master port.')
parser.add_option_group(optgrp)
optgrp = OptionGroup(parser, 'Concurrency Options')
optgrp.add_option('-n', '--parallel', type="int", default=1,
metavar="<parallel_processes>",
help='number of bitmap indexes to re-index at a time. ' \
'Valid values are 1-%d. (Default: 1)' % MAX_PARALLEL_REINDEX)
parser.add_option_group(optgrp)
optgrp = OptionGroup(parser, 'Mode Options')
optgrp.add_option('-m', '--mode', type='choice', choices=['d','drop','r','reindex', 'l', 'list'],
help='Mode of operation. Can be either r[eindex], d[rop] or l[ist]. '
'\'list\' can be used with --outfile to dump the CREATE INDEX sql file')
parser.add_option_group(optgrp)
optgrp = OptionGroup(parser, 'Logging Options')
optgrp.add_option('-o', '--outfile', type='string', metavar='<outfile>',
help='Create a sql file containing the CREATE INDEX sql of all bitmap indexes.'
'These statements will be written as the indexes are dropped or reindexed.')
optgrp.add_option('-v','--verbose', action='store_true', help='Debug output.')
parser.add_option_group(optgrp)
optgrp = OptionGroup(parser, 'Help Options')
optgrp.add_option('-?', '--help', action='store_true',
help='Display this message and exit.')
parser.add_option_group(optgrp)
parser.set_defaults(hostname=None, port=0, verbose=False, mode='reindex',
filters=[], slice=(None, None))
# Parse the command line arguments
(options, args) = parser.parse_args()
if options.help:
parser.print_help()
parser.exit(0)
# validate the options
if options.parallel < 1 or options.parallel > MAX_PARALLEL_REINDEX:
logger.error('Invalid -n option given. Value must be from 1 to 16.')
parser.exit(1)
if options.port >= 65535:
logger.error('Invalid port given. Value must be less than 65535.')
parser.exit(1)
if options.mode not in ['d', 'drop', 'r', 'reindex', 'l', 'list']:
logger.error('Invalid mode option. Must be either \'drop\', \'reindex\', or \'list\'.')
parser.exit(1)
if options.mode == 'drop' or options.mode == 'd':
logger.warn('The drop mode of operation will drop all bitmap indexes that exist.')
logger.warn('This is not a recoverable operation. You will need to recreate all')
logger.warn('bitmap indexes if you want to restore them.')
yn = ask_yesno('', "Are you sure you want to drop all bitmap indexes?",'N')
if not yn:
logger.info('Operation canceled by user.')
parser.exit(1)
return options, args
def get_bitmap_indexes(options):
"""Gets a list of all bitmap indexes on the system"""
bitmap_indexes = []
dburl = dbconn.DbURL(hostname=options.hostname,port=options.port)
conn = dbconn.connect(dburl)
try:
# note: catalog.getUserDatabaseList returns an array of arrays of len 1.
# That should probably be fixed at some point...
databases = catalog.getUserDatabaseList(conn)
conn.close()
for db in databases:
logger.info('Retrieving bitmap indexes from database %s...' % db[0])
dburl = dbconn.DbURL(hostname=options.hostname,
port=options.port,dbname=db[0])
conn = dbconn.connect(dburl)
cur = dbconn.execSQL(conn, GET_BITMAP_INDEXES_SQL)
for idx in cur:
logger.debug('Adding bitmap index %s from database %s' %
(idx[0], db[0]))
bitmap_indexes.append((db[0], idx[0], idx[1]))
conn.close()
except:
raise
return bitmap_indexes
def get_bitmap_index_def(options, db_name, oid):
conn = None
try:
dburl = dbconn.DbURL(hostname=options.hostname, port=options.port, dbname=db_name)
conn = dbconn.connect(dburl)
index_def = dbconn.execSQL(conn, GET_BITMAP_INDEX_DEF_SQL % oid).fetchall()
if len(index_def) == 1:
return index_def[0][0]
else:
return None
except:
pass
finally:
if conn:
conn.close()
def update_bitmap_indexes(options, bitmap_indexes):
"""Creates a worker pool and adds a command for every index
that needs to be reindexed or dropped."""
pool = WorkerPool(numWorkers=options.parallel)
fp = None
dburl = dbconn.DbURL(hostname=options.hostname, port=options.port)
try:
if options.outfile:
fp = open(options.outfile, 'w')
for (db_name, idx_oid, idx_name) in bitmap_indexes:
logger.debug('Adding reindex command for %s in database %s to pool.' %
(idx_name, db_name))
if options.outfile:
index_def = get_bitmap_index_def(options, db_name, idx_oid)
if index_def:
fp.write("\\c %s;\n" % db_name)
fp.write("%s;\n\n" % index_def)
if options.mode == 'reindex' or options.mode == 'r':
cmd = ReindexCommand('Reindex %s' % idx_name, dburl.pghost,
dburl.pgport, db_name, idx_name)
pool.addCommand(cmd)
elif options.mode == 'drop' or options.mode == 'd':
cmd = DropIndexCommand('Drop Index %s' % idx_name, dburl.pghost,
dburl.pgport, db_name, idx_name)
pool.addCommand(cmd)
elif options.mode == 'list' or options.mode == 'l':
logger.info('Bitmap index: %s.%s' % (db_name, idx_name))
else:
# just a safety check, but this should have been caught in the
# option parser.
logger.error('Invalid mode. Exiting...')
sys.exit(1)
except Exception, ex:
pool.haltWork()
pool.joinWorkers()
raise ex
logger.info('Waiting for workers to finish...')
try:
# Sit in a loop waiting for cancel or completion
while not pool.isDone():
time.sleep(.5)
except KeyboardInterrupt:
logger.info('User canceled')
pool.haltWork()
try:
# We are done
pool.haltWork()
pool.joinWorkers()
except:
# Ok to ignore this, we are done.
pass
if fp:
fp.close()
logger = get_default_logger()
setup_tool_logging(EXECNAME,getLocalHostname(),getUserName())
options, args = parseargs()
try:
if options.verbose:
enable_verbose_logging()
bitmap_indexes = get_bitmap_indexes(options)
update_bitmap_indexes(options, bitmap_indexes)
logger.info('Done.')
except Exception, ex:
logger.error('There was an error during reindexing: %s' % ex.__str__())
if options.verbose:
logger.exception(ex)
finally:
pass
\ No newline at end of file
COMMAND NAME: gpbitmapreindex
Rebuilds bitmap indexes after a 3.3.x to 4.0.x upgrade.
*****************************************************
SYNOPSIS
*****************************************************
gpbitmapreindex -m { r | d | {l [-o <output_sql_file>]} }
[-h <master_host>] [-p <master_port>]
[-n <number_of_processes>] [-v]
*****************************************************
DESCRIPTION
*****************************************************
The on-disk format of bitmap indexes has changed from release
3.3.x to 4.0.x. Users who upgrade must rebuild all bitmap indexes
after upgrading to 4.0. The gpbitmapreindex utility facilitates the
upgrade of bitmap indexes by either running the REINDEX command to
reindex them, or running the DROP INDEX command to simply remove them.
If you decide to drop your bitmap indexes rather than reindex,
run gpbitmapreindex in list --outfile mode first to output a SQL file
that you can use to recreate the indexes later. You must be the
Greenplum Database superuser (gpadmin) in order to run gpbitmapreindex.
*****************************************************
OPTIONS
*****************************************************
-h <host> | --host <host>
Specifies the host name of the machine on which the Greenplum
master database server is running. If not specified, reads from
the environment variable PGHOST or defaults to localhost.
-m {r|d|l} | --mode {reindex|drop|list}
Required. The bitmap index upgrade mode: either reindex, drop,
or list all bitmap indexes in the system.
-n <number_of_processes> | --parallel <number_of_processes>
The number of bitmap indexes to reindex or drop in parallel.
Valid values are 1-16. The default is 1.
-o <output_sql_file> | --outfile <output_sql_file>
When used with list mode, outputs a SQL file that can be
used to recreate the bitmap indexes.
-p <port> | --port <port>
Specifies the TCP port on which the Greenplum master database
server is listening for connections. If not specified, reads from
the environment variable PGPORT or defaults to 5432.
-v | --verbose
Show verbose output.
--version
Displays the version of this utility.
-? | --help
Displays the online help.
*****************************************************
EXAMPLES
*****************************************************
Reindex all bitmap indexes:
gpbitmapreindex -m r
Output a file of SQL commands that can be used to recreate all
bitmap indexes:
gpbitmapreindex -m list --outfile /home/gpadmin/bmp_ix.sql
Drop all bitmap indexes and run in verbose mode:
gpbitmapreindex -m d -v
*****************************************************
SEE ALSO
*****************************************************
REINDEX, DROP INDEX, CREATE INDEX
......@@ -71,7 +71,6 @@
<topicref href="utility_guide/admin_utilities/analyzedb.xml"/>
<topicref href="utility_guide/admin_utilities/gpactivatestandby.xml"/>
<topicref href="utility_guide/admin_utilities/gpaddmirrors.xml"/>
<topicref href="utility_guide/admin_utilities/gpbitmapreindex.xml"/>
<topicref href="utility_guide/admin_utilities/gpcheck.xml"/>
<topicref href="utility_guide/admin_utilities/gpcheckcat.xml"/>
<topicref href="utility_guide/admin_utilities/gpcheckperf.xml"/>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1"><title id="oq141610">gpbitmapreindex</title><body><p>Rebuilds bitmap indexes after a 3.3.x to 4.0.x upgrade.</p><section id="section2"><title>Synopsis</title><codeblock><b>gpbitmapreindex</b> <b>-m</b> { <b>r</b> | <b>d</b> | {<b>l</b> [<b>-o</b> <varname>output_sql_file</varname>]} }
[<b>-h</b> <varname>master_host</varname>] [<b>-p</b> <varname>master_port</varname>] [<b>-n</b> <varname>number_of_processes</varname>] [<b>-v</b>]
</codeblock></section><section id="section3"><title>Description</title><p>The on-disk format of bitmap indexes has changed from release 3.3.x to 4.0.x. Users who upgrade
must rebuild all bitmap indexes after upgrading to 4.0. The <codeph>gpbitmapreindex</codeph>
utility facilitates the upgrade of bitmap indexes by either running the
<codeph>REINDEX</codeph> command to reindex them, or running the <codeph>DROP
INDEX</codeph> command to simply remove them. If you decide to drop your bitmap indexes
rather than reindex, run <codeph>gpbitmapreindex</codeph> in <codeph>list --outfile</codeph>
mode first to output a SQL file that you can use to recreate the indexes later. You must be
the Greenplum Database superuser (<codeph>gpadmin</codeph>) in order to run
<codeph>gpbitmapreindex</codeph>.</p></section><section id="section4"><title>Options</title><parml><plentry><pt>-h <varname>host</varname> | --<varname>hosthost</varname></pt><pd>Specifies the host name of the machine on which the Greenplum master
database server is running. If not specified, reads from the environment
variable <codeph>PGHOST</codeph> or defaults to <codeph>localhost</codeph>.</pd></plentry><plentry><pt>-m {r|d|l} | --mode {reindex|drop|list}</pt><pd>Required. The bitmap index upgrade mode: either <codeph>reindex</codeph>,
<codeph>drop</codeph>, or <codeph>list</codeph> all bitmap indexes in
the system.</pd></plentry><plentry><pt>-n <varname>number_of_processes</varname> | --parallel <varname>number_of_processes</varname></pt><pd>The number of bitmap indexes to reindex or drop in parallel. Valid
values are 1-16. The default is 1.</pd></plentry><plentry><pt>-o <varname>output_sql_file</varname> | --outfile <varname>output_sql_file</varname></pt><pd>When used with <codeph>list</codeph> mode, outputs a SQL file that
can be used to recreate the bitmap indexes.</pd></plentry><plentry><pt>-p <varname>port</varname> | --port <varname>port</varname></pt><pd>Specifies the TCP port on which the Greenplum master database server
is listening for connections. If not specified, reads from the environment
variable <codeph>PGPORT</codeph> or defaults to 5432.</pd></plentry><plentry><pt>-v | --verbose</pt><pd>Show verbose output.</pd></plentry><plentry><pt>--version</pt><pd>Displays the version of this utility. </pd></plentry><plentry><pt>-? | --help</pt><pd>Displays the online help.</pd></plentry></parml></section><section id="section5"><title>Examples</title><p>Reindex all bitmap indexes:</p><codeblock>gpbitmapreindex -m r</codeblock><p>Output a file of SQL commands that can be used to recreate all bitmap
indexes:</p><codeblock>gpbitmapreindex -m list --outfile /home/gpadmin/bmp_ix.sql</codeblock><p>Drop all bitmap indexes and run in verbose mode:</p><codeblock>gpbitmapreindex -m d -v</codeblock></section><section id="section6"><title>See Also</title><p><i>Greenplum Database Reference Guide</i>: <codeph>REINDEX</codeph>,<codeph> DROP
INDEX</codeph>,<codeph> CREATE INDEX</codeph></p></section></body></topic>
......@@ -27,9 +27,6 @@
<p>
<xref href="gpaddmirrors.xml#topic1" type="topic" format="dita"/>
</p>
<p>
<xref href="gpbitmapreindex.xml#topic1"/>
</p>
<p>
<xref href="gpcheck.xml#topic1" type="topic" format="dita"/> (deprecated)</p>
<p>
......
......@@ -6,7 +6,6 @@
<topicref href="admin_utilities/analyzedb.xml"/>
<topicref href="admin_utilities/gpactivatestandby.xml"/>
<topicref href="admin_utilities/gpaddmirrors.xml"/>
<topicref href="admin_utilities/gpbitmapreindex.xml"/>
<topicref href="admin_utilities/gpcheck.xml"/>
<topicref href="admin_utilities/gpcheckcat.xml"/>
<topicref href="admin_utilities/gpcheckperf.xml"/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册