分成两个步骤,先修改instance_name,在修改db_name

修改SID
1.全备份数据库
RMAN> backup as compressed backupset database include current controlfile plus archivelog delete all input ;
(DBID=1698783370)
2.改环境变量中的ORACLE_SID
vi .bash_profile
3.改参数文件名称initSID.ora
mv initSBBB.ora initSBDB.ora

4.改数据文件和日志文件路径
SQL> startup mount pfile='/opt/oracle/product/11.1.0/db_1/dbs/initSBDB.ora';
$ cp *.dbf ../SBDB/
SQL> alter database rename file '/opt/oracle/oradata/SBBB/sysaux.dbf' to '/opt/oracle/oradata/SBDB/sysaux.dbf' ;
SQL> alter database rename file '/opt/oracle/oradata/SBBB/system.dbf' to '/opt/oracle/oradata/SBDB/system.dbf' ;
SQL> alter database rename file '/opt/oracle/oradata/SBBB/temp01.dbf' to '/opt/oracle/oradata/SBDB/temp01.dbf' ;
SQL> alter database rename file '/opt/oracle/oradata/SBBB/undotbs1.dbf' to '/opt/oracle/oradata/SBDB/undotbs1.dbf' ;
SQL> alter database rename file '/opt/oracle/oradata/SBBB/users01.dbf' to '/opt/oracle/oradata/SBDB/users01.dbf' ;
SQL> alter database rename file '/opt/oracle/oradata/SBBB/redo1.log' to '/opt/oracle/oradata/SBDB/redo1.log' ;
SQL> alter database rename file '/opt/oracle/oradata/SBBB/redo2.log' to '/opt/oracle/oradata/SBDB/redo2.log' ;
SQL> alter database rename file '/opt/oracle/oradata/SBBB/redo3.log' to '/opt/oracle/oradata/SBDB/redo3.log' ;

5.改密码文件
6.启动数据库,并做一个全库备份

接下来修改DB_NAME
1.先关闭后启动到mount状态
SQL> alter database mount ;

Database altered.

SQL>
SQL>
SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

2.使用ORACLE自带的nid工具,ORACLE需要启动到mount
$ nid target=sys/ocmb123 as sysdba dbname=SBDB

DBNEWID: Release 11.1.0.6.0 - Production on Mon Mar 17 20:29:23 2014

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Password:
Connected to database SBBB (DBID=1698783370)

Connected to server version 11.1.0

Control Files in database:
/opt/oracle/oradata/SBDB/control1.ctl
/opt/oracle/oradata/SBDB/control2.ctl
/opt/oracle/oradata/SBDB/control3.ctl

Change database ID and database name SBBB to SBDB? (Y/[N]) => Y

Proceeding with operation
Changing database ID from 1698783370 to 1234663846
Changing database name from SBBB to SBDB
Control File /opt/oracle/oradata/SBDB/control1.ctl - modified
Control File /opt/oracle/oradata/SBDB/control2.ctl - modified
Control File /opt/oracle/oradata/SBDB/control3.ctl - modified
Datafile /opt/oracle/oradata/SBDB/system.dbf - dbid changed, wrote new name
Datafile /opt/oracle/oradata/SBDB/sysaux.dbf - dbid changed, wrote new name
Datafile /opt/oracle/oradata/SBDB/undotbs1.dbf - dbid changed, wrote new name
Datafile /opt/oracle/oradata/SBDB/users01.dbf - dbid changed, wrote new name
Datafile /opt/oracle/oradata/SBDB/temp01.dbf - dbid changed, wrote new name
Control File /opt/oracle/oradata/SBDB/control1.ctl - dbid changed, wrote new name
Control File /opt/oracle/oradata/SBDB/control2.ctl - dbid changed, wrote new name
Control File /opt/oracle/oradata/SBDB/control3.ctl - dbid changed, wrote new name
Instance shut down

Database name changed to SBDB.
Modify parameter file and generate a new password file before restarting.
Database ID for database SBDB changed to 1234663846.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.
修改成功后,数据库会关闭。

3.修改initSBDB.ora里面的db_name=SBDB
SQL> startup mount pfile='/opt/oracle/product/11.1.0/db_1/dbs/initSBDB.ora';
ORACLE instance started.

Total System Global Area 523108352 bytes
Fixed Size 1301024 bytes
Variable Size 318768608 bytes
Database Buffers 197132288 bytes
Redo Buffers 5906432 bytes
Database mounted.
SQL>
SQL>
SQL>
SQL> alter database open resetlogs ;

Database altered.

至此数据库完全打开,instance_name,db_name全部改好。
还有一种方法不用nid,直接重建控制文件。
alter database backup controlfile to trace resetlogs ;
trace文件中会生成create controlfile的语句,相对比较麻烦,有兴趣可以尝试下。

另一种修改DB_NAME的大致思路:
1.alter system switch logifle;
2.alter database backup controlfile to trace resetlogs ;
3.shutdown immediate
4.user_dump_dest 查看trace文件
5拷贝出create controlfile 语句,REUSE改成set ,dbnam改成新的
6.改名control files,为了备份
7.改参数文件中db_name
8.执行重建控制文件的语句,如果报错
recover database using backup controlfile until cancel ;
如果继续报错,提供状态为CURRENT的日志 v$log;
select group#,seq#,status from v$log ;
9.alter database open resetlogs ;
10.增加新的TEMP文件
alter tablespace temp add tempfile '/opt/oracle/oradata/...' size 100m resue autoextend on next 10m maxsize 32767m ;
11.改全局数据库名
alter database rename global_name to **
12.全备数据库
13.确认dbsnmp.bsln_baselines的DBID ,INSTANCE_NAME已经更改。

修改数据库的instance_name和db_name的更多相关文章

  1. 查看mysql字符集、修改数据库、数据表、字段字符集

    查看所有表的字符集 SELECT table_name, table_type, engine, version, table_collation FROM information_schema.ta ...

  2. Oracle NID工具修改数据库DBID、数据库名称、数据库实例名

    DBID是数据库的唯一标识符,在一些特殊场合会涉及到DBID的相关内容,本篇文章的目的是演示将DB_NAME的值从ORCL修改为ORCL1. 一.查看当前的环境 [oracle@oracledb ad ...

  3. MySQL创建和修改数据库语法

    1.创建数据库语法: CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name    [create_specification [, create_spe ...

  4. 怎样在mysql里面修改数据库名称

    怎样在mysql里面修改数据库名称       提供三种方法:1. RENAME DATABASE db_name TO new_db_name这个..这个语法在mysql 5.1.7中被添加进来,到 ...

  5. MySQL修改数据库、表、列、外键字符编码和排序编码

    在重启Confluence应用时,突然遇见这个检查错误,查询总结需要修改Mysql数据库的所有字符编码和排序编码,报错如下: Confluence Help – This installation o ...

  6. activiti部署流程定义时出错:INSERT INTO ACT_GE_BYTEARRAY,修改数据库编码

    activiti部署流程定义时出错 // 部署流程定义 Deployment deployment = deploymentBuilder.deploy(); 错误信息:(有乱码的...没留下截图.. ...

  7. SQL SERVER 2005修改数据库名称,包括物理文件名和逻辑名称

    SQL SERVER 2005修改数据库名称,包括物理文件名和逻辑名称   原来数据库名称为 aa,物理文件名称为 aa.mdf 和 aa_log.ldf:   需要修改数据库名称为 bb,物理文件名 ...

  8. SQL Server修改数据库对象所有者(Owner)浅析

    在SQL Server数据库中如何修改数据库对象(表.视图.存储过程..)的所有者(Owner)呢?一般我们可以使用系统提供的系统存储过程sp_changeobjectowner来修改. 我们先看看s ...

  9. SQL SERVER 2012 修改数据库默认位置不立即生效

    今天修改SQL SERVER 2012的数据库默认位置:即数据文件.日志文件默认位置时遇到一个问题,单击"服务器属性"(Server Properties)--> 数据库设置 ...

随机推荐

  1. leetcode122 买卖股票的最佳时机 python

    题目:给定一个数组,它表示了一只股票的价格浮动,第i个元素代表的是股票第i天的价格.设计一个函数,计算出该股票的最大收益,注意,可以多次买入卖出,但下一次买入必须是在本次持有股票卖出之后.比如[1,7 ...

  2. 基于zookeeper简单实现分布式锁

    https://blog.csdn.net/desilting/article/details/41280869 这里利用zookeeper的EPHEMERAL_SEQUENTIAL类型节点及watc ...

  3. 华为荣耀7i手动更改DNS,提高网页加载速度

    为什么在同样的Wi-Fi网络下,别人的手机可以秒开网页,但自己的手机却总会慢个半拍或是经常打不开,简直龟速.有时还会加载网页失败.我想大部分人都遇到过吧. 今天本人给大家介绍一种方法,可以加快打开网页 ...

  4. BZOJ1095: [ZJOI2007]Hide 捉迷藏【动态点分治】

    Description 捉迷藏 Jiajia和Wind是一对恩爱的夫妻,并且他们有很多孩子.某天,Jiajia.Wind和孩子们决定在家里玩 捉迷藏游戏.他们的家很大且构造很奇特,由N个屋子和N-1条 ...

  5. Python源码分析之dis

    一.简单例子 def add(a, b): return a + b add_nums.py import foo a = [1, 'python'] a = 'a string' def func( ...

  6. [LeetCode系列] 跳跃问题II

    给定一系列非负整数, 每个值代表从此下标可以向前跳跃的最远距离, 试求出跳跃到数组尾端需要的最少步骤. 如给定 [2,3,1,1,4], 返回2. (从下标0跳到1, 从1跳到下标4). 算法描述: ...

  7. CentOS 6.0 VNC远程桌面配置方法(转帖)

    问题:新装开发机,安装VNC软件后,按照下面文档配置后,无法用VNC view连接,关闭防火墙后可以连上 解决方法:说明问题出在防火墙配置上,除了允许15900端口外,还有其他要设,经过排查后,加上如 ...

  8. android adb端口被占用解决方法

    1.输入adb devices命令 C:\Users\Nick>adb devices List of devices attached adb server version (31) does ...

  9. AngularJS资源大集锦

    AngularJS最近貌似很火,前段时间,CSDN的编辑专访了AngularJS创始人Misko Hevery.这不,Tuts+网站编辑Rey Bango应广大读者需要,把各种极好的AngularJS ...

  10. 爬取爱奇艺电视剧url

    ----因为需要顺序,所有就用串行了---- import requests from requests.exceptions import RequestException import re im ...