Oracle 實用技巧

來源:互聯網
上載者:User

標籤:des   http   io   ar   os   使用   sp   for   strong   

一、rlwrap在 linux中使用sqlplus對資料庫進行操作,常常由於敲錯命令或需要反覆執行某條語句,需要像linux本身有的曆史回調的功能, rlwrap 可以用來支援oracle下sqlplus曆史命令的回調功能,提高操作效率。  1、下載http://utopia.knoware.nl/~hlub/uck/rlwrap/#rlwrap目前最新版本 rlwrap-0.42.tar.gz (274 k)  2、上傳到linux伺服器上使用各類檔案傳輸工具將壓縮包上傳到伺服器,如xmanager的xftp工具  3、解壓縮[[email protected] ~]# tar -zxvf rlwrap-0.42.tar.gz   4、安裝解壓後會產生一個 rlwrap-0.42 檔案夾,運行檔案夾中的configure檔案進行安裝[[email protected] rlwrap-0.42]# ./configure[[email protected] rlwrap-0.42]#make[[email protected] rlwrap-0.42]#make install  5、安裝rlwrap錯誤問題的解決 【You need the GNU readline library(ftp://ftp.gnu.org/gnu/readline/ ) to build this program.】 如果安裝rlwrap的時候出現上述問題,那麼你可能缺失兩個包:  libtermcap-devel- 2.0.8-46.1.i386.rpm readline-devel-5.1-1.1.i386.rpm 需要在系統光碟片或或鏡像檔案中使用rpm進行安裝缺失的軟體包後再執行 rlwrap工具的安裝  6、驗證安裝的結果切換到oracle使用者使用rlwrap方式登陸到資料庫進行測試[[email protected] ~]# su - oracle[[email protected] ~]$  rlwrap sqlplus / as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 5 10:51:22 2014
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>select status from v$instance;SQL>select * from v$version; 在執行完語句後能使用上下箭頭進行指令的回調,並且可以使用backspace退格鍵進行刪除,大大提高了效率  7、寫入設定檔,方便使用[[email protected] ~]$  vi .bashrc  # User specific aliases and functions alias sqlplus=‘rlwrap sqlplus‘
alias rman=‘rlwrap rman‘
alias adrci=‘rlwrap adrci‘

[[email protected] ~]$ source .bashrc 這樣就能在sqlplus下也能有linux系統的查看曆史命令的功能了     二、glogin.sql檔案

oracle資料庫安裝好之後,預設在$ORACLE_HOME下面的sqlplus/admin/目錄裡面會有glogin.sql設定檔

這是一個全域的並且會自動啟動並執行設定檔,在用戶端使用sqlplus的時候會自動調用這個檔案。

因此我們可以在glogin.sql檔案裡面加入我們經常使用的一些設定,比如要設定登入的使用者和執行個體等。  1、設定在登陸sqlplus後顯示使用者名稱和執行個體名在預設登陸到sqlplus後,只會顯示一個SQL>作為的提示符,這樣就需要通過指令來查詢登陸的使用者和執行個體名稱【尤其是在需要切換到不同資料庫時,容易造成誤操作】 在glogin.sql檔案中加入下列語句來實現使用者名稱和執行個體名的顯示  set sqlprompt "_user‘@‘_connect_identifier> "  然後再登陸到sqlplus環境中,這樣提示符就會變成對應的結果[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 5 11:37:23 2014
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[email protected]>   2、設定頁面的長寬顯示比例在進行系統維護時,由於部分列名過長,導致查詢出來的結果往往顯示十分雜亂,不便於查看,這時就需要對頁面進行設定 在glogin.sql檔案中加入兩個設定 set linesize 200 set pagesize 9999設定的值可根據頁面的大小修改到合適的結果顯示 [email protected]>  set linesize 40
[email protected]> select * from v$version;
BANNER
----------------------------------------
Oracle Database 11g Enterprise Edition R
elease 11.2.0.1.0 - 64bit Production

PL/SQL Release 11.2.0.1.0 - Production
CORE     11.2.0.1.0     Production
TNS for Linux: Version 11.2.0.1.0 - Prod
uction

NLSRTL Version 11.2.0.1.0 - Production

[email protected]>  set linesize 200
[email protected]> /

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE     11.2.0.1.0     Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
  3、其他一些常見的設定項  set serveroutput on  --設定預設開啟dbms_output的輸出 define _editor=/usr/local/bin/vim --定義使用的編輯器【定義編輯器為vim,windows平台可設定為notepad】 column object_name format a30  --設定object_name的列長尾30【字元列使用a+數字來表示長度】 column object_id format 999999   --設定object_id列長尾6【數字列需要使用999表示長度,顯示多少位就用多少個9表示長度】   4、查看可設定的選項可在sqlplus中執行 show all,查看當前使用的設定項目  三、其他常用技巧  1、臨時返回系統提示符當在sqlplus中執行維護操作時,想返回到主機提示符下,但又不想退出當前會話,可採用 !、ho、host 這3個命令中的任意一個[email protected]>  !  --臨時返回作業系統提示符下
[[email protected] ~]$ ls
database_check.sql  database_info.txt  oradiag_oracle
database_info.sql   Desktop            plsql_code
[[email protected] ~]$ exit  --返回sqlplus提示符下 ----------------------------------------------------------------[email protected]> ho  --臨時返回作業系統提示符下
[[email protected] ~]$ ls
database_check.sql  database_info.txt  oradiag_oracle
database_info.sql   Desktop            plsql_code
[[email protected] ~]$ exit  --返回sqlplus提示符下---------------------------------------------------------------[email protected]> host  --臨時返回作業系統提示符下
[[email protected] ~]$ ls
database_check.sql  database_info.txt  oradiag_oracle
database_info.sql   Desktop            plsql_code
[[email protected] ~]$ exit  --返回sqlplus提示符下  註:使用rman過程中也能臨時返回系統提示符下,但只能使用host指令返回  2、oerr指令 oerr可以在Linux系統上查詢簡短的報錯資訊的含義,可以快速有效地輔助排查Oracle故障。oerr在oracle軟體安裝時會一併安裝  a、oerr的位置[[email protected] ~]$  which oerr
/u01/app/oracle/product/11.2.0/dbhome_1/bin/oerr   --oerr預設在$ORACLE_HOME/bin目錄下  b、oerr的用法 oerr ora 【errorid】   例子:[email protected]> select * from v$instance;
select * from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available [[email protected] ~]$ oerr ora  01034
01034, 00000, "ORACLE not available"
// *Cause: Oracle was not started up. Possible causes include the following:
//         - The SGA requires more space than was allocated for it.
//         - The operating-system variable pointing to the instance is
//           improperly defined.
// *Action: Refer to accompanying messages for possible causes and correct
//          the problem mentioned in the other messages.
//          If Oracle has been initialized, then on some operating systems,
//          verify that Oracle was linked correctly. See the platform
//          specific Oracle documentation. 通過使用oracle內建的oerr工具能快速瞭解錯誤原因並瞭解如果著手進行處理       

Oracle 實用技巧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.