DB名変更

(8.0.22)

https://www.softel.co.jp/blogs/tech/archives/5319

use mysql

show databases;

create database test2;

rename table
test.tab1 to test2.tab1,
test.tab2 to test2.tab2;

drop database test;

 

(19c)

https://docs.oracle.com/cd/F19136_01/sutil/oracle-dbnewid-utility.html#GUID-6CC9CA73-8C0C-4750-8D0E-ADFDB047E4AE
https://dekiruengineer.com/engineer/how_to_rename_an_oracle_database_pdb/
https://www.shift-the-oracle.com/config/change-oracle_sid.html

-- CDBの場合

select * from v$database;

create pfile from spfile;
shutdown immediate;
startup mount


nid TARGET=SYS DBNAME=orcl2 SETNAME=YES

vim initorcl.ora

*.db_name='orcl'

*.db_name='orcl2'

rm -i spfileorcl.ora

orapwd file=orapworcl password=oracle force=y format=12

sqlplus / as sysdba
startup

create spfile from pfile;
shutdown immediate;
startup;

select * from v$database;

alter database rename global_name to orcl2.example.com;

ORACLE_SIDも変更する場合
shutdown immediate;

mv spfileorcl.ora spfileorcl2.ora
mv orapworcl orapworcl2

vim /etc/oratab
orcl

orcl2

export ORACLE_SID=orcl2
sqlplus / as sysdba
startup mount
alter system set instance_name='orcl2' scope=spfile;
shutdown immediate;
startup;


-- PDBの場合

show pdbs

alter pluggable database pdb1 close;
alter pluggable database pdb1 open restricted;
alter session set container=pdb1;
alter pluggable database rename global_name to pdb2;

alter pluggable database pdb2 close;
alter pluggable database pdb2 open;

show pdbs

 

(13)

\l

alter database test rename to test2;

\l

(2019)

https://docs.microsoft.com/ja-jp/sql/relational-databases/databases/rename-a-database?view=sql-server-ver15

use master;

select * from sys.databases;

alter database test set single_user with rollback immediate;
alter database test modify name = test2;
alter database test2 set multi_user;

select * from sys.databases;