关于修改用户,表的 tablespace_name走的一点弯路

 

看tablespace 建在那个文件中:

SQL> select file_name,tablespace_name,bytes,status,online_status from dba_data_files;
FILE_NAME                    TABLESPACE_NA      BYTES STATUS    ONLINE_
---------------------------- ------------- ---------- --------- -------
/u02/ezhou/users01.dbf       USERS           66846720 AVAILABLE ONLINE
/u02/ezhou/sysaux01.dbf      SYSAUX         272629760 AVAILABLE ONLINE
/u02/ezhou/undotbs01.dbf     UNDOTBS1       298844160 AVAILABLE ONLINE
/u02/ezhou/system01.dbf      SYSTEM         513802240 AVAILABLE SYSTEM
/u02/ezhou/example01.dbf     EXAMPLE        104857600 AVAILABLE ONLINE
/u02/ezhou/test01.dbf        TB_TEST         10485760 AVAILABLE ONLINE
/u02/ezhou/example02.dbf     EXAMrPLE         10485760 AVAILABLE ONLINE

7 rows selected.

看table 属于那个tablespace:
SQL> select table_name, tablespace_name from user_tables where table_name = 'TEST';

TABLE_NAME                     TABLESPACE_NA
------------------------------ -------------
TEST                           USERS

Elapsed: 00:00:00.01

下面把 table: test 建在TB_TEST 下:


SQL> show user;     
USER is "SCOTT"
SQL> alter table test move tablespace TB_TEST;
alter table test move tablespace TB_TEST
            *
ERROR at line 1:
ORA-01652: unable to extend temp segment by 128 in tablespace TB_TEST

怀疑是temp 的问题:

SQL> select name,(bytes)/1024/1024 from v$tempfile;

NAME                                     (BYTES)/1024/1024
---------------------------------------- -----------------
/u02/ezhou/temp01.dbf                                   26

Elapsed: 00:00:00.01
SQL> show user;
USER is "SYS"

看到temp 的大小是26M,下面来extend 一下:
首先,看看那些user 用到这个临时表空间:

SQL>  select username,account_status, TEMPORARY_TABLESPACE from dba_userS where account_status = 'OPEN';

USERNAME       ACCOUNT_STATUS                   TEMPORARY_TABLESPACE
-------------- -------------------------------- ------------------------------
MGMT_VIEW      OPEN                             TEMP
SYS            OPEN                             TEMP
SYSTEM         OPEN                             TEMP
DBSNMP         OPEN                             TEMP
SYSMAN         OPEN                             TEMP
SHENG          OPEN                             TEMP
SCOTT          OPEN                             TEMP

7 rows selected.

Elapsed: 00:00:00.04

SQL> ALTER DATABASE TEMPFILE '/u02/ezhou/temp01.dbf' resize 40M;

Database altered.

Elapsed: 00:00:00.05

一般情况:应该是建立一个新的,然后把新建立的表空间设置为默认的,然后删除旧的。
上面的命令真强大。

SQL> select name,(bytes)/1024/1024 from v$tempfile;

NAME                                     (BYTES)/1024/1024
---------------------------------------- -----------------
/u02/ezhou/temp01.dbf                                   40

Elapsed: 00:00:00.01

下面把用户scott 的tablespace 改成:TB_TEST:
SQL> select table_name, owner from dba_tables where owner like 'SCOTT' and table_name = 'TEST';

TABLE_NAME                     OWNER
------------------------------ ------------------------------
TEST                           SCOTT

Elapsed: 00:00:00.08

SQL>alter user SCOTT TABLESPACE DEFAULT TB_TEST;

SQL> create table t (id number, name varchar2(10))
  2  ;

Table created.

Elapsed: 00:00:00.41

Elapsed: 00:00:01.67
SQL> select table_name, tablespace_name from user_tables;

TABLE_NAME                     TABLESPACE_NA
------------------------------ -------------
DEPT                           USERS
EMP                            USERS
BONUS                          USERS
SALGRADE                       USERS
T                              TB_TEST
TEST                           USERS

 

SQL> select table_name, tablespace_name from user_tables;

TABLE_NAME                     TABLESPACE_NA
------------------------------ -------------
DEPT                           USERS
EMP                            USERS
BONUS                          USERS
SALGRADE                       USERS
T                              TB_TEST
TEST                           USERS

当我发现新建的table tablespace 变成tb_test, 为啥其他的没有变呢?

当我向 t 表中插入 test 的数据也报错:
ERROR at line 1:
ORA-01652: unable to extend temp segment by 8 in tablespace TB_TEST。

我check 一下tb_test 的大小:只有20M,

我又查了 scott.test 的大小:

SQL> select owner, segment_name,tablespace_name,(bytes)/1024/1024 from dba_segments where owner like 'SCOTT';

OWNER      SEGMENT_NA TABLESPACE_NAME                (BYTES)/1024/1024
---------- ---------- ------------------------------ -----------------
SCOTT      PK_DEPT    USERS                                      .0625
SCOTT      DEPT       USERS                                      .0625
SCOTT      EMP        USERS                                      .0625
SCOTT      PK_EMP     USERS                                      .0625
SCOTT      BONUS      USERS                                      .0625
SCOTT      SALGRADE   USERS                                      .0625
SCOTT      T          TB_TEST                                        9
SCOTT      TEST       USERS                                         60

原因找到:tb_test 设置太小了:

下面扩大点:
alter database datafile 'u02/ezhou/test01.dbf' resize 100m;

Database altered.

Elapsed: 00:00:06.32
SQL> alter table scott.test move tablespace TB_test;

Table altered.

Elapsed: 00:00:28.56
SQL>

SQL> l
  1* select table_name, tablespace_name from user_tables
SQL> conn scott/oracle
Connected.
SQL> /

TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
DEPT                           USERS
EMP                            USERS
BONUS                          USERS
SALGRADE                       USERS
T                              TB_TEST
TEST                           TB_TEST

6 rows selected.

发现已经改变。
success.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

shenghuiping2001

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

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

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

打赏作者

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

抵扣说明:

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

余额充值