[Oracle] oracle修改SID、DB_NAME,由默认的orcl改为chicago


本文总阅读量

1、查看sid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[oracle@dax-mysql-slave dbs]$ sql
20:06:01 SYS@ orcl> show parameter name;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string orcl
db_unique_name string orcl
global_names boolean FALSE
instance_name string orcl
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string orcl

2、关闭数据库

1
2
3
4
5
20:06:12 SYS@ orcl> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
20:06:24 SYS@ orcl> exit

3、修改相关配置配置文件

编辑/etc/oratab将orcl替换为chicago

1
2
3
[oracle@dax-mysql-slave dbs]$ vim /etc/oratab 
[oracle@dax-mysql-slave dbs]$ more /etc/oratab
chicago:/data/u01/app/oracle/product/11.2.0.4/dbhome_1:N

修改dbs目录将orcl相关的配置文件文件名替换为chicago

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[oracle@dax-mysql-slave dbs]$ cd $ORACLE_HOME/dbs
[oracle@dax-mysql-slave dbs]$ ll *orcl*
-rw-rw----. 1 oracle oinstall 1544 Mar 16 20:06 hc_orcl.dat
-rw-r--r--. 1 oracle oinstall 1177 Mar 16 19:48 initorcl.ora
-rw-r-----. 1 oracle oinstall 1536 Mar 11 02:15 orapworcl
-rw-r-----. 1 oracle oinstall 2560 Mar 16 19:50 spfileorcl.ora
[oracle@dax-mysql-slave dbs]$ mv hc_orcl.dat hc_chicago.dat
[oracle@dax-mysql-slave dbs]$ mv initorcl.ora initchicago.ora
[oracle@dax-mysql-slave dbs]$ mv orapworcl orapwchicago
[oracle@dax-mysql-slave dbs]$ mv spfileorcl.ora spfilechicago.ora
[oracle@dax-mysql-slave dbs]$ ll *orcl*
ls: cannot access *orcl*: No such file or directory
[oracle@dax-mysql-slave dbs]$ ll *chicago*
-rw-rw----. 1 oracle oinstall 1544 Mar 16 20:06 hc_chicago.dat
-rw-r--r--. 1 oracle oinstall 1177 Mar 16 19:48 initchicago.ora
-rw-r-----. 1 oracle oinstall 1536 Mar 11 02:15 orapwchicago
-rw-r-----. 1 oracle oinstall 2560 Mar 16 19:50 spfilechicago.ora

4、重新启动数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[oracle@dax-mysql-slave dbs]$ export ORACLE_SID=chicago
[oracle@dax-mysql-slave dbs]$ sql

Connected to an idle instance.
20:09:10 SYS@ chicago> startup
ORACLE instance started.
Total System Global Area 2455228416 bytes
Fixed Size 2255712 bytes
Variable Size 620758176 bytes
Database Buffers 1811939328 bytes
Redo Buffers 20275200 bytes
Database mounted.
Database opened.
20:09:28 SYS@ chicago> show parameter name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string orcl
db_unique_name string orcl
global_names boolean FALSE
instance_name string chicago
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string orcl
20:09:39 SYS@ chicago> exit

至此sid已从orcl更改为chicago,下面开始修改db_name

5、备份控制文件,并关闭数据库

1
2
3
4
5
6
7
8
9
[oracle@dax-mysql-slave dbs]$ sql
20:17:36 SYS@ chicago> alter database backup controlfile to trace resetlogs;
Database altered.
Elapsed: 00:00:00.05
20:17:45 SYS@ chicago> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
20:18:03 SYS@ chicago> exit

6、根据alert_.log日志,查看备份控制文件的路径,并复制到其他目录

1
2
3
4
[oracle@dax-mysql-slave dbs]$ cd /data/u01/app/oracle/diag/rdbms/orcl/chicago/trace/
[oracle@dax-mysql-slave trace]$ cat alert_chicago.log |grep -E "Backup controlfile written"
Backup controlfile written to trace file /data/u01/app/oracle/diag/rdbms/orcl/chicago/trace/chicago_ora_14486.trc
[oracle@dax-mysql-slave trace]$ cp /data/u01/app/oracle/diag/rdbms/orcl/chicago/trace/chicago_ora_14486.trc /tmp/chicago.sql

7、修改复制出来的控制文件

未修改之前的文件内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Trace file /data/u01/app/oracle/diag/rdbms/orcl/chicago/trace/chicago_ora_14486.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /data/u01/app/oracle/product/11.2.0.4/dbhome_1
System name: Linux
Node name: dax-mysql-slave
Release: 3.10.0-327.el7.x86_64
Version: #1 SMP Thu Nov 19 22:10:57 UTC 2015
Machine: x86_64
Instance name: chicago
Redo thread mounted by this instance: 1
Oracle process number: 26
Unix process pid: 14486, image: oracle@dax-mysql-slave (TNS V1-V3)


*** 2019-03-16 20:17:45.310
*** SESSION ID:(131.5) 2019-03-16 20:17:45.310
*** CLIENT ID:() 2019-03-16 20:17:45.310
*** SERVICE NAME:(SYS$USERS) 2019-03-16 20:17:45.310
*** MODULE NAME:(sqlplus@dax-mysql-slave (TNS V1-V3)) 2019-03-16 20:17:45.310
*** ACTION NAME:() 2019-03-16 20:17:45.310

-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="orcl"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=4
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/data/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch'
-- LOG_ARCHIVE_DEST_1='MANDATORY NOREOPEN NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM EXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=ENABLE
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/data/u01/app/oracle/oradata/orcl/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/data/u01/app/oracle/oradata/orcl/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/data/u01/app/oracle/oradata/orcl/redo03.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/data/u01/app/oracle/oradata/orcl/system01.dbf',
'/data/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/data/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/data/u01/app/oracle/oradata/orcl/users01.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/data/u01/app/oracle/product/11.2.0.4/dbhome_1
/dbs/arch1_1_1002593622.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/data/u01/app/oracle/product/11.2.0.4/dbhome_1
/dbs/arch1_1_1003088967.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/data/u01/app/oracle/oradata/orcl/temp01.dbf'
SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
--

*** 2019-03-16 20:17:54.765
Stopping background process SMCO

*** 2019-03-16 20:17:55.918
Stopping background process QMNC

*** 2019-03-16 20:17:56.918
Stopping background process MMNL

*** 2019-03-16 20:17:57.918
Stopping background process MMON

*** 2019-03-16 20:17:58.939
ksukia: Starting kill, flags = 1
ksukia: killed 0 out of 0 processes.

*** 2019-03-16 20:18:00.031
*** 2019-03-16 20:18:00.031 4329 krsh.c
ARCH: Archival disabled due to shutdown: 1089

*** 2019-03-16 20:18:01.032
*** 2019-03-16 20:18:01.032 4329 krsh.c
ARCH: Archival disabled due to shutdown: 1089

修改操作过程:

1
2
3
4
5
6
7
STARTUP NOMOUNT该行上面的内容全部删除
以--开头的内容全部删除;(vim 方法 :%s/^--.*//g)
***下的记录进程动态的内容全部删除
CREATE CONTROLFILE REUSE DATABASE替换为CREATE CONTROLFILE SET DATABASE
RECOVER DATABASE USING BACKUP CONTROLFILE加上注释--RECOVER DATABASE USING BACKUP CONTROLFILE(也可删除)
ORCL替换为CHICAGO (vim 方法 :%s/ORCL/CHICAGO/g)
orcl替换为chicago (vim 方法 :%s/orcl/chicago/g)

修改之后

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
STARTUP NOMOUNT
CREATE CONTROLFILE SET DATABASE "CHICAGO" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/data/u01/app/oracle/oradata/chicago/redo01.log' SIZE 50M BLOCKSIZE 51
2,
GROUP 2 '/data/u01/app/oracle/oradata/chicago/redo02.log' SIZE 50M BLOCKSIZE 51
2,
GROUP 3 '/data/u01/app/oracle/oradata/chicago/redo03.log' SIZE 50M BLOCKSIZE 51
2
DATAFILE
'/data/u01/app/oracle/oradata/chicago/system01.dbf',
'/data/u01/app/oracle/oradata/chicago/sysaux01.dbf',
'/data/u01/app/oracle/oradata/chicago/undotbs01.dbf',
'/data/u01/app/oracle/oradata/chicago/users01.dbf'
CHARACTER SET ZHS16GBK
;
--RECOVER DATABASE USING BACKUP CONTROLFILE
ALTER DATABASE OPEN RESETLOGS;
ALTER TABLESPACE TEMP ADD TEMPFILE '/data/u01/app/oracle/oradata/chicago/temp01.db
f' SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

8、创建pfile文件,根据pfile修改对应的数据目录,并修改pfile文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[oracle@dax-mysql-slave trace]$ sql
Connected to an idle instance.
22:23:19 SYS@ chicago> create pfile='?/dbs/initchicago.ora' from spfile;
File created.
Elapsed: 00:00:00.01
22:23:43 SYS@ chicago> exit
Disconnected

[oracle@dax-mysql-slave dbs]$ cat initchicago.ora |grep orcl
orcl.__db_cache_size=1879048192
orcl.__java_pool_size=16777216
orcl.__large_pool_size=33554432
orcl.__oracle_base='/data/u01/app/oracle','/data/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=822083584
orcl.__sga_target=2466250752
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=503316480
orcl.__streams_pool_size=0
*.audit_file_dest='/data/u01/app/oracle/admin/orcl/adump'
*.control_files='/data/u01/app/oracle/oradata/orcl/control01.ctl','/data/u01/app/oracle/oradata/orcl/control02.ctl'
*.db_name='orcl'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'

修改audit_file_dest路径

1
2
[oracle@dax-mysql-slave dbs]$ cd /data/u01/app/oracle/admin/
[oracle@dax-mysql-slave admin]$ mv orcl/ chicago/

修改数据文件路径

1
2
[oracle@dax-mysql-slave admin]$ cd /data/u01/app/oracle/oradata/
[oracle@dax-mysql-slave oradata]$ mv orcl/ chicago/

修改日志文件路径

1
2
3
4
[oracle@dax-mysql-slave oradata]$ cd /data/u01/app/oracle/diag/rdbms/
[oracle@dax-mysql-slave rdbms]$ mv orcl/ chicago/
```
根据pfile文件提示的control_files文件路径,将对应路径下的control_files删除

[oracle@dax-mysql-slave rdbms]$ cd /data/u01/app/oracle/oradata/chicago/
[oracle@dax-mysql-slave chicago]$ mv control01.ctl /tmp
[oracle@dax-mysql-slave chicago]$ mv control02.ctl /tmp

1
修改pfile文件,将文本内容orcl全部替换为chicago

[oracle@dax-mysql-slave chicago]$ more $ORACLE_HOME/dbs/initchicago.ora
chicago.db_cache_size=1879048192
chicago.
java_pool_size=16777216
chicago.large_pool_size=33554432
chicago.
oracle_base=’/data/u01/app/oracle’,’/data/u01/app/oracle’#ORACLE_BASE se
t from environment
chicago.pga_aggregate_target=822083584
chicago.
sga_target=2466250752
chicago.shared_io_pool_size=0
chicago.
shared_pool_size=503316480
chicago.__streams_pool_size=0
*.audit_file_dest=’/data/u01/app/oracle/admin/chicago/adump’
*.audit_trail=’db’
*.compatible=’11.2.0.4.0’
*.control_files=’/data/u01/app/oracle/oradata/chicago/control01.ctl’,’/data/u01/ap
p/oracle/oradata/chicago/control02.ctl’
*.db_block_size=8192
*.db_domain=’’
*.db_name=’chicago’
*.diagnostic_dest=’/data/u01/app/oracle’
*.dispatchers=’(PROTOCOL=TCP) (SERVICE=chicagoXDB)’
*.open_cursors=300
*.pga_aggregate_target=819986432
*.processes=150
*.remote_login_passwordfile=’EXCLUSIVE’
*.sga_target=2462056448
*.undo_tablespace=’UNDOTBS1’

1
2
#### 9、进入实例,恢复控制文件
创建spfile文件

[oracle@dax-mysql-slave chicago]$ sql
Connected to an idle instance.
22:33:42 SYS@ chicago> create spfile from pfile=’?/dbs/initchicago.ora’ ;
File created.

1
执行编辑完成之后的控制文件脚本

22:36:05 SYS@ chicago> @/tmp/chicagolast.sql
Control file created.
Elapsed: 00:00:03.50
Database altered.
Elapsed: 00:00:07.48
Tablespace altered.
Elapsed: 00:00:00.94

1
数据库启动,查看相关参数

22:36:26 SYS@ chicago> show parameter name;
NAME TYPE VALUE


cell_offloadgroup_name string
db_file_name_convert string
db_name string chicago
db_unique_name string chicago
global_names boolean FALSE
instance_name string chicago
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string chicago

22:36:32 SYS@ chicago> select instance_name,status from v$instance;
INSTANCE_NAME STATUS


chicago OPEN

22:36:52 SYS@ chicago> select name,open_mode from v$database;
NAME OPEN_MODE


CHICAGO READ WRITE

22:37:56 SCOTT@ chicago> exit

```
至此数据库的dbname也修改完成。

目录
  1. 1. 1、查看sid
  2. 2. 2、关闭数据库
  3. 3. 3、修改相关配置配置文件
  4. 4. 4、重新启动数据库
  5. 5. 5、备份控制文件,并关闭数据库
  6. 6. 6、根据alert_.log日志,查看备份控制文件的路径,并复制到其他目录
  7. 7. 7、修改复制出来的控制文件
  8. 8. 8、创建pfile文件,根据pfile修改对应的数据目录,并修改pfile文件

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog