/*
这些可以替换为实际环境下你的账号口令和库名
用户名:test
密码: testpwd
数据库:testdb
*/
-- 生成表空间pipi,pipi_idx
--本机上
create tablespace pipi
datafile 'D:/DataBase/pipi_main1.dbf' size 500m
autoextend on next 200m maxsize 7000m;
create tablespace pipi_idx
datafile 'f:/DataBase/pipi_idx_main1.dbf' size 500m
autoextend on next 200m maxsize 7000m;
--155机器上
create tablespace pipi
datafile
'F:/database/pipi_main1.dbf' size 500m
autoextend on next 500m maxsize 10000m;
/*
create tablespace pipi_idx
datafile 'f:/DataBase/pipi_idx_main1.dbf' size 500m
autoextend on next 200m maxsize 7000m;
*/
--删除表空间
drop tablespace pipi including contents and datafiles
drop tablespace pipi_idx including contents and datafiles
--创建用户名和密码为test/testpwd,默认表空间为pipi,临时表空间为pipi_idx
create user test identified by testpwd
default tablespace pipi
temporary tablespace temp;
--删除test账户
drop user test cascade;
--为test分配角色权限
grant connect,resource,imp_full_database to test;
--移除test的权限
revoke connect,resource,imp_full_database from test;
--创建用户名和密码为test/testpwd,默认表空间为pipi,临时表空间为temp
create user test identified by testpwd
default tablespace pipi --不同环境,这里的默认表空间也会不同
temporary tablespace temp;
--删除test账户
drop user test cascade;
--为test 分配角色权限
grant connect,resource,imp_full_database to test;
--移除test的权限
revoke connect,resource,imp_full_database from test;
select table_name from user_tables;
select * from session_roles;
select * from user_role_privs;
select * from V$tablespace
--查看当前用户的默认表空间,临时表空间
select username,default_tablespace,temporary_tablespace from user_users;
--exp导出表多的话,需要加入参数compress=no,否则可能会出现ora-1659的错误,提示你空间不够,而实际搭建的时候指定的
--表空间大约30g,对于才几百个表,又没有导入数据,绝对是够的,在导入过程中出现这个问题,查了很久才知道compress=no加上的必要性
--10.2帮助上的描述
/*
Default: y
Specifies how Export and Import manage the initial extent for table data.
The default, COMPRESS=y,
causes Export to flag table data for consolidation into one initial extent upon import. If extent sizes are large (for example, because of the PCTINCREASE
parameter), the allocated space will be larger than the space required to hold the data.
If you specify COMPRESS=n,
Export uses the current storage parameters, including the values of initial extent size and next extent size. The values of the parameters may be the values specified in the CREATE TABLE
orALTER TABLE
statements or the values modified by the database system. For example, the NEXT
extent size value may be modified if the table grows and if the PCTINCREASE
parameter is nonzero.
*/
exp test/testpwd@testdb owner=test buffer=409600 file=d:/db.dmp rows=n compress=no
--imp导入数据库的时候,根据不同环境确定对于存储过程是否需要进行编译,不编译则指定为compile=n
imp test/test@testdb fromuser=test touser=test rows=n buffer=409600 file=d:/db.dmp feedback=500 commit=y compile=n
--windows 下默认的字符集是SIMPLIFIED CHINESE_CHINA.ZHS16GBK
--select userenv('language') from dual;
--select table_name from user_tables;
--dmp文件第2,第3个字节可以查出dmp文件的字符集0354是ZHS16GBK
--select nls_charset_name(to_number('0001','xxxx'))
--server characterset
select * from nls_database_parameters
--client characterset
select * from nls_instance_parameters
--session characterset
select * from nls_session_parameters
--显示相关信息
select count(*) from user_indexes;
select count(*) from user_objects;
select count(*) from user_constraints;
select count(table_name) from user_tables;
select * from v$tablespace;
SELECT a.tablespace_name "表空间名",total 表空间大小,free 表空间剩余大小,
(total-free) 表空间使用大小,
ROUND((total-free)/total,4)*100 "使用率 %"
FROM (SELECT tablespace_name,SUM(bytes) free FROM DBA_FREE_SPACE
GROUP BY tablespace_name ) a,
(SELECT tablespace_name,SUM(bytes) total FROM DBA_DATA_FILES
GROUP BY tablespace_name) b
WHERE a.tablespace_name=b.tablespace_name
--显示表空间关联的文件位置
select * from dba_data_files where tablespace_name like 'UNDO%';
--杂项
select file_name,bytes/1024/1024 from dba_data_files where tablespace_name like 'UNDOTBS1'
select usn,xacts,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks from v$rollstat order by rssize;