分成两个步骤,先修改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. Eclipse 项目有红惊叹号

    Eclipse 项目有红感叹号原因:显示红色感叹号是因为jar包的路径不对 解决:在项目上右击Build Path -> Configure Build Paht...(或Propertise- ...

  2. C++ readdir、readdir_r函数

    readdir, readdir_r - 读一个目录 readdir函数: struct dirent *readdir(DIR *dirp); The  data  returned by read ...

  3. ZetCode PyQt4 tutorial layout management

    !/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This example shows ...

  4. 中南林业科技大学第十一届程序设计大赛- I:背包问题

    链接:https://www.nowcoder.com/acm/contest/124/I来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒空间限制:C/C++ 131072K,其他语言26214 ...

  5. 7-19 PAT Judge(25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  6. C编译相关

    1,#error在编译期进行警告判断 eg: #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 和条件编译宏一起使用,在编译时就可以 ...

  7. 在IE7+ 中弹出窗口并关闭本身窗口的脚本(备忘)

    window.onload =function(){ window.open("http://www.126.com"); window.opener=null; window.o ...

  8. PostgreSQL 9.6 keepalived主从部署

    ## 环境: PostgreSQL版:9.6 角色                     OS                    IPmaster                 CentOS7 ...

  9. 【python】Beautiful Soup的使用

    1. Beautiful Soup的简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: Beautiful Soup提供一些简单的.pyt ...

  10. postman 获取时间戳的方法 和md5加密的方法

    获取时间戳方法: postman.setGlobalVariable("timestamp",Math.round(new Date().getTime()));   这整句是获取 ...