Oracle 12c: converting from AL32UTF8 to WE8MSWIN1252 - database

I have a situation where I need to convert an Oracle 12c database from NLS AL32UTF8 to WE8MSWIN1252. Based on what I've read, migration in this direction, from single byte to multibyte, is problematic, but I'm wondering if the following steps would do the trick (see below). Basically, I want to drop the project's main schema, run the alter database character set command, and then re-import the data from the original source database (this is all part of a database migration, thus I can scrap the project's main schema in the AL32UTF8 database). In other words, none of the client's data will be present during the conversion. The database will be stock/naked.
Would this work? Or will basic data dictionary tables suffer during conversion from AL32UTF8 to WE8MSWIN1252? Thank you.
The steps:
-- drop the main project schema
shutdown immediate;
startup mount;
alter system enable restricted session;
alter system set job_queue_processes=0;
alter system set aq_tm_processes=0;
alter database open;
alter database character set WE8MSWIN1252;
shutdown immediate;
startup;
-- re-import the project's schema

Related

Moving DataBase from Microsoft SQL folder to App_Data folder (appseting.json)

1. "WebApi": "Data Source=.;Initial Catalog=TaskDB; Integrated Security=true"
2. "WebApi": "Server=(localdb)\\mssqllocaldb;AttachDBFilename=%CONTENTROOTPATH%\\App_Data\\TaskDB.mdf;Trusted_Connection=true;MultipleActiveResultSets=true"
I am trying to move my DataBase from main folder of Microsoft SQL to project folder App_Data, but it does not work for some reason. I do not know why maybe my connection string is wrong. So with number 1 is working fine, but it is in main folder of Microsoft SQL, but with number 2 there is something wrong I guess
The files of database are exclusive in hand of SQL Server. You can not move database when it is online. Taking database offline, requires that no one be connected to database.
First take the database offline then try to move the files. You can take the database offline both using SSMS and query. First line of code kill all active sessions then set database multiple user; but it must be offline before anyone can connect to database so all these code must be executed together.
ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE DatabaseName SET MULTI_USER
GO
USE master
GO
ALTER DATABASE DATABASE_NAME SET OFFLINE
Be aware that when you move file to another location database could not been brought ONLINE if you do not set new filename before taking the database offline.
Use this code for all of files that you want to move them.
ALTER DATABASE TEST
MODIFY FILE (NAME = 'LOGICAL_NAME', FILENAME = 'New_Directort\Filename.mdf')
After you moved the files then bring online the database with this statement.
ALTER DATABASE DATABASE_NAME SET ONLINE
As you can see this action is not a kind, that can be done without plan. Specially with application code. When trying to do it in application code; then all session including application connection will be lost. then you can not continue the progress.

Can we remove Memory Optimized file group from database

I checked In sql server 2019(15.0.2070.41) and tried to remove with bellow mentioned command:
Alter database InMemoryCheckpoint
Remove file InMemoryCheckpointDF
Alter database InMemoryCheckpoint
Remove filegroup InMemoryCheckpointDF
You can't remove a memory-optimized filegroup.
The following limitations apply to a memory-optimized filegroup:
Once you use a memory-optimized filegroup, you can only remove it by
dropping the database. In a production environment, it is unlikely
that you will need to remove the memory-optimized filegroup.
https://learn.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/the-memory-optimized-filegroup?view=sql-server-ver15
!!! Please use this method in case of corrupted database that contains memory optimized table (you can't use DBCC check on databases that contains memory optimized tables) !!!
WARNING: This is an unsupported operation. There have been reports of unrecoverable log corruption when using this.
It's a hack method and it's risky. Microsoft didn't verified this solution
Before doing anything take backup
1- Delete memory optimized tables
2- Detach Database
3- Create new database with same files without memory optimized filegroup
4- Modify database files and change it to detached database (mdf,ldf,ndf) files
alter database test1 modify file (name='test1' , filename='C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\test.mdf')
alter database test1 modify file (name='test1_log' , filename='C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\test_log.ldf')
5- Now try to to repair database:
alter database test1 set emergency
alter database test1 set single_user with ROLLBACK IMMEDIATE;
dbcc checkdb(test1,repair_allow_data_loss)
alter database test1 set multi_user
alter database test1 set online
6- After successfully repair database remove memory optimized filegroup from database
ALTER DATABASE [test1] REMOVE FILEGROUP [memory_optimized_filegroup_0]
Follow steps correctly for prevent log corruption
Step 4: Alter log file name must be done correctly
Step 5: DBCC is Important to prevent corruption
Also for getting best result:
Don't use database while doing steps (Insert - Update - Changing
Schema)
do CHECKPOINT to flush log to data file then shrink log file
you will never have log corruption issue
Don't forget:
Before using your database do this steps for checking issue:
Insert or update 1 row in database
Do CHECKPOINT
Restart server
If database got online i think you did all steps correctly else Restore database from backup and forget about removing memory optimized filegroup
Used these commands and they worked fine for me:
USE [<dbname>]
GO
ALTER DATABASE [<dbname>] REMOVE FILE [<filename>]
GO
ALTER DATABASE [<dbname>] REMOVE FILEGROUP [<Group Name>]
GO

Oracle Database RMAN Backup not Restoring Tables or Users

I am trying to backup an Oracle 19c Database using RMAN but I seem to be running into a few hiccups. What I did first was create test tables and users in the database before backup. Within RMAN I then ran
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
With the database backed up I then dropped the test tables and users I created and starting restoring the database
RMAN> restore controlfile from 'LOCATIN OF CONTROLFILE';
RMAN> ALTER DATABASE MOUNT;
RMAN> RESTORE DATABASE;
RMAN> RECOVER DATABASE;
RMAN> ALTER DATABASE OPEN RESETLOGS;
When I then connected to the database, it is missing all the tables and users I deleted. I'm not sure whether if I needed to update my datafiles or there is a step that I am overlooking. Thank you
You have to use
Set until SCn
and provide a SCn before you are dropping the tables and and tablespaces.
You can also create a restore point before dropping tables and use rman command to restore database to restore point 'rspname'
This is impossible! Firstly, rman run with "PLUS ARCHIVELOG" so your database is currently in archivelog mode. Secondly, you restore controlfile & database then perform "COMPLETE" recovery so at the time of complete - your test tables and users must be there.
If you would have followed the steps them you must see the tables. To avoid confusion use set until time or SCN or Time
SET UNTIL SCN <scn after object creation>;
SET UNTIL SEQUENCE <seq no after table creation>;
set until time <time after table creation>;
Also pls verify did you connect to right database
Here is the example
RMAN> restore controlfile from 'LOCATIN OF CONTROLFILE';
RMAN> ALTER DATABASE MOUNT;
RMAN>RUN
{allocate channel c1 device type disk;
allocate channel c2 device type disk;
set until time '2020-03-19:15:30:00';
restore database;
recover database;
ALTER DATABASE OPEN RESETLOGS;
}

Restore Standby database failed in Oracle 11g express

I have two machine A and B and i want two setup standby database in machine B, so i have followed below steps..
Install oracle 11g express in machine A and same install in another
machine B for standby.
Enable Archive mode in both machine A and B.
Create TableSpace with name tbs_test on both machine.
Create user testuser on both machine & grant permission for dba.
In Machine A, i have create a table Tb_Employee and insert data
into table Tb_Employee on table space tbs_test.
Now take backup from some script on machine A and trying to
restore on machine B but not succeed due to some error mentioned in below statement.
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
*
ERROR at line 1:
ORA-00283: recovery session canceled due to errors
ORA-19909: datafile 1 belongs to an orphan incarnation
ORA-01110: data file 1: 'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF'
I have used following script to take backup(Full backup + Archive)
Step 1 Execute Begin Backup Script
conn / as sysdba;
alter system checkpoint;
alter tablespace SYSAUX begin backup;
alter tablespace SYSTEM begin backup;
alter tablespace TBS_Test begin backup;
exit;
Step 2 Copy SYSAUX.DBF, SYSTEM.DBF and TBS_Test.DBF files to backup directory
Step 3 create standby control file through execute following script
conn / as sysdba;
alter database backup controlfile to trace as 'C:\Backup\controlfile.txt' reuse;
alter database backup controlfile to 'C:\Backup\controlfile.ctl' reuse;
alter database create standby controlfile as 'C:\Backup\controlfile_standby.ctl';
exit
Step 4 copy stand by control file as Control.DBF into backup directory
Step 5 After copied files Execute End Backup Script
conn / as sysdba;
alter tablespace SYSAUX end backup;
alter tablespace SYSTEM end backup;
alter tablespace UNDOTBS1 end backup;
alter tablespace TBS_Test end backup;
exit;
Step 6 Execute script for Archive log
conn / as sysdba;
alter system checkpoint;
alter system archive log current;
disconnect;
exit;
Step 7 After execute script copy all archive files into backup directory("C:/Backup")
After just restore file into Machine B.
Not sure Oracle Express support standby (please consult the
documentation - as I remember Data Guard is licensed on top of
Enterprize Edition)
In order to configure standby it is not enough just to backup one
instance and restore to another - for this you will have to make
some more configurations (for example - to name instances according,
FORCE LOGGING, backup controlfile for standby, set LOG_ARCHIVE_DEST
parameters and many others, see documentation)
Your question is too "wide" we don't know what and how it has been done (put the scripts here), and in which order.

SQL Server Data Tools - Recovery Mode

I am using SQL Server Data Tools (SSDT) to manage my database schema. Every time I choose to publish changes to my schema, the script contains the following bit:
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET RECOVERY FULL
WITH ROLLBACK IMMEDIATE;
END
The problem is, I don't want it to change my recover mode to FULL. I would like it to be SIMPLE.
How can I modify my SSDT project to indicate that I want simple recovery mode, so that it will stop trying to change it to full every time I publish it?
Actually, found this option (and a lot more) within the "database settings" button in the project settings. A bit hidden IMO :)

Resources