[20120926]只读表空间.txt

简介: [20120926]只读表空间.txtSQL> select * from v$version ;BANNER-------------------------------------------------------------------------...
[20120926]只读表空间.txt

SQL> select * from v$version ;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

CREATE TABLESPACE TEST DATAFILE
  '/u01/app/oracle11g/oradata/test/test01.dbf' SIZE 64M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
LOGGING
PERMANENT
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

create table t tablespace test as select rownum id,'testtest' name from dual connect by level

ALTER TABLESPACE TEST READ ONLY;

SQL> create table tx tablespace test as select rownum id,'testtest' name from dual connect by level
create table tx tablespace test as select rownum id,'testtest' name from dual connect by level
                                                                         *
ERROR at line 1:
ORA-01647: tablespace 'TEST' is read-only, cannot allocate space in it

SQL> drop table t purge ;
Table dropped.

-- 即使建立在只读表空间的对象,其建立的对象可以删除,但是占用的空间呢?

SQL> column objectname format a20
SQL> SELECT owner, DECODE (partition_name, NULL, segment_name, segment_name || ':' || partition_name) objectname,
       segment_type objecttype, NVL (BYTES, 0) "SIZE", NVL (initial_extent, 0) initialext, NVL (next_extent, 0) nextext,
       NVL (extents, 0) numextents, NVL (max_extents, 0) "MAXEXTENTS",HEADER_FILE,HEADER_BLOCK
  FROM dba_segments
 WHERE tablespace_name = 'TEST';

OWNER   OBJECTNAME           OBJECTTYPE               SIZE INITIALEXT    NEXTEXT NUMEXTENTS MAXEXTENTS HEADER_FILE HEADER_BLOCK
------- -------------------- ------------------ ---------- ---------- ---------- ---------- ---------- ----------- ------------
SCOTT   8.130                TEMPORARY              262144      65536    1048576          4 2147483645           8          130

--objectname=8.130. 看看能访问吗? TEMPORARY段不能这样访问.
SQL> select * from "8.130";
select * from "8.130"
              *
ERROR at line 1:
ORA-00942: table or view does not exist

google找到一段解析:

http://blog.tanelpoder.com/2010/07/11/dropping-and-creating-tables-in-read-only-tablespaces-what/

    Wow, Oracle has converted the table segment into a temporary segment instead (see segment_type)! Bur our tablespace is
read only, how can it do that?! The answer is that neither the regular DROP nor DROP PURGE need to write anything into the
tablespace where the segment resides! The initial DROP operation just updated data dictionary, like renaming the table to
BIN$… in OBJ$ and so on. The second DROP PURGE operation just ran a bunch of deletes against data dictionary to indicate
that the table object is gone. But why is the TEMPORARY segment left behind? This has to do with locally managed tablespaces.
Before LMT days, when you dropped a segment, then the segment space was released and acquired back to tablespace through 
inserts/updates to UET$/FET$ (used/free extents) base tables, which resided in system tablespace like all other data dictionary
base tables. But with LMTs, the free space information is kept in bitmaps in the tablespace files themselves! Thus, if you
drop a table in a read only LMT tablespace, the table will be gone, but the space will not be physically released (as you 
can't update the LMT bitmaps in read only tablespace files). However, Oracle doesn't want to lose that space should someone
make the tablespace read write later on, so the table segment is updated to be a TEMPORARY segment instead of completely 
deleting it from data dictionary. That's how the SMON can clean it up later on should that tablespace become read-write 
again. The 9.130 in SEGMENT_NAME column means relative file# 9 and starting block# 130, that's a segment's unique identifier
in a tablespace. Let's move on. This example is executed on Oracle 11.2, while logged on to a non-SYS/SYSTEM user:

    该blog还提到了deferred segment creation的问题,就是表空间只读,在11GR2下依旧可以建立表,但是不分配段.

SQL> select status from dba_tablespaces where tablespace_name = 'TEST';

STATUS
---------
READ ONLY

SQL> create table test(a int) tablespace test;
Table created.

SQL> drop table test purge;
Table dropped.

SQL> create table test (a int) segment creation IMMEDIATE tablespace test;
create table test (a int) segment creation IMMEDIATE tablespace test
*
ERROR at line 1:
ORA-01647: tablespace 'TEST' is read-only, cannot allocate space in it

SQL> select owner,segment_name,segment_type from dba_segments where tablespace_name = 'TEST';

OWNER  SEGMENT_NAME  SEGMENT_TYPE
------ ------------- ------------------
SCOTT  8.130         TEMPORARY

按照blog的介绍,只要打开读写模式,smon就会清除这些临时段.

SQL> alter tablespace test read write;
Tablespace altered.

SQL> select owner,segment_name,segment_type from dba_segments where tablespace_name = 'TEST';
no rows selected

--OK,临时段被清除.



目录
相关文章
|
4天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1112 2
|
3天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
584 11
|
13天前
|
人工智能 运维 安全
|
4天前
|
弹性计算 Kubernetes jenkins
如何在 ECS/EKS 集群中有效使用 Jenkins
本文探讨了如何将 Jenkins 与 AWS ECS 和 EKS 集群集成,以构建高效、灵活且具备自动扩缩容能力的 CI/CD 流水线,提升软件交付效率并优化资源成本。
305 0
|
11天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
13天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
817 23
|
4天前
|
缓存 供应链 监控
VVIC seller_search 排行榜搜索接口深度分析及 Python 实现
VVIC搜款网seller_search接口提供服装批发市场的商品及商家排行榜数据,涵盖热销榜、销量排名、类目趋势等,支持多维度筛选与数据分析,助力选品决策、竞品分析与市场预测,为服装供应链提供有力数据支撑。

热门文章

最新文章