oracle读取表空间物理文件中数据,shell脚本读取oracle数据库数据写入到文件中
1、linux 需要用 sqlplus 客戶(hù)端去連接oracle 數(shù)據(jù)庫(kù),首先需要確認(rèn)有沒(méi)有安裝:which sqlplus
2、如果沒(méi)有安裝就需要先安裝一下(百度)
3、配置環(huán)境變量:
vim /etc/profile
4、執(zhí)行 source /etc/profile
5、whereis oracle? #查看oracle 客戶(hù)端安裝路徑
6、?進(jìn)入客戶(hù)端目錄
7、編輯配置文件:vim tnsnames.ora
ORCL?=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = servicename)
)
)
8、編輯保存完成以后,可以用命令行測(cè)試是否連接成功
9、sqlplus username/password@ORCL
10、編寫(xiě)shell腳本(我查詢(xún)的是表空間使用率,根據(jù)需求自行修改)
#! /bin/bash
sqlplus username/password@ORCL << EOF
set linesize 200
set pagesize 200
spool /home/tmp/zxh.log
select a.tablespace_name, total, free,(total-free) as usage from
(select tablespace_name, sum(bytes)/1024/1024 as total from dba_data_files group by tablespace_name) a,
(select tablespace_name, sum(bytes)/1024/1024 as free from dba_free_space group by tablespace_name) b
where a.tablespace_name = b.tablespace_name;
spool off
quit
EOF
遇到的問(wèn)題:
1、INSERT -- W10: Warning: Changing a readonly file
su root
password:《輸入你的root密碼》
然后就切換到你的root用戶(hù),就有權(quán)限修改一些readonly的文件了
2、source /home/oracle/.bash_profile? //環(huán)境變量生效
總結(jié)
以上是生活随笔為你收集整理的oracle读取表空间物理文件中数据,shell脚本读取oracle数据库数据写入到文件中的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python目前有多少库文件_必学Pyt
- 下一篇: qt项目中输出日志