linux下使用Oracle常用命令

 进入Oracle用户

su - oracle

以dba身份进入sql语句

sqlplus / as sysdba

启动数据库相关命令
启动数据库

startup

启动监听(关闭监听的命令lsnrctl stop),退出sql编写界面

lsnrctl start

关闭数据库服务,在sql编写界面

shutdown immediate

常看当前连接用户的信息 

select * from user_users;

查看数据库的启动状态 (查看进程里面有没 有Oracle数据库这个进程)

ps -ef|grep oracle

表空间相关命令
Sql语句执行的时候要加上分号
创建表空间:

SQL> create tablespace test_work
2 datafile'/u01/app/oracle/oradata/abc.dbf'
3 size 10M AUTOEXTEND ON;

查询当前所有的表空间:

select *from DBA_TABLESPACES

分类别查看当前的表空间:

SQL> select tablespace_name,
2 file_name,
3 round(bytes / (1024 * 1024), 0) total_space(显示出来的数字是以M为单位的)
4 from dba_data_files
5 order by tablespace_name;

删除相应的表空间

drop tablespace xxx including contents and datafiles;

查看详细数据文件:

SQL> select file_name,tablespace_name from dba_data_files;

扩展表空间 

alter database datafile '/u01/app/oracle/oradata/abc.dbf' resize 20M;

查看表空间的名字及文件所在位置

select tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) total_space
from sys.dba_data_files
order by tablespace_name

-查询当前表空间下使用情况

select a.tablespace_name,
a.bytes / 1024 / 1024 "sum MB",
(a.bytes - b.bytes) / 1024 / 1024 "used MB",
b.bytes / 1024 / 1024 "free MB",
round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "used%"
from (select tablespace_name, sum(bytes) bytes
from dba_data_files
group by tablespace_name) a,
(select tablespace_name, sum(bytes) bytes, max(bytes) largest
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
order by ((a.bytes - b.bytes) / a.bytes) desc;

 

posted @ 2019-07-31 11:17  tomhaha  阅读(15303)  评论(0编辑  收藏  举报