linux下使用Oracle常用命令

admin 2020年6月12日06:21:30评论39 views字数 1345阅读4分29秒阅读模式

进入Oracle用户

1

su - oracle


以dba身份进入sql语句

1

sqlplus / as sysdba


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

1

startup


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

1

lsnrctl start


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

1

shutdown immediate


常看当前连接用户的信息 

1

select * from user_users;


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

1

ps -ef|grep oracle


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

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


查询当前所有的表空间:

1

select *from DBA_TABLESPACES


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

1

2

3

4

5

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;


扩展表空间 

1

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


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

linux下使用Oracle常用命令

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;

linux下使用Oracle常用命令


本文始发于微信公众号(LemonSec):linux下使用Oracle常用命令

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2020年6月12日06:21:30
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   linux下使用Oracle常用命令http://cn-sec.com/archives/310048.html

发表评论

匿名网友 填写信息