1,SGA PGA

--查看为数据库分配的内存。

select * from v$sga;

--内存分配细节

select * from v$sgastat;

--SGA分配情况。

select * from v$parameter a where a.NAME in('shared_pool_size','log_buffer','db_cache_size','java_pool_size','larger_pool_size');

--查看SGA使用情况

select component,current_size/1048576,min_size/1048576 from v$sga_dynamic_components;

 ---查询PGA总大小。

SQL> show parameter pga ; 

 --已经消耗的PGA

SQL> select round(sum(pga_alloc_mem)/1048576,1) from v$process;

--xshell 中, 查看为数据库分配多少cpu 。

[root@localhost ~]# su - oracle

[oracle@localhost ~]$ sqlplus zy_12c/1@192.168.100.51:1521/orcl

SQL> show parameters cpu

 

2,processessessions

 --修改processes和sessions值

alter system set processes=1500 scope=spfile; 

--查询数据库进程数

sql>select parameter process;

sql>select count(*) from v$process;

--每个session都会占用一定的PGA资源,必要的时候,需要控制session的数量。

select count(*) from v$session;

 

3,游标

--查看ORACLE最大游标数

SQL> show parameter open_cursors;

--查看当前打开的游标数目

SQL> select count(*) from v$open_cursor;

--修改ORACLE最大游标数

SQL> alter system set open_cursors=1000 scope=both;

--系统已更改。

SQL> show parameter open_cursors;

 

4,oracle数据库占用的memory

--查看数据库内存大小

SQL> show parameter memory;

--修改数据库内存

SQL> show parameter spfile;

SQL> create spfile from pfile;--把spfile文件覆盖由pflie , 注意使用会把定义好的session值等覆盖了。

SQL> shutdown immediate;

SQL> startup;

SQL> alter system set memory_max_target=40G scope=spfile;

SQL> alter system set memory_target=40G scope=spfile;

SQL> shutdown immediate;

SQL> startup;

SQL> show parameter memory;

如果linux系统不能修改成更大的内存, 参考http://blog.sina.com.cn/s/blog_5d32e4930102wl3c.html , 修改系统的共享内容空间,再增加oracle内存。  




5,系统配置参数

--显示oracle系统配置参数

SQL> show parameter target;

 

6,表空间

--查询数据库表空间使用情况。 

SELECT a.tablespace_name, 

a.bytes total, 

b.bytes used, 

c.bytes free, 

(b.bytes * 100) / a.bytes "% USED ", 

(c.bytes * 100) / a.bytes "% FREE " 

FROM sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c 

WHERE a.tablespace_name = b.tablespace_name 

AND a.tablespace_name = c.tablespace_name; 

--查询使用过的表空间

select distinct tablespace_name from dba_all_tables;--系统表

select distinct tablespace_name from user_all_tables; --用户表

 

--根据表空间查询,表空间内的表

select table_name from dba_all_tables where tablespace_name = tablespacename

 

7,用户设置

--设置用户密码忽略大小写

ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON = FALSE;  

--查询用户权限

select * from session_privs;

 

--查看字符集

select userenv('language') from dual;  




10,控制台

https://localhost:1158/em/console   sys、oracle123、sysdba 登录。

 

 

--创建表空间

create tablespace viewhigh1 datafile 'D:\OracleDataFile\viewhigh1_01.dbf' size 2G autoextend on next 1G maxsize unlimited;


--修改表空间

ALTER TABLESPACE oews ADD DATAFILE  'E:\oews\oews.dbf' SIZE 5g  AUTOEXTEND ON NEXT 5g MAXSIZE unlimited; 

 

--创建临时表空间        

create temporary tablespace viewhigh_temp tempfile 'D:\OracleDataFile\viewhigh_temp_01.dbf' SIZE 2G autoextend on next 1G maxsize unlimited;


--sqlplus 登录

drgs_yd_test/drgs_yd_test@10.10.242.22/orcl


--设置用户密码忽略大小写

ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON = FALSE;  


--修改processes和sessions值

alter system set processes=1500 scope=spfile;  

alter system set sessions=1500 scope=spfile;





--正在执行的sql

select sql_text, b.sid,b.serial#, 'alter system kill session'''||b.SID||','||b.serial#||''';',b.username

from v$process a, v$session b, v$sqlarea c

where a.addr = b.paddr

and b.sql_hash_value = c.hash_value;

--kill

alter system kill session 'sid,serial#';  




--查询死锁

select a.session_id, c.serial#, a.locked_mode, a.oracle_username, a.os_user_name, c.machine,

       c.terminal, b.object_name, c.logon_time

from   v$locked_object a, all_objects b, v$session c

where  a.object_id = b.object_id and a.session_id = c.sid

order  by c.sid, c.serial#; 

--kill

alter system kill session 'sid,serial#';  




----基准库维护

--删除用户及表空间及表空间文件一起删除掉

declare

  cSQL varchar2(2000);

begin

  for i in (select sid,serial# from v$session where username = 'OES') loop

   dbms_output.put_line('alter system kill session ''' || i.sid || ',' || i.serial# || ''''); 

   execute immediate 'alter system kill session ''' || i.sid || ',' || i.serial# || '''';

  end loop;

  execute immediate 'drop user OES cascade';

  execute immediate 'drop tablespace OES1 including contents and datafiles cascade constraint';

end;


--目录

select * from dba_directories t;


-- 查看表空间路径

select * from dba_data_files; 



---删除表空间

drop tablespace drgs_yd_test including contents and datafiles cascade constraint;



--创建用户 

create user OES511

  identified by 1

  default tablespace OES511

  temporary tablespace TEMP

  profile DEFAULT

  password expire;

-- Grant/Revoke object privileges 

grant read, write on directory DATA_PUMP_DIR to OES511;

-- Grant/Revoke role privileges 

grant connect to OES511 with admin option;

grant dba to OES511 with admin option;

grant exp_full_database to OES511;

grant imp_full_database to OES511;

grant resource to OES511 with admin option;

-- Grant/Revoke system privileges 

grant alter user to OES511;

grant create any view to OES511;

grant create session to OES511;

grant create user to OES511;

grant drop any view to OES511;

grant drop user to OES511;

grant unlimited tablespace to OES511 with admin option;

-- Set the user's default roles 

alter user OES511

  default role connect, dba, resource;



--建表空间。 

create tablespace OES5111 datafile '/data1/orcl/oes511_01.dbf' size 2G autoextend on next 1G maxsize unlimited;



--恢复库。 如果不知道dmp中的数据库用户名时,用ue打开看一下。(如果有报错的话,最好看一下后面四个参数如何设置)

--full=y ignore=y table_exists_action=replace transform=segment_attributes:n

--恢复库

impdp OES/1  directory=DUMPDIR  dumpfile=OES_2019-05-17.DMP  logfile=OES_5119_1.log  REMAP_SCHEMA=OES:OES  table_exists_action=replace transform=segment_attributes:n

--同时恢复两个库

impdp OES/1  directory=DUMPDIR  dumpfile=OES_2019-05-17.DMP  logfile=OES_5119_1.log  REMAP_SCHEMA=OES:OES,OES511:OES511  table_exists_action=replace transform=segment_attributes:n



--备份库

expdp OES/1 directory=DUMPDIR  dumpfile=OES_2019-05-17.DMP  logfile=OES_2019-05-17.log  schemas=OES

--同时备份两个库

expdp OES511/1 dumpfile=OES511_20190517.dmp  schemas=OES511,rep,OES directory=DUMPDIR





中文乱码:

1)select userenv('language') from dual; --先查询数据库字符集

2)select * from V$NLS_PARAMETERS 查看第一行中PARAMETER项中为NLS_LANGUAGE 对应的VALUE项中是否和第一步得到的值一样。

3)如果不是,需要设置环境变量.PLSQL客户端使用的编码和服务器端编码不一致,插入中文时就会出现乱码.

4)设置环境变量计算机->属性->高级系统设置->环境变量->新建

5)设置变量名:NLS_LANG,变量值:第1步查到的值, 我的是    AMERICAN_AMERICA.ZHS16GBK

步骤阅读

6)重新启动PLSQL,插入数据正常