ReliDB

ReliDB

Oracle tips and tricks.

ReliDB RSS Feed
 
 
 
 

Recreate Oracle User account.

Since the release of Oracle 10g and 9i, most would think that the need for scripts to recreate individual database components are unnecessary and they would be correct if you are already at Oracle 9i or 10g. Oracle 9i provides the user of the DBMS_METADATA package, which give the DBA the ability to generate the DDL for most any Oracle structure. Oracle 10g has enhanced the abilities of DBMS_METADATA and given the add value of ORACLE expdmp and impdmp, which do not require the existence of such objects as a user to transport data between databases. However, there still exist tons of Oracle 8i and earlier versions, which do not contain either of the abilities above and from which we still have to recreate individual oracle objects. This article is part of a series that covers the recreation of Oracle objects by producing the DDL from which to recreate them.

In this article we will cover the recreate of an Oracle User account in its most simple form. NOTE: We will not cover the recreation of a user defined profile or other objects an oracle user account may depend on. For that information, please see my related article Recreation of User defined Oracle Profiles.

The below script regenerates a user account:

set serveroutput on
spool c:\oradata\create_user_account.sql

declare

curr varchar2(30):= ‘TEST_USER’;
v_ext varchar2(3);

begin

for user in(select * from dba_users where username = curr)
loop

dbms_output.put_line(’create tablespace ‘||user.default_tablespace);

for dat_file in(select * from dba_data_files where
tablespace_name=user.default_tablespace)
loop

if dat_file.autoextensible=’YES’
then
v_ext:=’ON’;
else
v_ext:=’OFF’;
end if;

dbms_output.put_line(’datafile ‘||””||dat_file.file_name||””||’ size
‘||floor(dat_file.bytes/1024/1024)||’m');
dbms_output.put_line(’autoextend ‘||v_ext);
dbms_output.put_line(’maxsize ‘||floor(dat_file.maxbytes/1024/1024)||’m');
end loop;
dbms_output.put_line(’/');

dbms_output.put_line(’create user ‘||user.username||’ identified by
‘||user.username||’;');

dbms_output.put_line(’alter user ‘||user.username||’ default tablespace
‘||user.default_tablespace||’;');

dbms_output.put_line(’alter user ‘||user.username||’ temporary tablespace
‘||user.temporary_tablespace||’;');

dbms_output.put_line(’alter user ‘||user.username||’ profile
‘||user.profile||’;');

if user.account_status<>’OPEN’
then
dbms_output.put_line(’alter user ‘||user.username||’ account lock;’);
end if;

end loop;

for role in(select * from dba_role_privs where grantee=curr)
loop

if role.admin_option = ‘YES’
then
dbms_output.put_line(’grant ‘||role.granted_role||’ to ‘||role.grantee||’ with
admin option’||’;');
else
dbms_output.put_line(’grant ‘||role.granted_role||’ to ‘||role.grantee||’;');
end if;
end loop;

for sys_priv in(select * from dba_sys_privs where grantee=curr)
loop

if sys_priv.admin_option = ‘YES’
then
dbms_output.put_line(’grant ‘||sys_priv.privilege||’ to ‘||sys_priv.grantee||’
with admin option’||’;');
else
dbms_output.put_line(’grant ‘||sys_priv.privilege||’ to
‘||sys_priv.grantee||’;');
end if;
end loop;

for tab_priv in(select * from dba_tab_privs where grantee=curr)
loop

if tab_priv.grantable = ‘YES’
then
dbms_output.put_line(’grant ‘||tab_priv.privilege||’ on
‘||tab_priv.owner||’.'||tab_priv.table_name||’ to ‘||tab_priv.grantee||’ with
grant option;’);
else
dbms_output.put_line(’grant ‘||tab_priv.privilege||’ on
‘||tab_priv.owner||’.'||tab_priv.table_name||’ to ‘||tab_priv.grantee||’;');
end if;

end loop;
end;
/

spool off

The output generated by above script to recreate the TEST_USER account is listed below.

MYDB >
MYDB > set serveroutput on
MYDB > spool c:\oradata\create_user_account.sql
MYDB >
MYDB >
MYDB > declare
2
3 curr varchar2(30):= ‘TEST_USER’;
4 v_ext varchar2(3);
5
6
7 begin
8
9
10 for user in(select * from dba_users where username = curr)
11 loop
12
13
14 dbms_output.put_line(’create tablespace ‘||user.default_tablespace);
15
16 for dat_file in(select * from dba_data_files where tablespace_name=user.def
ault_tablespace)
17 loop
18
19 if dat_file.autoextensible=’YES’
20 then
21 v_ext:=’ON’;
22 else
23 v_ext:=’OFF’;
24 end if;
25
26
27 dbms_output.put_line(’datafile ‘||””||dat_file.file_name||””||’ size ‘|
|floor(dat_file.bytes/1024/1024)||’m');
28 dbms_output.put_line(’autoextend ‘||v_ext);
29 dbms_output.put_line(’maxsize ‘||floor(dat_file.maxbytes/1024/1024)||’m');
30 end loop;
31 dbms_output.put_line(’/');
32
33 dbms_output.put_line(’create user ‘||user.username||’ identified by ‘||user
.username||’;');
34
35
36 dbms_output.put_line(’alter user ‘||user.username||’ default tablespace ‘||
user.default_tablespace||’;');
37
38 dbms_output.put_line(’alter user ‘||user.username||’ temporary tablespace ‘
||user.temporary_tablespace||’;');
39
40 dbms_output.put_line(’alter user ‘||user.username||’ profile ‘||user.profil
e||’;');
41
42 if user.account_status<>’OPEN’
43 then
44 dbms_output.put_line(’alter user ‘||user.username||’ account lock;’);
45 end if;
46
47 end loop;
48
49
50 for role in(select * from dba_role_privs where grantee=curr)
51 loop
52
53
54 if role.admin_option = ‘YES’
55 then
56 dbms_output.put_line(’grant ‘||role.granted_role||’ to ‘||role.grantee||’ w
ith admin option’||’;');
57 else
58 dbms_output.put_line(’grant ‘||role.granted_role||’ to ‘||role.grantee||’;’
);
59 end if;
60
61
62 end loop;
63
64 for sys_priv in(select * from dba_sys_privs where grantee=curr)
65 loop
66
67 if sys_priv.admin_option = ‘YES’
68 then
69 dbms_output.put_line(’grant ‘||sys_priv.privilege||’ to ‘||sys_priv.grantee
||’ with admin option’||’;');
70 else
71 dbms_output.put_line(’grant ‘||sys_priv.privilege||’ to ‘||sys_priv.grantee
||’;');
72 end if;
73
74 end loop;
75
76 for tab_priv in(select * from dba_tab_privs where grantee=curr)
77 loop
78
79 if tab_priv.grantable = ‘YES’
80 then
81 dbms_output.put_line(’grant ‘||tab_priv.privilege||’ on ‘||tab_priv.owner||
‘.’||tab_priv.table_name||’ to ‘||tab_priv.grantee||’ with grant option;’);
82 else
83 dbms_output.put_line(’grant ‘||tab_priv.privilege||’ on ‘||tab_priv.owner||
‘.’||tab_priv.table_name||’ to ‘||tab_priv.grantee||’;');
84 end if;
85
86 end loop;
87 end;
88 /
create tablespace FOMIS_PROBLEM_TRACKING_BE2
datafile ‘C:\ORACLE\PRODUCT\10.1.0\ORADATA\MYDB\FOMIS_PROBLEM_TRACKING_BE2′
size 304m
autoextend ON
maxsize 4096m
/

create user TEST_USER identified by TEST_USER;
alter user TEST_USER default tablespace TEST_USER_T;
alter user TEST_USER temporary tablespace TEMP;
alter user TEST_USER profile DEFAULT;
grant CONNECT to TEST_USER;
grant CREATE JOB to TEST_USER;
grant CREATE TYPE to TEST_USER;
grant CREATE VIEW to TEST_USER;
grant CREATE TABLE to TEST_USER;
grant ALTER SESSION to TEST_USER;
grant CREATE CLUSTER to TEST_USER;
grant CREATE LIBRARY to TEST_USER;
grant CREATE SESSION to TEST_USER;
grant CREATE SYNONYM to TEST_USER;
grant CREATE TRIGGER to TEST_USER;
grant CREATE OPERATOR to TEST_USER;
grant CREATE SEQUENCE to TEST_USER;
grant CREATE DIMENSION to TEST_USER;
grant CREATE INDEXTYPE to TEST_USER;
grant CREATE PROCEDURE to TEST_USER;
grant CREATE ANY CONTEXT to TEST_USER;
grant CREATE DATABASE LINK to TEST_USER;
grant UNLIMITED TABLESPACE to TEST_USER;
grant CREATE MATERIALIZED VIEW to TEST_USER;
grant EXECUTE on SYS.DBMS_RLS to TEST_USER;
grant EXECUTE on CTXSYS.CTX_DDL to TEST_USER;
grant EXECUTE on CTXSYS.CTX_DOC to TEST_USER;

PL/SQL procedure successfully completed.

MYDB >
MYDB >

This completes the creation of SQL to regenerate a specific user account.

 

LARRY J. Catt, OCP 9i, 10g

Oracle 10g RMAN database Setup

Oracle Recovery Manager is an excellent tool for the backup and recovery of Oracle databases. It allows you to easily backup your information on scheduled bases to ensure against all forms of data loss. Additionally, it makes the process of recovering from data corruption to disk loss in a very expedient manor. The following instruction set covers the setup of an oracle database for storage of your recovery catalog and the cataloging of your first target database. This instruction set was written from a Linux installed Oracle system; however it will work on most any flavor of UNIX.

1. Logon to your linux server as the Oracle software owner.

2. Use the ./dbca command as follows to open up the Oracle Database Creation Assistant or create a database named RMAN manually. Note: This oracle database is only used to store the catalog information of backed-up databases, thus the storage and memory requirements are very low. I would not allocate more than 200MB of space and 100MB of memory to this database.

linux1# cd $ORACLE_HOME/bin
linux1#
linux1# ./dbca

3. If using dbca, follow the prompted screens to create a general purpose database.

4. If the database is created using manual methods ensure that the following Oracle scripts are executed after build.

connect sys/oracle@RMAN as sysdba
set echo off
@?/rdbms/admin/catalog
@?/rdbms/admin/catproc
@?/rdbms/admin/catrep
@?/rdbms/admin/catexp
@?/rdbms/admin/catldr
@?/rdbms/admin/dbmsutil
@?/rdbms/admin/prvtutil.plb
@?/rdbms/admin/dbmssql
@?/rdbms/admin/prvtsql.plb
@?/rdbms/admin/dbmsdefr
@?/rdbms/admin/prvtdefr.plb
@?/rdbms/admin/catqueue
@?/rdbms/admin/dbmsaqad
@?/rdbms/admin/prvtaqad.plb
@?/rdbms/admin/catcr
@?/rdbms/admin/prvtcr.plb
connect system/oracle@RMAN
@?/rdbms/admin/catdbsyn
@?/sqlplus/admin/pupbld.sql
conn sys/oracle@RMAN as sysdba
@?/rdbms/admin/utlrp

5. Logon to your newly created database and create a tablespace for the RMAN user with the following command.

create tablespace rman
datafile ‘/u05/oradata/RMAN/rman01.dbf’ size 200m
extent management local autoallocate
segment space management auto;

6. Logon to your newly created database and create the RMAN User with the following command. Then grant the RMAN user the privileges: recovery_catalog_owner, connect, and resource.

create user rman identified by rman
temporary tablespace temp
default tablespace rman quota unlimited on rman;

grant recovery_catalog_owner to rman;

grant connect,resource to rman;

7. Add the following text to the listener.ora file on the server hosting the RMAN database and ensure that an entry is listed on all database servers to be backed-up in their individual tnsnames.ora files for the newly created RMAN database.

(SID_DESC =
(ORACLE_HOME = /u01/opt/app/oracle/product/10.2.0/Db_1)
(SID_NAME = RMAN1)
)

8. Issue a stop and restart of the oracle listener for changes to take affect.

linux1# lsnrctl stop

linux1# lsnrctl start

9. Register the target database in the catalog.

10. Logon to your server and set the ORACLE_SID parameter to your target database.

linux1# echo $ORACLE_SID

linux1# ORACLE_SID=orcl
linux1# export ORACLE_SID
linux1# echo $ORACLE_SID
orcl
linux1#

11. Execute the command , to logon to the RMAN utility.

linux1# rman target / catalog rman/rman@RMAN

Recovery Manager: Release 10.2.0.2.0 - Production on Wed Sep 24 15:42:29 2008

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

connected to target database: ORCL (DBID=3051662701)
connected to recovery catalog database

RMAN>

12. Issue the command in the RMAN utility.

RMAN> create catalog

recovery catalog created

RMAN>

13. Issue the command in the RMAN utility.

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN>

14. NOTE: By default RMAN will attempt to register a TAPE drive in the system. If you do not have a tape drive available specify.

RMAN> CONFIGURE CHANNEL DEVICE TYPE ‘SBT_TAPE’ clear;

old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE ‘SBT_TAPE’ MAXPIECESIZE 10 G;
old RMAN configuration parameters are successfully deleted
starting full resync of recovery catalog
full resync complete

This completes the creation of RMAN recovery catalog and registration of your target database.

Larry Catt, OCP 9i, 10g

Recreating Oracle 10g EM

Oracle 10g Enterprise Manager has been a vast improvement over previous versions. However, I have experienced several situation where its behavior has become very unpredictable due to changes to DBSNMP or SYSMAN schemas and changes made to the your EM configuration files. In these situations, I have found it much easier to remove the EM components and re-install to resolve the problems. NOTE: This may not always be your best option; some objects created in EM may no longer exist after performing this procedure. However, EM will work without error itself.

1. Login to your Oracle server as the oracle software owner, set your ORACLE_SID and shutdown your Oracle EM console.

[root@linux1 ~]# su - oracle
[oracle@linux1 ~]$ ORACLE_SID=orcl
[oracle@linux1 ~]$ export ORACLE_SID
[oracle@linux1 ~]$ emctl stop dbconsole
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://linux1:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 10g Database Control …
… Stopped.
[oracle@linux1 ~]$

2. Startup the Oracle universal installer, located under $ORACLE_HOME/oui/bin directory. The shell script to execute the installer is runInstaller.

3. At the welcome screen select deinstall Products.

4. At the Inventory screen, expand the tabs Oracle Home and Oracle Database to show all installed components. Ensure that only Oracle Enterprise Manager is selected and press the Remove button.

5. At the Confirmation screen, press the Yes button to continue.

6. The Oracle Universal Installer will remove all Oracle Enterprise Manager components.

7. After the uninstall is complete, the Oracle Universal Installer will return you to the Inventory screen, press the Close button to exit the installer.

8. Login to SQL*Plus with as sysdba and drop the user schemas dbsnmp and sysman with the cascade clause.

login as: oracle
oracle@linux1’s password:
Last login: Mon Jan 14 11:31:32 2008 from 192.168.1.101
[oracle@linux1 ~]$ ORACLE_SID=orcl
[oracle@linux1 ~]$ export ORACLE_SID
[oracle@linux1 ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jan 14 13:47:52 2008

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

SQL> connect / as sysdba
SQL> drop user sysman cascade;
User dropped.
SQL> drop user dbsnmp cascade;
User dropped.
SQL>

9. Now execute the script catsnmp.sql located in $ORACLE_HOME/rdbms/admin to recreate the dbsnmp schema.

SQL>$ORACLE_HOME/rdbms/admin/catsnmp.sql

10. Startup the Oracle universal installer, located under $ORACLE_HOME/oui/bin directory. The shell script to execute the installer is runInstaller.
11. At the welcome screen select Next button.

12. At the Specify Source Location page, enter the directory where you unzipped your oracle database software and select Next.

13. At the Select Installation Type, select the Custom radio button and press Next.

14. At the Specify Home Details, enter the Home name and default path for installation and press Next.

15. You will receive a Warning message stating the directory is not empty. Select Yes to continue.

16. At the Available Products Components page, ensure that only Oracle Enterprise Manger is select and press Next button.

17. At the Product-Specific Prerequisite Checks page, select Next.

18. At the Summary page, select the Install button.

19. The Oracle Enterprise Manger will now install.

20. Once the End of Installation page is display, select the exit button.

21. Logon to your Oracle host machine console as the oracle software owner and set your ORACLE_SID variable.

login as: oracle
oracle@linux1’s password:
Last login: Mon Jan 14 11:31:32 2008 from 192.168.1.101
[oracle@linux1 ~]$ ORACLE_SID=orcl
[oracle@linux1 ~]$ export ORACLE_SID

22. Startup the em console and test your connection.

[oracle@linux1 ~]$ emctl start dbconsole
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://linux1:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 10g Database Control ……………….. started.
——————————————————————
Logs are generated in directory /u01/oracle/oracle/product/10.2.0/db_1/linux1_orcl/sysman/log
[oracle@linux1 ~]$

23. Test your connect to the dbconsole at reference address in the emctl start command: normally this would be http://<machine_name>:1158/em

 

 

Larry Catt, OCP 9i, 10g

Popular Posts

Recent Comments

Links

Meta