Followers

Thursday, August 29, 2019

Mamun's DBA Blog: Why and How to Open Database in Restrict Mode?

As a DBA sometime you have to take database in restrict mode. Today's article will discuss the details about Database Restrict Mode. Stay Tune!!!

1. What Is Restricted Mode

When a database is placed in restricted mode, only users that have RESTRICTED SESSION privilege granted to them can connect to the database. Users that lack this privilege will get an error.
Users that are already connected to the database, prior to placing the database in restricted session, will not get disconnected. These sessions need to be manually killed after.

Why would you put a database in restricted session?
During certain maintenance task, you might want to restrict access to the database.
You want to be able to connect to the database to perform your tasks, but you do not want any other users mocking around, changing the data. Such maintenance tasks could be upgrading a database with an export/import process, fixing replicated data, deleting specific data, reorganizing tables, taking a consistent export. In these cases the restricted session is not a must, you could still proceed with the database open read write, but you might encounter some problems down the road.

2. Starting Up Database In Restricted Mode

You can start up a database in restricted mode.
Prior to starting up the database in restricted mode, you need to shutdown the running database first.
SQL> shutdown immediate;
SQL> startup restrict;
SQL> select logins from v$instance;

LOGINS
----------
RESTRICTED
 
The good thing about this method is, that all users connected to the database will get disconnected when you shutdown the database. These users will not be able to connect unless they have the RESTRICTED SESSION privilege.

3. Placing Open Database In Restricted Mode

If you do not want to shutdown the database, there is an ALTER SYSTEM command you can use to place the database in restricted mode.

SQL> alter system enable restricted session;

The downside to this method is that users already connected to the database will not get disconnected. You need to manually kill these sessions.

4. Script To Kill Existing Sessions

In order to help you kill the sessions that are sticking around after the database has been placed in restricted mode you can use the following script.
This script can be used any other time to generate the kill commands.

--check what sessions there are in the database

SELECT s.inst_id,
       s.sid,
       s.serial#,
       p.spid,
       s.username,
       s.program,
       s.sql_id
FROM   gv$session s
JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE  s.type != 'BACKGROUND'
AND    s.username not in ('SYS','SYSTEM')
ORDER BY s.inst_id,s.sid,s.serial#;


INST_ID   SID  SERIAL# SPID    USERNAME  PROGRAM            SQL_ID
------- ----- -------- ------- --------- ------------------ -------------
      1     4    33271 31370   HRAPP     JDBC Thin Client 
      1     5      369 25228   HRAPP     JDBC Thin Client   318fujwu02mz1
      1    43       59 25232   SYSADM    JDBC Thin Client   ar3mfzt410h9y
      1    46      415 25513   HRQUERY   JDBC Thin Client 

-- generate the kill command.
-- if you decide to kill the sessions, then run the generated commands.

select 'alter system kill session ' || '''' || s.sid|| ',' || s.serial# || ',@' || s.inst_id || ''';' as "Kill_Session_Command"
FROM   gv$session s
JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE  s.type != 'BACKGROUND'
AND    s.username not in ('SYS','SYSTEM')
ORDER BY s.inst_id,s.sid,s.serial#;

Kill_Session_Command
----------------------------------------
alter system kill session '4,33271,@1';
alter system kill session '5,369,@1';
alter system kill session '43,59,@1';
alter system kill session '46,415,@1';

Tuesday, July 16, 2019

Mamun's DBA Blog: Reset weblogic server admin user password

Reset WebLogic User Password: Action Plan-1
-------------------------------------------------------
1. Make sure all the services are down

2. change directory to /u01/app/middleware/user_projects/domains/bifoundation_domain/bin

cd /u01/app/middleware/user_projects/domains/bifoundation_domain/bin

3. Source the setDomainEnv.sh (Linux)/setDomainEnv.cmd(Windows)  script so we can get all the WebLogic variables set correctly

In Linux:  . /setDomainEnv.sh

In windows: setDomainEnv.cmd

4. Now change the directory to security directory in your instance.

cd /u01/app/middleware/user_projects/domains/bifoundation_domain/security

5. Move the DefaultAuthenticatorInit.ldift to a backup file

In Linux:

mv DefaultAuthenticatorInit.ldift DefaultAuthenticatorInit_old.ldift

In Windows:

mv DefaultAuthenticatorInit.ldift DefaultAuthenticatorInit_old.ldift

6. Run the “java weblogic.security.utils.AdminAccount  newuser  newpassword .” to generate a new DefaultAuthenticatorInit.ldift with a new user with the assigned password within the security directory

eg:
java weblogic.security.utils.AdminAccount weblogic weblogic123 .

Note: Replace newuser and newpassword with a user and password of your choosing. Ensure the password is a minimum of 8 characters and contains at least one numeric character.
Also, don’t forget the period “.” at the end of the above command, it is required.


7. Change directory to /u01/app/middleware/user_projects/domains/bifoundation_domain/servers/AdminServer/security

cd /u01/app/middleware/user_projects/domains/bifoundation_domain/servers/AdminServer/security/

8. Edit the boot.properties file and replace newpassword and newusername with the user and password you defined in step 6.
Do this for all the servers in the domain.

vi boot.properties

username=weblogic
password=newpassword

The boot.properties will get encrypted once the admin server starts up

9. Rename or remove directory /u01/app/middleware/user_projects/domains/bifoundation_domain/servers/AdminServer/data/ldap
as it will get recreated once the WebLogic Admin server starts.

e.g:
cd /u01/app/middleware/user_projects/domains/bifoundation_domain/servers/AdminServer/data/

mv ldap ldap_date

10. Change directory to /u01/app/middleware/user_projects/domains/bifoundation_domain/bin and start the Weblogic Admin Server

cd  /u01/app/middleware/user_projects/domains/bifoundation_domain/bin

In Linux:  ./startWebLogic.sh

In Windows: startWebLogic.cmd

11. Use new credentials to startup in startup command.Once the weblogic server is up, you’ll be able to login to Console with the new weblogic Admin user and password.

===================================================================
Reset WebLogic User Password: Action Plan-2
-------------------------------------------------------
Please try the below actionplan to change the weblogic admin password:

--> Firstly Shut down the WebLogic domain--> the managed servers, Admin Server and Node Manager.

--> Rename the data folder under the AdminServer of the domain to old_data, this is the path: %DOMAIN_HOME%/servers/AdminServer/data

--> In the same command prompt that you opened earlier, set the environment variable of the domain by calling: %DOMAIN_HOME%/bin/ --> ./setDomainEnv.sh

--> In the same command prompt, change directory to security folder: cd %DOMAIN_HOME%/security

-->Inside the %DOMAIN_HOME%/security directory, move the file "DefaultAuthenticatorInit.ldift" to "%DOMAIN_HOME%/security/old/"

--> In the next step, the command that we are going to run will create a new file “DefaultAuthenticatorInit.ldift” in the security folder

-->Run the following command to reset or change admin password:
java weblogic.security.utils.AdminAccount weblogic password .

NOTE: The DOT at the end of the above command represents the current directory. A new "DefaultAuthenticatorInit.ldift" file will be created in the current directory
when you execute the command.

--> Update the "boot.properties" file under the directory %DOMAIN_HOME%/servers/AdminServer/security/ with your username and the new password.

--> Now start the admin server using the new credentials from %DOMAIN_HOME%/bin/ --> ./startWeblogic.sh

Once the AdminServer started, login into the Admin console using the username and the new password.

Monday, May 27, 2019

Mamun's DBA Blog: How to Install & Run ORAchk


To run orachk follow the steps below...

Step 1. Download the ORAchk zip from MOS DOC ID 1268927.2 if not have downloaded.
Note: Download the 2nd one.

Step 2. Check if the directory “/opt/oracle.SupportTools/orachk” exists
     a. If the directory does not exist, create it and unzip the zip file to it.
     b. If the directory exists but ORAchk isn't installed, unzip the zip file.

Step 3. After you’ve completed the installation, you’re ready to run ORAchk from the OS command line as root
    ./orachk –a –o verbose

Step 4. Then get the report as zip by following the directed location at the end.

Wednesday, May 15, 2019

Mamun's DBA Blog: How To Check Undo Tablespace Size and Free Size in Oracle

First Connect through SQLPlus then,

SQL> select a.tablespace_name, SIZEMB, USAGEMB, (SIZEMB - USAGEMB) FREEMB
     from (select sum(bytes) / 1024 / 1024 SIZEMB, b.tablespace_name from dba_data_files a,
     dba_tablespaces b where a.tablespace_name = b.tablespace_name and b.contents = 'UNDO'
     group by b.tablespace_name) a, (select c.tablespace_name, sum(bytes) / 1024 / 1024 USAGEMB
     from DBA_UNDO_EXTENTS c where status <> 'EXPIRED'group by c.tablespace_name) b
     where a.tablespace_name = b.tablespace_name;

TABLESPACE_NAME     SIZEMB    USAGEMB        FREEMB
--------------- ---------- ---------- -------------------------------------------------
UNDOTBS1                        15360         50.6875           15309.3125
UNDOTBS2                        15360         40.5625           15319.4375

Mamun's DBA Blog: How To Check Redolog File Size in Oracle

Here we go for fetch the size of all redo logs...
SQL> set linesize 300
SQL> column REDOLOG_FILE_NAME format a45
SQL> SELECT
        a.GROUP#,
        a.THREAD#,
        a.SEQUENCE#,
        a.ARCHIVED,
        a.STATUS,
        b.MEMBER    AS REDOLOG_FILE_NAME,
        (a.BYTES/1024/1024) AS SIZE_MB
    FROM v$log a
    JOIN v$logfile b ON a.Group#=b.Group#
    ORDER BY a.GROUP# ASC;

    GROUP#    THREAD#  SEQUENCE#  ARC           STATUS                    REDOLOG_FILE_NAME                    SIZE_MB
---------- ---------- ---------- --- --------- --------------------------------------------- ---------------------------------------------------------------------
         1               1               17309           NO             CURRENT   +RECO/ieclive/onlinelog/group_1.257.860629021        200
         1               1               17309           NO              CURRENT   +DATA/ieclive/onlinelog/group_1.266.860629021       200
         2               1               17306          YES             INACTIVE  +RECO/ieclive/onlinelog/group_2.259.860629023        200
         2               1               17306          YES             INACTIVE  +DATA/ieclive/onlinelog/group_2.268.860629023        200
         3               2               30917          NO              CURRENT   +DATA/ieclive/onlinelog/group_3.261.860629087        200
         3               2               30917          NO              CURRENT   +RECO/ieclive/onlinelog/group_3.261.860629087        200
         4               2               30914         YES              INACTIVE  +DATA/ieclive/onlinelog/group_4.270.860629089         200
         4               2               30914         YES              INACTIVE  +RECO/ieclive/onlinelog/group_4.262.860629089         200
         5               1               17307         YES              INACTIVE  +RECO/ieclive/onlinelog/group_5.258.860629023         200
         5               1               17307         YES              INACTIVE  +DATA/ieclive/onlinelog/group_5.272.860629023         200
  

Mamun's DBA Blog: Gathering Table Stats in Oracle11g

Hello Visitors!!!


  • When we gather stats we are updating Optimizer to choose optimal execution plan which enhance the performance of the database.
  • We can gather stats at database level,schema level, Table level,Index level.
Table Level Stats :

SQL> Begin DBMS_STATS.GATHER_TABLE_STATS (
         ownname =>'SCOTT',
         tabname =>'EMPLOYEE',
         degree => 2,
         cascade => TRUE,
         METHOD_OPT => 'FOR COLUMNS SIZE AUTO',
         estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE);
         END;
         /


Parameters Defination:-
  • Owner-name = Schema Name which holds the table.
  • Tabname = Table Name
  • Degree  = When you set degree to some value oracle will invoke slave process which speedup the performance.
  • cascade = The cascade option can be used to analyze al the indexes.
  • METHOD_OPT (FOR COLUMNS SIZE AUTO) = Auto is the Oracle default and this option will analyze histograms  on what the optimizer considers to be "important columns". The optimizer does this by examining your current workload when you run the dbms_stats command,interrogating all current SQL in the library cache to see which columns might benefit from a histogram.
  •  estimate_percent = This argument is a new way to allow Oracle's dbms_stats to automatically   estimate  the "best" percentage of a segment to sample when gathering statistics.

Mamun's DBA Blog: How to Check Oracle Database Listener Port Status from Sql & OS Level

Hello Everyone!

You can check listener status in windows environment by using Sql & Os using Netstat.


SQL> select * from gv_$listener_network;


  
C:\Users\oracle> netstat -na |find "1521"

  TCP    0.0.0.0:1521                0.0.0.0:0                       LISTENING
  TCP    10.10.20.244:1521      10.10.20.244:49928     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49929     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49933     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49934     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49939     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:49947     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.244:50037     TIME_WAIT
  TCP    10.10.20.244:1521      10.10.20.246:50605     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:50613     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:55062     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:57671     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:57675     ESTABLISHED
  TCP    10.10.20.244:1521      10.10.20.246:57680     ESTABLISHED



C:\Users\oracle> netstat -a -o -n

Active Connections

  Proto  Local Address    Foreign Address       State           PID
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       752
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:1158           0.0.0.0:0              LISTENING       2828
  TCP    0.0.0.0:1521           0.0.0.0:0              LISTENING       1984
  TCP    0.0.0.0:1831           0.0.0.0:0              LISTENING       14504
  TCP    0.0.0.0:3389           0.0.0.0:0              LISTENING       5316