Oracle安装后必须干的几件事

Oracle安装后必须干的几件事

1. 改默认密码有效期为无限期

详见CSDN博客:Oracle11g密码过期(默认180天)及设置密码无限期的方法

2. 给空表分表下segment

ORACLE 11G中有个新特性,当表无数据时,不分配segment,以节省空间。

影响:当使用exp导出xxxx.dmp文件时,空表不会导入,回导致表缺失的问题

1. 临时性解决Oracle11g空表导出问题

此法仅限本次对已经存在的表进行分析与分配空间,后面加的表就不起作用了,还是得每次分析一次

  1. 首先使用下面的sql语句查询一下当前用户下的所有空表
select table_name from user_tables where NUM_ROWS=0 or num_rows is null;
  1. 根据空表拼接 对空表分配空间的语句
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 or num_rows is null;
  1. 执行上面对空表分配空间的alter语句,类似语句如下
alter table TB_TEST1 allocate extent;
alter table TB_TEST2 allocate extent;
alter table TB_TEST3 allocate extent;
alter table TB_TEST4 allocate extent;
alter table TB_TEST5 allocate extent;
  1. 再次执行exp命令时就可以导出空表了

2. 永久性解决Oracle11g空表导出问题

通过修改Oracle11g的配置,自动为空表分配segment表空间,永久性解决空表导出问题

  1. 进入sqlplus
sqlplus / as sysdba
  1. 先查询下deferred_segment_creation的值

通过show parameter deferred_segment_creation;语句查询,如下:

C:\Users\yuanjinsheng>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期三 1214 09:34:30 2022
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
# 查询
SQL> show parameter deferred_segment_creation;

NAME                                 TYPE
------------------------------------ ----------------------
VALUE
------------------------------
deferred_segment_creation            boolean
TRUE
SQL>

具体如下图:
在这里插入图片描述

  1. 修改Oracle的deferred_segment_creation参数值,默认为true,改为false即可
    执行alter system set deferred_segment_creation=false;更改参数值
C:\Users\yuanjinsheng>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期三 1214 09:34:30 2022
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
# 修改
SQL> alter system set deferred_segment_creation=false;
系统已更改。
#再次查看值为FALSE
SQL> show parameter deferred_segment_creation;
NAME                                 TYPE
------------------------------------ ----------------------
VALUE
------------------------------
deferred_segment_creation            boolean
FALSE
SQL>

具体过程如下图:
在这里插入图片描述

  1. 改完配置后重启Oracle数据库服务让设置的参数生效

  2. 注意:该参数设置后只对上面参数改动后新增的空表分配segment空间,对之前建立的空表(已经存在的空表)不分配segment空间,仍不能导出,需要通过下面语句进行分析处理

  3. 给原有的空表分配segment空间

# 1.适用数据库用户登录,并查询当前用户下的空表
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 or num_rows is null;
# 2. 将上面语句执行的结果拷贝出来并一一执行一下,如下:
alter table TB_TEST1 allocate extent;
alter table TB_TEST2 allocate extent;
alter table TB_TEST3 allocate extent;
alter table TB_TEST4 allocate extent;
alter table TB_TEST5 allocate extent;
  1. 再次执行exp命令时就可以导出空表了

3. 表空间

备份与恢复数据更方便

以下脚本以Oracle12c为例,Oracle11g同样适用

1. 查看表空间

--查看用户
select * from dba_users t where t.username like 'C##%'

---查看表空间名称及表空间文件位置
select t1.name,t2.name from v$tablespace t1,v$datafile t2 where t1.ts# = t2.ts#;

---1.表空间信息查看
select * from dba_tablespaces; ---查看表空间
select * from dba_data_files; --查看数据库文件位置
select * from dba_free_space; --查看空闲空间 
---2.临时表空间信息查看
select * from dba_temp_files;
select * from dba_temp_free_space;

2. 创建表空间及用户

--创建表空间
create tablespace TESTDB_DATA
datafile 'E:\APP\ORADATA\ORCL\TESTDB_DATA.dbf' --dbf文件位置
size 500M 
autoextend on next 100M 
maxsize unlimited;
--创建临时表空间
create temporary tablespace temporary_TESTDB_DATA
tempfile 'E:\APP\ORADATA\ORCL\TESTDB_DATA_temp.dbf' 
size 500M 
autoextend on 
next 100M maxsize unlimited
extent management local;


---创建用户并指定默认表空间
create user c##testdb identified by testdb
profile default
default tablespace TESTDB_DATA
temporary tablespace temporary_TESTDB_DATA
account unlock;

3. 修改表空间(需要时)

---修改表的表空间
select 'alter table  ' || TABLE_NAME || '  move tablespace docmanagement;'
  from USER_TABLES UT
 where UT.TABLESPACE_NAME = 'USERS'
 
--查询当前用户下在 USERS 表空间中的所有索引 ,并修改索引的表空间为 docmanagement
select 'alter index '|| index_name ||' rebuild tablespace docmanagement;' from user_indexes i
where i.tablespace_name = 'USERS'

4. 删除表空间(需要时)

--删除表空间及数据库文件
drop tablespace DOCMANAGEMENT including contents and datafiles;

--删除临时表空间及数据库文件
drop tablespace TEMPORARY_DOCMANAGEMENT including contents and datafiles;

4. 用户相关

以testdb/testdb作为用户名与密码举例

--创建用户
create user c##testdb identified by testdb

--用户授权,将connect,resource,dba权限授予testdb
grant connect,resource,dba to c##testdb

--修改用户密码
alter user testdb identified by test123

--删除用户
--drop user c##testdb cascade
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jinshengyuanok

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值