Exemple #1
0
    def check_connection_params(self):
        # Check whether the binary files of the database can be located through environment variables.
        try:
            self.exec_command_on_host("which gsql")
            self.exec_command_on_host("which gaussdb")
            self.exec_command_on_host("which gs_guc")
            self.exec_command_on_host("which gs_ctl")
        except ExecutionError as e:
            logging.exception("An exception occurred while checking connection parameters: %s", e)
            raise OptionError("The parameters about SSH login user are incorrect. Please check.\n"
                              "Hint: The binary file path of the database cannot be obtained after the login."
                              "Please ensure that the paths of tools such as gsql and gs_ctl are added to environment "
                              "variables ($PATH).") from None

        # Check whether the third-party libraries can be properly loaded.
        try:
            self.exec_command_on_host("gaussdb --version")
            self.exec_command_on_host("gsql --version")
        except ExecutionError as e:
            logging.exception("An exception occurred while checking connection parameters: %s", e)
            raise DBStatusError("The database environment is incorrectly configured. "
                                "login to the database host as the user and check whether "
                                "the database environment can be used properly. "
                                "For example, check environment variables $LD_LIBRARY_PATH.") from None

        # Check whether the database is started.
        # And check whether the user name and password are correct.
        try:
            if not self.is_alive():
                raise DBStatusError("Failed to login to the database. "
                                    "Check whether the database is started. ")

            # Get database instance pid and data_path.
            _, self.data_path = self.exec_statement(
                "SELECT datapath FROM pg_node_env;"
            )
        except ExecutionError as e:
            logging.exception("An exception occurred while checking connection parameters: %s", e)
            raise DBStatusError("Failed to login to the database. "
                                "Check whether the user name or password is correct, "
                                "and whether the database information passed to the X-Tuner is correct.") from None

        # Check whether the current user has sufficient permission to perform tuning.
        try:
            self.exec_statement("select * from pg_user;")
        except ExecutionError as e:
            logging.exception("An exception occurred while checking connection parameters: %s", e)
            raise DBStatusError("The current database user may not have the permission to tune best_knobs. "
                                "Please assign the administrator permission temporarily so that you can "
                                "obtain more information from the database.") from None
Exemple #2
0
    def restart(self):
        logging.info(construct_header("Restarting database.", padding="*"))
        self.exec_statement("checkpoint;")  # Prevent the database from being shut down for a long time.
        self.exec_command_on_host("gs_ctl stop -D {data_path}".format(data_path=self.data_path),
                                  ignore_status_code=True)
        self.exec_command_on_host("gs_ctl start -D {data_path}".format(data_path=self.data_path),
                                  ignore_status_code=True)

        if self.is_alive():
            logging.info("The database restarted successfully.")
        else:
            logging.fatal("The database restarted failed.")
            raise DBStatusError("The database restarted failed.")

        logging.info(construct_header())
    def restart(self):
        logging.info(
            construct_dividing_line("Restarting database.", padding="*"))
        try:
            self.exec_statement(
                "checkpoint;"
            )  # Prevent the database from being shut down for a long time.
        except ExecutionError:
            logging.warning(
                "Cannot checkpoint perhaps due to bad GUC settings.")
        self.exec_command_on_host(
            "gs_ctl stop -D {data_path}".format(data_path=self.data_path),
            ignore_status_code=True)
        self.exec_command_on_host(
            "gs_ctl start -D {data_path}".format(data_path=self.data_path),
            ignore_status_code=True)

        if self.is_alive():
            logging.info("The database restarted successfully.")
        else:
            logging.fatal("The database restarted failed.")
            raise DBStatusError("The database restarted failed.")

        logging.info(construct_dividing_line())