How to use Shell scripts in Linux to maintain Oracle

Source: Internet
Author: User
Tags how to use sql
The roles and responsibilities of system administrators and DBAs are different. But in fact, this difference is usually not obvious. Many IT departments employ databases and operating systems.

The roles and responsibilities of system administrators and DBAs are different. But in fact, this difference is usually not obvious. Many IT departments employ employees who can solve database-level and operating system-level problems. Of course, Oracle databases use operating system resources and can closely interact with their environments.

In addition, many system administrators and DBAs find it necessary or convenient to automate jobs related to their work. Software installation, system resource monitoring, and system management involve repetitive and error-prone tasks, and the automatic process can accomplish these tasks better than the manual process.

One of the ways to automate these tasks is shell scripts. Shell scripts play an important role since the beginning of Linux system installation. Various scripts are called when the system is started or shut down. Utilities from Oracle and other third-party vendors can also be called through shell scripts. Since these scripts can be developed quickly, they have always been used to build application prototypes. The system administrator has used the functions implemented by shell scripts to provide a solution tailored to the specific requirements and features of the system to be monitored.

In this article, I will introduce the functions that can be implemented by the "bash" shell script and related to installing, running, and maintaining the Oracle database on the Linux platform. Note: This article is applicable to beginners of Linux scripts or DBAs who are unfamiliar with Linux. it is not applicable to most experienced Linux system administrators.

◆ What is a Shell script?

Shell scripts are text files that contain command sequences. When a file (or script) is run, the commands contained in the file are executed. The term shell only refers to the specific command line user interface used to communicate with the Linux kernel. There are currently multiple different shells, including C shell (csh), Korn shell (ksh), Bourne shell (sh), and Bourne-Again shell (bash ). Shell itself is a command used to read, interpret, and normally execute other commands from a file or terminal. Bourne-Again shell combines the features of the above other shells. this script is used for demonstration in this article.

The first line in the script file can be used to specify the shell used to run the script. The following is the meaning of the first line in all script examples:

#! /Bin/bash

◆ Why use Shell scripts?

Because shell scripts are related to DBA work, you may not immediately see the value of shell scripts, which is related to your work experience. If you have never used UNIX or UNIX-like systems before, you may be confused about a large number of obscure commands. In addition to relational databases, Oracle 10 GB also provides a robust platform for processing database data and several methods for interacting with the operating system outside the database.

However, you will find several reasons to explore the shell script field, including:

• Existing scripts must be supported.

• The system needs to be automatically set up before the Oracle software is installed. For example, you can write a script to check the initial state of the OS and report any prerequisites that must be met before installing the software. This script can also create related OS users and groups and set environment variables for users.

• You can use a running Oracle database to execute manual or scheduled tasks. However, some tasks need to be run when the database is not running. You can use scripts to stop or start databases (as well as listeners or related database processes ). Unable to start such actions from the database.

• You need a mechanism to monitor the database status (for example, whether a process is running and can be queried. Such scripts can also monitor other processes and resources that are not specific to Oracle, so as to provide more detailed information about the current running status of the system.

• Automatic backup is required. Oracle Recovery Manager (RMAN) is a utility used to develop backup scripts that can run on any platform. You can call Oracle Recovery Manager from shell scripts and use it to perform various backup and Recovery activities.

• You may have a requirement that is not specific to a database. You may have installed multiple databases on one computer. We recommend that you do not use a single database to meet this requirement, because this will lead to potential security problems. In these cases, shell scripts provide a method that can meet this requirement and does not associate processes with a single database.

◆ Under what circumstances do I not use Shell scripts?

Oracle databases include functions beyond the traditional definition of RDBMS. Like any other part of the software, it uses the resources provided by the operating system, but it "sees" and "changes" its environment much more than other software. The fixed views of SQL and Oracle provide the system view from inside the database, while shell scripts provide the system view from outside the database. Shell scripts are not a solution for all problems.

We must be aware that many aspects of the operating system can be monitored and modified from within the database. You can use the fixed view (with a v $ prefix) of Oracle to determine the host name (v $ instance) of the computer or the name of the platform where the database is running (v $ database ). You can also determine the location and other attributes of database-related files in this way. You can directly query data files (v $ datafile, dba_data_files), temporary files (v $ tempfile, dba_temp_files), and redo logs (v $ logfile) from the database) location and other attributes of the archived log (v $ archived_log) and control File (v $ controlfile. You can use this view and view some init. ora parameters (db_recovery_file_dest, db_recovery_file_dest_size) to determine information about the flash recovery zone ($ recovery_file_dest. You can also query the status of processes (v $ process) and memory (v $ sga, v $ sgastat, etc. There are various built-in PL/SQL packages and the ability to create Java and C database objects that allow other accesses to the underlying OS.

If you are considering writing a script for a task that requires a large number of database access, the script may not be the best choice. Later in this article, we will introduce how to use SQL * Plus to access the database, but in many cases, using other languages can better solve this problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.