def start(): 'Start the database in pg-latest' prefix.check_for_pg_latest() with cd(paths['pg-latest']): # "set -m" spawns postgres in a new process group so it runs in the background run('set -m; bin/pg_ctl -D data -l logfile start')
def run(self, *args): if self.before_run_hook: self.before_run_hook() prefix.check_for_pg_latest() # make sure we're pointed at a real instance utils.add_github_to_known_hosts() # make sure ssh doesn't prompt repo = self.repo_path_for_url(self.repo_url) if len(args) == 0: git_ref = self.default_git_ref else: git_ref = args[0] utils.rmdir(repo, force=True) # force because git write-protects files run('git clone -q {} {}'.format(self.repo_url, repo)) with cd(repo), path('{}/bin'.format(config.paths['pg-latest'])): run('git checkout {}'.format(git_ref)) run('make install') if self.post_install_hook: self.post_install_hook() utils.psql('CREATE EXTENSION {} CASCADE;'.format(self.extension_name))
def tpch(**kwargs): 'Generates and loads tpc-h data into the instance at pg-latest' prefix.check_for_pg_latest() psql = '{}/bin/psql'.format(config.paths['pg-latest']) connectionURI = kwargs.get('connectionURI', kwargs.get('connectionURI', '')) scale = kwargs.get('scale-factor', kwargs.get('scale_factor', 10)) partition_type = kwargs.get('partition-type', kwargs.get('partition_type', 'default')) # generate tpc-h data tpch_path = '{}/tpch_2_13_0'.format(config.paths['tests-repo']) with cd(tpch_path): run('make') run('SCALE_FACTOR={} CHUNKS="o 24 c 4 P 1 S 4 s 1" sh generate2.sh'.format(scale)) # clear old tables run('{} {} -f drop_tables.sql'.format(psql, connectionURI)) # create the tpc-h tables if partition_type == 'default': run('{} {} -f tpch_create_tables.ddl'.format(psql, connectionURI)) elif partition_type == 'hash': run('{} {} -f tpch_create_hash_partitioned_tables.ddl'.format(psql, connectionURI)) elif partition_type == 'append': run('{} {} -f tpch_create_append_partitioned_tables.ddl'.format(psql, connectionURI)) # stage tpc-h data for segment in run('find {} -name \'*.tbl*\''.format(tpch_path)).splitlines(): table_name = os.path.basename(segment).split('.')[0] run('''{} {} -c "\COPY {} FROM '{}' WITH DELIMITER '|'"'''.format(psql, connectionURI, table_name, segment)) run('{} {} -f warm_up_cache.sql'.format(psql, connectionURI))
def common_setup(build_citus_func): run('pkill postgres || true') prefix.check_for_pg_latest() # empty it but don't delete the link run('rm -r {}/ || true'.format(config.paths['pg-latest'])) redhat_install_packages() build_postgres() build_citus_func() create_database() pg.start() pg_latest = config.paths['pg-latest'] with cd(pg_latest): run('bin/createdb $(whoami)') utils.psql('CREATE EXTENSION citus;')
def common_setup(build_citus_func): with hide('stdout'): run('pkill postgres || true') prefix.check_for_pg_latest() # empty it but don't delete the link run('rm -r {}/ || true'.format(config.paths['pg-latest'])) redhat_install_packages() build_postgres() build_citus_func() create_database() pg.start() pg_latest = config.paths['pg-latest'] with cd(pg_latest): while getattr(run('bin/pg_isready'), 'return_code') != 0: print('Waiting for database to be ready') run('bin/createdb $(whoami)') with hide('stdout'): utils.psql('CREATE EXTENSION citus;')
def set_config_str(config): prefix.check_for_pg_latest() psql('ALTER SYSTEM SET {}'.format(config))
def set_config(key, value): 'Changes the postgres configuration: e.g. `fab pg.set_config:max_connections,200`' prefix.check_for_pg_latest() psql('ALTER SYSTEM SET {} TO {}'.format(key, value))
def read_config(key): 'Returns the present value of the requested key e.x `fab pg.read_config:max_connections`' prefix.check_for_pg_latest() psql('SHOW {}'.format(key))
def restart(): 'Restart the database in pg-latest' prefix.check_for_pg_latest() with cd(paths['pg-latest']): run('set -m; bin/pg_ctl -D data -l logfile restart')
def stop(): 'Stop the database in pg-latest' prefix.check_for_pg_latest() with cd(paths['pg-latest']): run('set -m; bin/pg_ctl -D data stop')