nagios mail notify

There are lots of services monitor in your nagios,what if the service is down?
The most important issue is that the admin should be notified by the first time,email is great tool on it.

1.contact.cfg

edit the contact.cfg file to tell the nagios who is the admin to receieve all the mail

# template which is defined elsewhere.

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (de
fined above)
        alias                           Nagios Admin            ; Full name of user

        email                           admin@gmail.com  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }

2.commands.cfg

nothing need to be changed in the commands.cfg,the sample is marked below:

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME
$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTI
FICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SER
VICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Inf
o:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ 
**" $CONTACTEMAIL$
        }

3.using the sendmail in linux to sending mail

vi the /etc/mail.rc which is the config file of sendmail

# add by admin

set from=sender@gmail.com smtp=smtp.gmail.com
set smtp-auth-user=sender@gmail.com smtp-auth-password=pwd_email_account smtp-auth=login

4.windows.cfg
enable the function of mail notification by add option “notifications_enabled 1”

# Change the host_name to match the name of the host you defined above

define service{
        use                     generic-service
        host_name               COS360,PRINTER_SRV_BJ,MENJIN,VM_BJ
        service_description     C:\ Drive Space
        check_command           check_nt!USEDDISKSPACE!-l c -w 80 -c 90
        notifications_enabled   1
        }

//add  notifications_enabled in services will open the notification

5.tesing

bring down one of the service,you will get the email notification

–EOF–

nagios

you can use nagios to monitor your infrastructure of basic IT resources.

you should first define a host to be monitored then use the define service to do the action,it’s the OO thinking mind.

taking the NT platform as a example,install the NSClient++ plugin as agent to the hosts you want to monitor.

define host{
        use             windows-server  ; Inherit default values from a template
        host_name       host1  ; The name we're giving to this host
        alias           COS Security Server     ; A longer name associated with the host
        address         172.16.60.134   ; IP address of the host
        }


define service{
        use                     generic-service
        host_name               host1
        service_description     NSClient++ Version
        check_command           check_nt!CLIENTVERSION
        }

111

check_command is the bin action of monitoring the resource,there are lots of monitor action in $nagios/bin and you add

–EOF–

Something interesting is happening…

Something interesting is happening…

The world’s largest taxi company owns no vehicles;the world’s most popular media owner creates no content;the most valuable retailer has no inventory;the world’s largest accommodation provider owners no real estate.

the revolution is involving..

interesting is happening

FW:Microsoft Announces New Container Technologies for the Next Generation Cloud

source:http://blogs.technet.com/b/server-cloud/archive/2015/04/08/microsoft-announces-new-container-technologies-for-the-next-generation-cloud.aspx

Guest post by Mike Neil, General Manager for Windows Server, Microsoft

In today’s cloud-first world, businesses increasingly rely on applications to fuel innovation and productivity. As the cloud evolves, containers are emerging as an attractive way for developers to quickly and efficiently build and deploy these applications at the speed of business. Offering developers and IT professionals the ability to deploy applications from a workstation to a server in mere seconds, containers are taking application development to a whole new level.

As developers look to expand the benefits of containers to a broader set of applications, new requirements are emerging. For example, heightened levels of trust may be required for enterprise systems or in hosted environments. Furthermore, developers often deploy into mixed operational environments where they may not have control of the platform where the application is deployed. Virtualization has historically provided a valuable level of isolation that enables these scenarios but there is now opportunity to blend the efficiency and density of the container model with the right level of isolation.

Last October, Microsoft and Docker, Inc. jointly announced plans to bring containers to developers across the Docker and Windows ecosystems via Windows Server Containers, available in the next version of Windows Server. We will be unveiling the first live demonstration in a few weeks, starting at the BUILD conference. Today, we are taking containerization one step further by expanding the scenarios and workloads developers can address with containers:

• Hyper-V Containers, a new container deployment option with enhanced isolation powered by Hyper-V virtualization 
• Nano Server, a minimal footprint installation of Windows Server that is highly optimized for the cloud, and ideal for containers.

First-of-Their-Kind Hyper-V Containers

Leveraging our deep virtualization experience, Microsoft will now offer containers with a new level of isolation previously reserved only for fully dedicated physical or virtual machines, while maintaining an agile and efficient experience with full Docker cross-platform integration. Through this new first-of-its-kind offering, Hyper-V Containers will ensure code running in one container remains isolated and cannot impact the host operating system or other containers running on the same host.

While Hyper-V containers offer an additional deployment option between Windows Server Containers and the Hyper-V virtual machine, you will be able to deploy them using the same development, programming and management tools you would use for Windows Server Containers. In addition, applications developed for Windows Server Containers can be deployed as a Hyper-V Container without modification, providing greater flexibility for operators who need to choose degrees of density, agility, and isolation in a multi-platform, multi-application environment.

Our Containers in the Docker Ecosystem

Docker plays an important part in enabling the container ecosystem across Linux, Windows Server and the forthcoming Hyper-V Containers. We have been working closely with the Docker community to leverage and extend container innovations in Windows Server and Microsoft Azure, including submitting the development of the Docker engine for Windows Server Containers as an open contribution to the Docker repository on GitHub. In addition, we’ve made it easier to deploy the latest Docker engine using Azure extensions to setup a Docker host on Azure Linux VMs and to deploy a Docker-managed VM directly from the Azure Marketplace. Finally, we’ve added integration for Swarm, Machine and Compose into Azure and Hyper-V.

“Microsoft has been a great partner and contributor to the Docker project since our joint announcement in October of 2014,” said Nick Stinemates, Head of Business Development and Technical Alliances. “They have made a number of enhancements to improve the developer experience for Docker on Azure, while making contributions to all aspects of the Docker platform including Docker orchestration tools and Docker Client on Windows. Microsoft has also demonstrated its leadership within the community by providing compelling new content like dockerized .NET for Linux. At the same time, they’ve been working to extend the benefits of Docker containers- application portability to any infrastructure and an accelerated development process–to its Windows developer community.”

Introducing Nano Server: The Nucleus of Modern Apps and Cloud

The operating system has evolved dramatically with the move to the cloud. Many customers today need their OS for the primary purpose of powering born-in-the-cloud applications. Leveraging our years of experience building and running hyper-scale datacenters, Microsoft is uniquely positioned to provide a purpose-built OS to power modern apps and containers.

The result is Nano Server, a minimal footprint installation option of Windows Server that is highly optimized for the cloud, including containers. Nano Server provides just the components you need – nothing else, meaning smaller server images, which reduces deployment times, decreases network bandwidth consumption, and improves uptime and security. This small footprint makes Nano Server an ideal complement for Windows Server Containers and Hyper-V Containers, as well as other cloud-optimized scenarios. A preview will be available in the coming weeks, and you can read more about the technology on the Windows Server blog.

Containers are bringing speed and scale to the next level in today’s cloud-first world. Microsoft is uniquely positioned to propel more organizations forward into the next era of containerization, by offering flexibility and choice through Windows Server containers, Linux containers, and Hyper-V containers both in the cloud and on-premises. Today’s announcements are just the beginning of what’s to come, as we continue to fuel both the growth of containers in the industry, and new levels of application innovation for all developers.

Stay tuned for more details on these new innovations, beginning at our BUILD conference in a few weeks.

“华为四核honor”与小米2同一天登陆

    看到一条新闻,华为推出了"honor四核版"手机,售价也只有1888元。海思 K3V2四核1.4GHz处理器、4.5英寸1280×720分辨率 IPS屏幕,拥有2G RAM,摄像头达到800万像素,电池容量2230mAh。在加上今天是期待已久的小米2的网络发售时间,中午的时候在我努力的" 刷新"页面、"不断F5"时,面对半瘫不瘫的页面,nothing you can do but wait….终于,不到3分钟,终于有了反馈,售 罄、抢购完毕,88,11月再来,很无奈,还真是成了之前提过的"期货小米2"。曾想华为下午推出了这个利器,挑在这个时间点,不知华为终端是有意,还是 巧合,但看配置,小米2其实没太多亮点了,后者逐渐在赶上。

    其实,我一直有个观点:粘着用户的应该是易用的ROM(miui),而不是硬件配置。当下,手机的硬件配置已经不是瓶颈了,某种程度来讲,已经出现“配置 过剩”了,而小米做得不错的地方是在混乱的android市场上,一直在不断优化自己的rom,将其易用性不断提升,一直有不少的粉丝,用心可见。记得几 个月前,给父母买了小米,60左右的老人在两天内基本把功能摸熟了,其实这个就是最好的易用性体现,手机是否好用,让老年人或者没有“背景”的人用就可以 了,产品好坏很容易分辨出来。就当某个周五,老爹在应用小米例行的更新之后,惊奇的发现之前手机上已经硕大的字体,变得更大了,之前偏小的二级菜单字体也 变大了,老爹如获至宝,多年未解决的问题,在智能手机时代搞定了,我也松了一口气。要知道为了给老爹换个称心如意的手机,在市面上,我跑了很久,一直在山 寨手机里面找来找去的我,也终于卸下重担,仅仅是为了满足老人“字大”、“手写”的两个简单的需求。

   也许,只有老罗那样非常追求完美的家伙能做出超过miui的rom了,于是,非常期待一个月后老罗的ROM。

    华为应当完善自己的rom,在易用性上投入本来具备优势的研发力量,打造好自己的rom,加上华为在运营商那里耕耘这么多年,没有理由做得比miui差 的。当然,在变化迅速的互联网行业,华为欠缺的是“迅速”,如何让“大象跳舞”?面对快速变化的而用户需求,如何快速满足,打造好自己的产品?

    四 核,小米2会慢慢的面对很多四核的竞争对手,例如后面会问世的LG nexus 4:高通骁龙S4四核1.5GHz处理器,搭配的内存高达 2GB base on android 4.2,价格1900人民币,是的,没错,只有1900元,想必小米2背后是阵阵凉气。"期货小米2"随着时间 的推移,不久其性价比就不会再那么优势明显了,强敌在后,小心了,2012的第四季度,好戏上演,精彩连连。


–EOF–

 

 

500 OOPS: cannot change directory

environment:

centos 6.2 x86+vsftpd

It’s a long time having not playing with centos and vsftpd,there is the call from the customer for help about the error msg:”vsftp 500 OOPS: cannot change directory” as trying to use the ftp service……

it may be done with the selinux…or firewall….

setsebool -P ftpd_disable_trans 1

“-P” means permanent and disable the selinux service

“service vsftpd restart” will kick away the problem.

 

–EOF–

FreeNAS backup solution using rsync and virtualbox

I used the FreeNAS as file server  for about 50 users and the freenas works stable as a rock from 2008 till now,which was based on a hp desktop dc5700 with 1G ram and 140G disk volume.However,with the data increasing and time went by, the stability was the most important stuff I need to consider about,so I made the backup solution to work as primary/standby to shorten the MTTR which use RSYNC,vm tech..
because I only have few days and limited resources, so maybe the solution seems a little rough…anyway,it’s ok,just change the ip will finish the taking over and the bussiness is not so real-time.

 

The difference between buffer and cache

piece of information got from wiki to clarify the difference between buffer and cache

The terms “buffer” and “cache” are not mutually exclusive and the functions are frequently combined; however, there is a difference in intent.
A buffer is a temporary memory location that is traditionally used because CPU instructions cannot directly address data stored in peripheral devices. Thus, addressable memory is used as an intermediate stage. Additionally, such a buffer may be feasible when a large block of data is assembled or disassembled (as required by a storage device), or when data may be delivered in a different order than that in which it is produced. Also, a whole buffer of data is usually transferred sequentially (for example to hard disk), so buffering itself sometimes increases transfer performance or reduces the variation or jitter of the transfer’s latency as opposed to caching where the intent is to reduce the latency. These benefits are present even if the buffered data are written to the buffer once and read from the buffer once.
A cache also increases transfer performance. A part of the increase similarly comes from the possibility that multiple small transfers will combine into one large block. But the main performance-gain occurs because there is a good chance that the same datum will be read from cache multiple times, or that written data will soon be read. A cache’s sole purpose is to reduce accesses to the underlying slower storage. Cache is also usually an abstraction layer that is designed to be invisible from the perspective of neighboring layers.

put it simple:buffer is used to slowdown the write behavior such as cpu to disk.cache is used to speedup the read behavior.(buffer是缓冲写,cache是加速读取..)

details refer:http://en.wikipedia.org/wiki/Cache#The_difference_between_buffer_and_cache

amazon RDS for oracle

amazon真是个伟大的公司!这不,在微博上看到了release amazon RDS on oracle的消息。慢慢打开了封闭企业的大门,要知道在金融行业中,oracle的占有率很高,在传统的oltp类型的应用中,能与oracle竞争的对手真不多。但是我好奇企业对于私密数据的安全性是否存有担忧?尤其在国内。

Amazon RDS for Oracle Database

Amazon RDS makes it easy to set up, operate, and scale Oracle Database deployments in the cloud. With Amazon RDS, you can deploy multiple editions of Oracle Database 11g in minutes with cost-efficient and re-sizable hardware capacity. Amazon RDS frees you up to focus on application development by managing time-consuming database administration tasks including provisioning, backups, software patching, monitoring, and hardware scaling.

You can run Amazon RDS for Oracle under two different licensing models – “License Included” and “Bring-Your-Own-License (BYOL)”. In the “License Included” service model, you do not need separately purchased Oracle licenses; the Oracle Database software has been licensed by AWS. “License Included” pricing starts at $0.16 per hour, inclusive of software, underlying hardware resources, and Amazon RDS management capabilities. If you already own Oracle Database licenses, you can use the “BYOL” model to run Oracle deployments on Amazon RDS, with rates starting at $0.11 per hour. The “BYOL” model is designed for customers who prefer to use existing Oracle database licenses or purchase new licenses directly from Oracle.

You can take advantage of hourly pricing with no upfront fees or long-term commitments. In addition, you also have the option to purchase Reserved DB Instances under one or three year reservation terms. With Reserved DB Instances, you can make low, one-time, upfront payment for each DB Instance and then pay a significantly discounted hourly usage rate, achieving up to 48% net cost savings.

详细可以参考aws的官方网站http://aws.amazon.com/rds/oracle/

indexfile is not a good solution

indexfile的方式不是一个好的解决办法。接着上一篇文章,试想如果scott用户下面的对象有几万个,还一个个去更改TABLESPACE “USERS”吗?工作量还是大了一些,当然你会说不是有vi,editplus之类的工具嘛。。。个人觉得还是unlimited tablespace权限回收的方式,比较妥当。

************************************************************************
REM  CREATE TABLE “SCOTT”.”DEPT” (“DEPTNO” NUMBER(2, 0), “DNAME”
REM  VARCHAR2(14), “LOC” VARCHAR2(13)) PCTFREE 10 PCTUSED 40 INITRANS 1
REM  MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1
REM  BUFFER_POOL DEFAULT) TABLESPACE “USERS” LOGGING NOCOMPRESS ;
CONNECT SCOTT;
CREATE UNIQUE INDEX “SCOTT”.”PK_DEPT” ON “DEPT” (“DEPTNO” ) PCTFREE 10
INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS
1 BUFFER_POOL DEFAULT) TABLESPACE “USERS” LOGGING ;
REM  ALTER TABLE “SCOTT”.”DEPT” ADD CONSTRAINT “PK_DEPT” PRIMARY KEY
REM  (“DEPTNO”) USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
REM  STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL
REM  DEFAULT) TABLESPACE “USERS” LOGGING ENABLE ;
REM  CREATE TABLE “SCOTT”.”EMP” (“EMPNO” NUMBER(4, 0), “ENAME”
REM  VARCHAR2(10), “JOB” VARCHAR2(9), “MGR” NUMBER(4, 0), “HIREDATE” DATE,
REM  “SAL” NUMBER(7, 2), “COMM” NUMBER(7, 2), “DEPTNO” NUMBER(2, 0))
REM  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536
REM  FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE “USERS”
REM  LOGGING NOCOMPRESS ;
CREATE UNIQUE INDEX “SCOTT”.”PK_EMP” ON “EMP” (“EMPNO” ) PCTFREE 10
INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS
1 BUFFER_POOL DEFAULT) TABLESPACE “USERS” LOGGING ;
REM  ALTER TABLE “SCOTT”.”EMP” ADD CONSTRAINT “PK_EMP” PRIMARY KEY
REM  (“EMPNO”) USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
REM  STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL
REM  DEFAULT) TABLESPACE “USERS” LOGGING ENABLE ;
REM  CREATE TABLE “SCOTT”.”SALGRADE” (“GRADE” NUMBER, “LOSAL” NUMBER,
REM  “HISAL” NUMBER) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
REM  STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL
REM  DEFAULT) TABLESPACE “USERS” LOGGING NOCOMPRESS ;
REM  CREATE TABLE “SCOTT”.”STATTAB” (“STATID” VARCHAR2(30), “TYPE”
REM  CHAR(1), “VERSION” NUMBER, “FLAGS” NUMBER, “C1” VARCHAR2(30), “C2”
REM  VARCHAR2(30), “C3” VARCHAR2(30), “C4” VARCHAR2(30), “C5”
REM  VARCHAR2(30), “N1” NUMBER, “N2” NUMBER, “N3” NUMBER, “N4” NUMBER,
REM  “N5” NUMBER, “N6” NUMBER, “N7” NUMBER, “N8” NUMBER, “N9” NUMBER,
REM  “N10” NUMBER, “N11” NUMBER, “N12” NUMBER, “D1” DATE, “R1” RAW(32),
REM  “R2” RAW(32), “CH1” VARCHAR2(1000), “CL1” CLOB) PCTFREE 10 PCTUSED 40
REM  INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST
REM  GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE “USERS_REORG0” LOGGING
REM  NOCOMPRESS LOB (“CL1”) STORE AS (TABLESPACE “USERS_REORG0” ENABLE
REM  STORAGE IN ROW CHUNK 8192 PCTVERSION 10 NOCACHE LOGGING
REM  STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL
REM  DEFAULT)) ;
CREATE INDEX “SCOTT”.”STATTAB” ON “STATTAB” (“STATID” , “TYPE” , “C5” ,
“C1” , “C2” , “C3” , “C4” , “VERSION” ) PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE “USERS_REORG0” LOGGING ;
REM  CREATE TABLE “SCOTT”.”TEST” (“OWNER” VARCHAR2(30), “OBJECT_NAME”
REM  VARCHAR2(128), “SUBOBJECT_NAME” VARCHAR2(30), “OBJECT_ID” NUMBER,
REM  “DATA_OBJECT_ID” NUMBER, “OBJECT_TYPE” VARCHAR2(19), “CREATED” DATE,
REM  “LAST_DDL_TIME” DATE, “TIMESTAMP” VARCHAR2(19), “STATUS” VARCHAR2(7),
REM  “TEMPORARY” VARCHAR2(1), “GENERATED” VARCHAR2(1), “SECONDARY”
REM  VARCHAR2(1), “NAMESPACE” NUMBER, “EDITION_NAME” VARCHAR2(30)) PCTFREE
REM  10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 9437184
REM  FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE
REM  “USERS_REORG0” LOGGING NOCOMPRESS ;
REM  CREATE TABLE “SCOTT”.”TEST2″ (“OWNER” VARCHAR2(30), “OBJECT_NAME”
REM  VARCHAR2(128), “SUBOBJECT_NAME” VARCHAR2(30), “OBJECT_ID” NUMBER,
REM  “DATA_OBJECT_ID” NUMBER, “OBJECT_TYPE” VARCHAR2(19), “CREATED” DATE,
REM  “LAST_DDL_TIME” DATE, “TIMESTAMP” VARCHAR2(19), “STATUS” VARCHAR2(7),
REM  “TEMPORARY” VARCHAR2(1), “GENERATED” VARCHAR2(1), “SECONDARY”
REM  VARCHAR2(1), “NAMESPACE” NUMBER, “EDITION_NAME” VARCHAR2(30)) PCTFREE
REM  10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 9437184
REM  FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE
REM  “USERS_REORG0” LOGGING NOCOMPRESS ;
REM  CREATE TABLE “SCOTT”.”TEST3″ (“OWNER” VARCHAR2(30), “OBJECT_NAME”
REM  VARCHAR2(128), “SUBOBJECT_NAME” VARCHAR2(30), “OBJECT_ID” NUMBER,
REM  “DATA_OBJECT_ID” NUMBER, “OBJECT_TYPE” VARCHAR2(19), “CREATED” DATE,
REM  “LAST_DDL_TIME” DATE, “TIMESTAMP” VARCHAR2(19), “STATUS” VARCHAR2(7),
REM  “TEMPORARY” VARCHAR2(1), “GENERATED” VARCHAR2(1), “SECONDARY”
REM  VARCHAR2(1), “NAMESPACE” NUMBER, “EDITION_NAME” VARCHAR2(30)) PCTFREE
REM  10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 9437184
REM  FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE
REM  “USERS_REORG0” LOGGING NOCOMPRESS ;
REM  CREATE TABLE “SCOTT”.”TEST4″ (“DEPTNO” NUMBER(2, 0), “DNAME”
REM  VARCHAR2(14), “LOC” VARCHAR2(13)) PCTFREE 10 PCTUSED 40 INITRANS 1
REM  MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1
REM  BUFFER_POOL DEFAULT) TABLESPACE “USERS_REORG0” LOGGING NOCOMPRESS ;
REM  CREATE TABLE “SCOTT”.”TEST5″ (“DEPTNO” NUMBER(2, 0), “DNAME”
REM  VARCHAR2(14), “LOC” VARCHAR2(13)) PCTFREE 10 PCTUSED 40 INITRANS 1
REM  MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1
REM  BUFFER_POOL DEFAULT) TABLESPACE “USERS_REORG0” LOGGING NOCOMPRESS ;
REM  ALTER TABLE “SCOTT”.”EMP” ADD CONSTRAINT “FK_DEPTNO” FOREIGN KEY
REM  (“DEPTNO”) REFERENCES “DEPT” (“DEPTNO”) ENABLE NOVALIDATE ;
REM  ALTER TABLE “SCOTT”.”EMP” ENABLE CONSTRAINT “FK_DEPTNO” ;

困惑好久的事情。。。

很多朋友希望在进行数据迁移的时候,能够将数据导入不同于原来系统的表空间,但是在导入后却发现,数据还是被导入了原表空间,也就是只跟着user变化的想法落空了,fromuser to user。。这是因为如果缺省的原用户具备unlimited tablespace权限的话,那么导入的时候会按照原来的位置导入,也就是带着storage选项,选择缺省的表空间。所以,在规划之初,建议unlimited tablespace选项还是慎重授予。

shrinking database segment online

oracle 10g开始有了一个新的功能:shrinking database segment online,shrink的本质是对表执行一系列的dml操作,可以
填满表段中的”漏洞空间”,而把所有剩余空间留在表的末端,然后oracle可以重置该表的hwm,释放自由空间。但是有代价的,
会产生大量的redo,需要斟酌。100万行的数据表,可能大概有近200M的redo开销。。

SQL> SELECT SUM(BYTES)/1024/1024 FROM DBA_EXTENTS WHERE SEGMENT_NAME=’TEST’;

SUM(BYTES)/1024/1024
——————–
30

SQL> ALTER TABLE USER.TEST ENABLE ROW MOVEMENT;

表已更改。

SQL> ALTER TABLE USER.TEST SHRINK SPACE;

表已更改。

SQL> SELECT SUM(BYTES)/1024/1024 FROM DBA_EXTENTS WHERE SEGMENT_NAME=’TEST’;

SUM(BYTES)/1024/1024
——————–
29.25
空间占用从30M降到29.25M,看来还是有一定效果的。