def run_deploy(): args = Args() if not args.try_configure_connect_to_pg(): sys.exit(1) if not Pooler.is_superuser(): sys.stderr.write("ERROR: Bootstrap must be run by PostgreSQL superuser\n") sys.exit(1) try: for sql in CreateSchemaSQL.split(QuerySplit): if args.args.verbose: sys.stdout.write("\nExecuting query:\n{0}\n".format(sql)) Pooler.query(sql) except Exception as e: sys.stderr.write("Query:\n{0}\nerror: {1}\n".format(sql, e)) sys.exit(2) try: for sql in GrantsOnSchemaSQL.format( mamonsu_version.replace('.', '_'), args.args.mamonsu_username).split(QuerySplit): if args.args.verbose: sys.stdout.write("\nExecuting query:\n{0}\n".format(sql)) Pooler.query(sql) except Exception as e: sys.stderr.write("Query:\n{0}\nerror: {1}\n".format(sql, e)) sys.exit(2) sys.stdout.write("Bootstrap successfully completed\n")
def run_deploy(): args = Args() if not args.try_configure_connect_to_pg(): sys.exit(1) if not Pooler.is_superuser(): sys.stderr.write( "ERROR: Bootstrap must be run by PostgreSQL superuser\n") sys.exit(1) try: for sql in CreateSchemaSQL.format( mamonsu_version, mamonsu_version.replace('.', '_'), '[0-9A-F]{24}', 'wal' if Pooler.server_version_greater('10.0') else 'xlog', 'wal_lsn' if Pooler.server_version_greater('10.0') else 'xlog_location', 'waiting' if Pooler.server_version_less('9.6.0') else 'case when wait_event_type is null then false ' ' else true end as waiting' ).split(QuerySplit): if args.args.verbose: sys.stdout.write("\nExecuting query:\n{0}\n".format(sql)) Pooler.query(sql) except Exception as e: sys.stderr.write("Query:\n{0}\nerror: {1}\n".format(sql, e)) sys.exit(2) try: for sql in GrantsOnSchemaSQL.format( mamonsu_version.replace('.', '_'), args.args.mamonsu_username, 'wal' if Pooler.server_version_greater('10.0') else 'xlog' ).split(QuerySplit): if args.args.verbose: sys.stdout.write("\nExecuting query:\n{0}\n".format(sql)) Pooler.query(sql) except Exception as e: sys.stderr.write("Query:\n{0}\nerror: {1}\n".format(sql, e)) sys.exit(2) sys.stdout.write("Bootstrap successfully completed\n")
FROM list WHERE filename similar to '{2}' $$ LANGUAGE SQL SECURITY DEFINER; CREATE EXTENSION IF NOT EXISTS pg_buffercache; CREATE OR REPLACE FUNCTION public.mamonsu_buffer_cache() RETURNS TABLE(SIZE BIGINT, TWICE_USED BIGINT, DIRTY BIGINT) AS $$ SELECT SUM(1) * 8 * 1024, SUM(CASE WHEN usagecount > 1 THEN 1 ELSE 0 END) * 8 * 1024, SUM(CASE isdirty WHEN true THEN 1 ELSE 0 END) * 8 * 1024 FROM public.pg_buffercache $$ LANGUAGE SQL SECURITY DEFINER; """.format(mamonsu_version, mamonsu_version.replace('.', '_'), '[0-9A-F]{24}') GrantsOnSchemaSQL = """ ALTER TABLE public.mamonsu_config OWNER TO {1}; ALTER TABLE public.mamonsu_timestamp_master_{0} OWNER TO {1}; GRANT EXECUTE ON FUNCTION public.mamonsu_timestamp_master_update() TO {1}; GRANT EXECUTE ON FUNCTION public.mamonsu_timestamp_get() TO {1}; GRANT EXECUTE ON FUNCTION public.mamonsu_count_autovacuum() TO {1}; GRANT EXECUTE ON FUNCTION public.mamonsu_get_oldest_xid() TO {1}; GRANT EXECUTE ON FUNCTION public.mamonsu_get_oldest_query() TO {1};
FROM pg_catalog.pg_stat_activity WHERE query like '%%autovacuum%%' and state <> 'idle' and pid <> pg_catalog.pg_backend_pid() $$ LANGUAGE SQL SECURITY DEFINER; CREATE OR REPLACE FUNCTION public.mamonsu_count_xlog_files() RETURNS BIGINT AS $$ WITH list(filename) as (SELECT * FROM pg_catalog.pg_ls_dir('pg_xlog')) SELECT COUNT(*)::BIGINT FROM list WHERE filename similar to '{2}' $$ LANGUAGE SQL SECURITY DEFINER; CREATE EXTENSION IF NOT EXISTS pg_buffercache; CREATE OR REPLACE FUNCTION public.mamonsu_buffer_cache() RETURNS TABLE(SIZE BIGINT, TWICE_USED BIGINT, DIRTY BIGINT) AS $$ SELECT SUM(1) * 8 * 1024, SUM(CASE WHEN usagecount > 1 THEN 1 ELSE 0 END) * 8 * 1024, SUM(CASE isdirty WHEN true THEN 1 ELSE 0 END) * 8 * 1024 FROM public.pg_buffercache $$ LANGUAGE SQL SECURITY DEFINER; """.format( mamonsu_version, mamonsu_version.replace('.', '_'), '[0-9A-F]{24}')