Thursday, December 3, 2020

Replication and auto-failover

 

Step 1. Make sure MySQL Servers are configured correctly

For some of the utilities, it’s important that you’re using Global Transaction IDs; binary logging needs to be enabled; may as well use the new crash-safe slave functionality… It’s beyond the scope of this post to go through all of those and so instead I’ll just give example configuration files for the 5 MySQL Servers that will be used:

my1.cnf

[mysqld]
binlog-format=ROW
log-slave-updates=true
gtid-mode=on
disable-gtid-unsafe-statements=true # Use enforce-gtid-consistency from 5.6.9+
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
datadir=/home/billy/mysql/data1
server-id=1
log-bin=util11-bin.log
report-host=utils1
report-port=3306
socket=/home/billy/mysql/sock1
port=3306

my2.cnf

[mysqld]
binlog-format=ROW
log-slave-updates=true
gtid-mode=on
disable-gtid-unsafe-statements=true # Use enforce-gtid-consistency from 5.6.9+
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
datadir=/home/billy/mysql/data2
server-id=2
log-bin=util12-bin.log
report-host=utils1
report-port=3307
socket=/home/billy/mysql/sock2
port=3307

my3.cnf

[mysqld]
binlog-format=ROW
log-slave-updates=true
gtid-mode=on
disable-gtid-unsafe-statements=true # Use enforce-gtid-consistency from 5.6.9+
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
datadir=/home/billy/mysql/data3
server-id=3
log-bin=util2-bin.log
report-host=utils2
report-port=3306
socket=/home/billy/mysql/sock3
port=3306

my4.cnf

[mysqld]
binlog-format=ROW
log-slave-updates=true
gtid-mode=on
disable-gtid-unsafe-statements=true # Use enforce-gtid-consistency from 5.6.9+
master-info-repository=TABLE
relay-log-info-repository=TABLE
master-info-file=/home/billy/mysql/master4.info
datadir=/home/billy/mysql/data4
server-id=4
log-bin=util4-bin.log
report-host=utils2
report-port=3307
socket=/home/billy/mysql/sock4
port=3307

my5.cnf

[mysqld]
binlog-format=ROW
log-slave-updates=true
gtid-mode=on
disable-gtid-unsafe-statements=true # Use enforce-gtid-consistency from 5.6.9+
datadir=/home/billy/mysql/data5
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
#master-info-file=/home/billy/mysql/master5.info
server-id=5
log-bin=util5-bin.log
report-host=utils2
report-port=3308
socket=/home/billy/mysql/sock5
port=3308

The utilities are actually going to be run from a remote host and so it will be necessary for that host to access each of the MySQL Servers and so a user has to be granted remote access (note that the utilities will automatically create the replication user):

[vivek@dba1 ~]$ mysql -h 127.0.0.1 -P3306 -u root -e "grant all on *.* to root@'%' with grant option;"

[vivek@dba1 ~]$ mysql -h 127.0.0.1 -P3307 -u root -e "grant all on *.* to root@'%' with grant option;"

[vivek@dba2 ~]$ mysql -h 127.0.0.1 -P3306 -u root -e "grant all on *.* to root@'%' with grant option;"

[vivek@dba2 ~]$ mysql -h 127.0.0.1 -P3307 -u root -e "grant all on *.* to root@'%' with grant option;"

[vivek@dba2 ~]$ mysql -h 127.0.0.1 -P3308 -u root -e "grant all on *.* to root@'%' with grant option;"

Set up replication

While there are extra options (such as specifying what username/password to use for the replication user or providing a password for the root user) I’m going to keep things simple and use the defaults as much as possible. The following commands are run from the MySQL Utilities terminal – just click on the pocket-knife icon in MySQL Workbench.

mysqlreplicate --master=root@utils1:3306 --slave=root@utils1:3307
# master on utils1: ... connected.
# slave on utils1: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.

mysqlreplicate --master=root@utils1:3306 --slave=root@utils2:3306
# master on utils1: ... connected.
# slave on utils2: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.

mysqlreplicate --master=root@utils1:3306 --slave=root@utils2:3307
# master on utils1: ... connected.
# slave on utils2: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.

mysqlreplicate --master=root@utils1:3306 --slave=root@utils2:3308
# master on utils1: ... connected.
# slave on utils2: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.

That’s it, replication has now been set up from one master to four slaves.

You can now check that the replication topology matches what you intended:

mysqlrplshow --master=root@utils1 --discover-slaves-login=root;
# master on utils1: ... connected.
# Finding slaves for master: utils1:3306

# Replication Topology Graph
utils1:3306 (MASTER)
   |
   +--- utils1:3307 - (SLAVE)
   |
   +--- utils2:3306 - (SLAVE)
   |
   +--- utils2:3307 - (SLAVE)
   |
   +--- utils2:3308 - (SLAVE)

Additionally, you can also check that any of the replication relationships is correctly configure:

mysqlrplcheck --master=root@utils1 --slave=root@utils2
# master on utils1: ... connected.
# slave on utils2: ... connected.
Test Description                                                     Status
---------------------------------------------------------------------------
Checking for binary logging on master                                [pass]
Are there binlog exceptions?                                         [pass]
Replication user exists?                                             [pass]
Checking server_id values                                            [pass]
Is slave connected to master?                                        [pass]
Check master information file                                        [pass]
Checking InnoDB compatibility                                        [pass]
Checking storage engines compatibility                               [pass]
Checking lower_case_table_names settings                             [pass]
Checking slave delay (seconds behind master)                         [pass]
# ...done.

Including the -s option would have included the output that you’d expect to see from SHOW SLAVE STATUSG on the slave.

Automated monitoring and failover

The previous section showed how you can save some serious time (and opportunity for user-error) when setting up MySQL replication. We now look at using the utilities to automatically monitor the state of the master and then automatically promote a new master from the pool of slaves. For simplicity I’ll stick with default values wherever possible but note that there are a number of extra options available to you such as:

  • Constraining which slaves are eligible for promotion to master; the default is to take the most up-to-date slave
  • Binding in your own scripts to be run before or after the failover (e.g. inform your application to switch master?)
  • Have the utility monitor the state of the servers but don’t automatically initiate failover

Here is how to set it up:

mysqlfailover --master=root@utils1:3306 --discover-slaves-login=root --rediscover

MySQL Replication Failover Utility
Failover Mode = auto     Next Interval = Wed Aug 15 13:19:30 2012

Master Information
------------------
Binary Log File    Position  Binlog_Do_DB  Binlog_Ignore_DB
util11-bin.000001  2586

Replication Health Status
+---------+-------+---------+--------+------------+---------+
| host    | port  | role    | state  | gtid_mode  | health  |
+---------+-------+---------+--------+------------+---------+
| utils1  | 3306  | MASTER  | UP     | ON         | OK      |
| utils1  | 3307  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3306  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3307  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3308  | SLAVE   | UP     | ON         | OK      |
+---------+-------+---------+--------+------------+---------+

Q-quit R-refresh H-health G-GTID Lists U-UUIDs

mysqlfailover will then continue to run, refreshing the state – just waiting for something to go wrong.

Rather than waiting, I kill the master MySQL Server:

mysqladmin -h utils1 -P3306 -u root shutdown

Checking with the still-running mysqlfailover we can see that it has promoted utils1:3307.

MySQL Replication Failover Utility
Failover Mode = auto     Next Interval = Wed Aug 15 13:21:13 2012

Master Information
------------------
Binary Log File    Position  Binlog_Do_DB  Binlog_Ignore_DB
util12-bin.000001  7131

Replication Health Status
+---------+-------+---------+--------+------------+---------+
| host    | port  | role    | state  | gtid_mode  | health  |
+---------+-------+---------+--------+------------+---------+
| utils1  | 3307  | MASTER  | UP     | ON         | OK      |
| utils2  | 3306  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3307  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3308  | SLAVE   | UP     | ON         | OK      |
+---------+-------+---------+--------+------------+---------+

Q-quit R-refresh H-health G-GTID Lists U-UUIDs

Add the recovered MySQL Server back into the topology

After restarting the failed MySQL Server, it can be added back into the mix as a slave to the new master:

mysqlreplicate --master=root@utils1:3307 --slave=root@utils1:3306
# master on utils1: ... connected.
# slave on utils1: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.

The output from mysqlfailover (still running) confirms the addition:

MySQL Replication Failover Utility
Failover Mode = auto     Next Interval = Wed Aug 15 13:24:38 2012

Master Information
------------------
Binary Log File    Position  Binlog_Do_DB  Binlog_Ignore_DB
util12-bin.000001  7131

Replication Health Status
+---------+-------+---------+--------+------------+---------+
| host    | port  | role    | state  | gtid_mode  | health  |
+---------+-------+---------+--------+------------+---------+
| utils1  | 3307  | MASTER  | UP     | ON         | OK      |
| utils1  | 3306  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3306  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3307  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3308  | SLAVE   | UP     | ON         | OK      |
+---------+-------+---------+--------+------------+---------+

Q-quit R-refresh H-health G-GTID Lists U-UUIDs

If it were important that the recovered MySQL Server be restored as the master then it is simple to manually trigger the promotion (after quitting out of mysqlfailover):

mysqlrpladmin --master=root@utils1:3307 --new-master=root@utils1:3306 --demote-master 
  --discover-slaves-login=root switchover

# Discovering slaves for master at utils1:3307
# Checking privileges.
# Performing switchover from master at utils1:3307 to slave at utils1:3306.
# Checking candidate slave prerequisites.
# Waiting for slaves to catch up to old master.
# Stopping slaves.
# Performing STOP on all slaves.
# Demoting old master to be a slave to the new master.
# Switching slaves to new master.
# Starting all slaves.
# Performing START on all slaves.
# Checking slaves for errors.
# Switchover complete.
#
# Replication Topology Health:
+---------+-------+---------+--------+------------+---------+
| host    | port  | role    | state  | gtid_mode  | health  |
+---------+-------+---------+--------+------------+---------+
| utils1  | 3306  | MASTER  | UP     | ON         | OK      |
| utils1  | 3307  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3306  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3307  | SLAVE   | UP     | ON         | OK      |
| utils2  | 3308  | SLAVE   | UP     | ON         | OK      |
+---------+-------+---------+--------+------------+---------+
# ...done.

Friday, May 8, 2020

Getting Started with Oracle Server - DBA TOOLS

By Using these listed of tools,utility we can reach our goals as a "Database Administrator".
(1)OUI  - ORACLE UNIVERSAL INSTALLER
(2)DBCA - DATABASE CONFIGURATION ASSISTANCE
(3)DBUA - DATABASE UPGRADATION  ASSISTANCE
(4)NETCA - NET CONFIGURATION ASSISTANT
(5)NETMGR - NET MANAGER
(6)SQL*PLUS
(7)ISQL*PLUS
(8)EXP/IMP - EXPORT / IMPORT
(9)DATAPUMP - EXPDP / IMPDP
(10)SQL*LOADER - USE TO LOAD DATA FROM FLAT FILES INTO  DATABASE
(11)OEM - ORACLE ENTERPRISE MANAGER
(12)DBSTART - AUTOMATIC START UP ORACLE DATABASE
13)DBSHUT -  AUTOMATIC SHUT DOWN ORACLE DATABASE
let us  see  uses of Database tools
(1) OUI (ORACLE UNIVERSAL INSTALLER):                                     
  - It's java based installer   that enables to you install oracle components               
  - It's main Purpose is install & uninstall  software               
  - It's enables to "Upgrade " from one version into another version
(2) DBCA (DATABASE CONFIGURATION ASSISTANCE)                 
  - By Using these tool we can create  or delete the Database               
  - It's easiest  method of creating  database and this utility is typically located in
 ORACLE_HOME/bin
(3) DBUA (DATABASE UPGRADATION  ASSISTANCE)               
  - It help us to  through the upgrade process and configures the database for the new release.             
  - It also  supports RAC(Real Application Cluster ) and ASM (Automatic Storage Management)          - Before Upgradation it's has stated pre upgradation check for             
      * Any invalid user accounts or roles             
      * Any invalid datatypes or invalid objects             
      * Any desupported character sets             
      * Adequate resources, including rollback segments,tablespaces, and free diskspace             
      * Backs up all necessary files (optional).             
      * Any missing SQL scripts needed for the upgrade             
  - After  completion pre upgradation checks its automatically accomplish below  listed             
     * Modifies or creates new required tablespaces             
     * Invokes the appropriate upgrade scripts             
     * Archives redo logs             
     * Disables archiving during the upgrade phase             
 (4) NETCA (NET CONFIGURATION ASSISTANT )             
  - It's a Wizard based tool with a graphical user interface             
  - It Main Purpose is to configure the  listener names and protocol(IP) addresses             
 (5) NETMGR (NET MANAGER)              
  - It's a Graphical User InterFace  tool               
  - It can be used on client or server side             
  - It's integrated with  OEM (Oracle Enterprise Manager)             
  - By using these utility we can create below network components             
     * Naming             
     * Naming Methods             
     * Profiles             
     * Listeners             
 - Netca is a configuration Utility it is used to configure the tns and listener files.             
 - Netmgr is used to monitor the status of listener and find the connectivity issues.             
 (6)  SQL*PLUS &  ISQL*PLUS             
 - It's command line user interface ,Windows Graphical User Interface (GUI)             
 - SQL*PLUS is a client server using SQL, PL/SQL and special commands against an Oracle DB         - ISQL*PLUS is a  ( web-based user interface ) web browser version of SQL*PLUS             
 - Major differences of ISQL*PLUS is we can save the Query and Result in HTML Table format
(8) EXP/IMP  (EXPORT / IMPORT)             
 - It's a traditional  method of taking backup (logical  backup method)             
 - When  exporting a database objects are stored in a  binary file format which can be  imported into another oracle database             
 - We can perform  exp/imp between  the oracle databases and we cannot export data and  apply to import it into a non-Oracle database.             
 (9) DATAPUMP (EXPDP / IMPDP)             
 - Its a replacement  of  Exp/imp , the old export/ import tools are still available but not supported all oracle 10g and  11g features.The new utilities are called EXPDP / IMPDP             
 - Compare to exp/imp data pump  had much options like we can see the job status,stop_job,Kill_job,continue_client(Resume job),start_job             
 (10) SQL*LOADER                            
 - It's loads the data from external file  into database table of an oracle database             
 - It has powerful engine of data parsing that put little limitations on format data of  data files             
 (11) OEM (ORACLE ENTERPRISE MANAGER)                             
 - It's   a set of web based tools ,by using this tool  can manage  software  and hardware produced by  " ORACLE CORPORATION "& some of non " ORACLE ENTITIES "             
 - Each machine has a licensing  cost.
(12) dbstart (DATABASE  START)                             
 - It's automatically starts the oracle database instance  and listeners               -
 $cat /etc/oratab
  issuing this command we can see what are the available database listed here  by default it has  set on  'N' and we need to change 'Y' after these changes we don't need issue startup command for  each time
(13) dbshut (DATABASE SHUTDOWN)                             
 - By issuing this  command  shut down an oracle instances

Wednesday, March 18, 2020

ORACLE ARCHITECTURE INTERVIEW QUESTIONS

1. Explain briefly about Oracle database architecture 
Ans. Oracle database architecture is a combination of instance and database. Instance is a combination of memory structures and background processes which helps in reading and writing the data to/from the database .
2. Which background process is used during user connectivity? 
Ans. PMON 
3. What are base tables? When and how they will get created?
Ans. Base tables are dictionary information of the database. They will be created at the time of database creation using SQL.BSQ script.
4. What are different views DBA uses? Which script will create them?
Ans. We use data dictionary views to look into permanent information about the database and dynamic performance views to get ongoing actions in the database. Both the views will be created after database creation using catalog.sql script.
5. Why to execute catproc.sql script?
Ans. It will create necessary packages and procedures which DBA use for certain actions.
6. Explain the phases of SQL execution
Ans. SQL execution contains 2 phases.
i. Parsing – in which syntax checking, semantic checking and dividing the statement into literals will be done
ii. Execution – in which parsed statement will get converted into ASCII format and will be executed
iii. Fetch – in which data will be fetched either from database buffer cache or database.
7. What is mean by semantic checking? Which component helps in that?
Ans. Semantic checking means checking for the privileges for the user or in other words authorizing the user. Base tables or dictionary will help in doing this.
8. What is server process?
Ans. It is a process created to help the user process either in reading/writing the data in the database.
9. What is the difference between physical and logical read?
Ans. If we fetch data from database buffer cache, then its called logical read. If we fetch it from database, its called physical read as it includes an I/O operation.
10. Why to maintain a copy of data in database buffer cache?
Ans. When the same query is ran by same or different user, data can be picked from buffer cache thus avoiding I/O and improving performance.
11. Why server process will not start searching from MRU end?
Ans. If server process starts searching at MRU end,  there is a chance that data may get flush from buffer cache by the ime it reaches LRU end. In that case again to fetch data, we need to do an I/O which is costly. So oracle designed its architecture that server process will search only from LRU end.
12. What are the logical structures of the database?
Ans. Tablespace, segment, extent and oracle data block are logical structures.
13. What are the 4 mandatory tablespaces req to run the database?
Ans. SYSTEM, SYSAUX, TEMP and UNDO.
14. Can I have a database without SYSAUX tablespace in 10g?
Ans. Yes, but load will be more on system tablespace.
15. If we have physical structures, why do we need logical structures?
Ans. Logical strutures are defined to provide the easeness in maintenance.
16. Explain the difference between a block, extent and segment?
Ans. Block is a basic storage unit whereas extent is a small memory area allocated to a table     and segment is an object which occupies space.
17. What are redo entries? When and where they will be created?
Ans. A single atomic chance happened to the database is called redo entry. They will be created when we run any DML or DDL commands or when any changes are done in the database. They will be created in PGA.
18. What is different status for a block in database buffer cache?
Ans. UNUSED, FREE, PINNED and DIRTY.
19. What is write-ahead protocol?
Ans. LGWR writing before DBWR is called write-ahead protocol.
20. Will there be any undo generated in case of DDL statement processing? If so why?
Ans. Yes. Reason is even tough it is a DDL externally, it will be DML to base tables and to rollback them always oracle requires undo.
21. What is PGA?
Ans. PGA is a memory area which is used to store user’s exclusive information like session information and helps in executing a query.
22. What is the difference between memory allocation in 8i and 9i for PGA?
Ans. In 8i, we need to set different individual parameters where as in 9i setting only one parameter PGA_AGGREGATE_TARGET would be enough
22. Which is correct? Sorting will take place in PGA or temp tablespace?
Ans. Both. If the data which to be sorted is more than sort area size of PGA, then temp tablespace will be used.
23. How you will define INSTANCE and DATABASE?
Ans. INSTANCE is a combination of memory structures and background processes which helps in reading/writing the data. DATABASE is mix of physical and logical structures which helps in storing user data.
24. What is SGA?
Ans. SGA is a combination of different memory structures which helps in several actions in the database.
25. What are the responsibilities of SMON?
Ans. It will do instance recovery, coalesces the tablespace and will release the temp segments occupied by a transaction when it is completed.
26. Why oracle maintains to redo log files?
Ans. To avoid any space constraints.
27. What is a log switch? What happens when it occurs?
Ans. Answer is available in the class notes.
28. What is SCN and which process writes that?
Ans. SCN is a unique number assigned to a transaction which modifies data in the database. CKPT process will always update this SCN to both datafiles header and control file.
29. What are the other new background processes in 10g that you know?
Ans.
MMAN – memory manager which helps in maintaining ASMM
RVWR – helps in generating flashback logs incase flashback is turned on
CTWR – helps incremental backup in RMAN
MMNL – memory monitor light, which helps in AWR statistics collection
MMON – manageability monitor, which helps in automatic problem detection and self-tuning.
30. What information control file contains?
Ans. It contains latest SCN, all locations and sizes of data files and redo log files, database creation date and timestamp and control file parameters.
31. What is server parameter file and how it is different from parameter file?
Ans. Spfile is a binary file and it helps in changing parameters efficiently than a pfile.
33. What is Ifile and when it is used?
Ans. Ifile is a index file which can help database when pfile or spfile are not in default location.
34. How to recover if I lost parameter pfile or spfile?
Ans. We can recover from alert log file which contains non-default parameters.
35. If we have both pfile and spfile in place, which file oracle will use during startup?
Ans. Spfile.
36. What are hidden parameters and their use?
Ans. Hidden parameters are to be used only on recommendation of oracle support and sometimes they help us in providing work around to any serious problem in the database.
37. What is the purpose of password file?
Ans. It is used to authenticate any user is connecting as SYSDBA from a remote machine.
38. Even though there is a password file, still I observed that any user is being able to connect as sysdba from remote machine without a password. What went wrong?
Ans. REMOTE_LOGIN_PASSWORD is not set to exclusive.
39. While creating password file, what is the use of ENTRIES?
Ans. To specify how many users with sysdba role can connect to the database remotely.
40. What is ASMM? Which background process helps in that?
Ans. Setting SGA_TARGET parameter is called ASMM. This helps in managing all SGA components automatically and MMAN is the background process helps in that
41. How database will behave when you have both ASMM and individual parameters are configured?
Ans. Values of individual parameters will act as minimum and ASMM as maximum.
42. You increased the SGA_MAX_SIZE parameter to a higher value. But when trying to increase SGA_TARGET, its throwing error that “it cannot increase”. What might be the reason?
Ans. Kernel parameter SHMMAX may be reached. We should increase that first.
43. Which parameter helps ASMM to be affective? What is the value it should be set to?
Ans. SGA_TARGET and value is dependent on no of transactions in the database.
44. What is AMM in 11g?
Ans. Managing both SGA and PGA automatically by oracle is called Automatic Memory Management (AMM).
45. My database size is 1 TB, how much SGA will you configure?
Ans. SGA size is not dependent on database size, it depends on how many transactions happening in the database.
46. What is alert log? How it is helpful for DBA?
Ans. It is file which helps in diagnosing all the errors occurred in the database.
48. What are the contents of alert log file?
Ans. Database startup and shutdown times, non-default parameters, any logical or physical structural changes and all oracle errors etc.
49. What happens if we remove alert log file when database is in use?
Ans. No effect on the database functionality. Oracle will create a new alert log file.
50. If we have alert log file to diagnose the problem, why we need trace files? What are they?
Ans. Alert log itself cannot provide complete information about the error, in which case it will generate trace file. Depends on the error, it will generate background, core or user trace files.
51. Which background process is responsible for writing into alert log file?
Ans. All the background processes are responsible.
52. Which process will start first when instance is started?
Ans. PSP0, process spanner. This background process will start other processes like PMON, SMON etc. But in alert log first it will show PMON.
52. Which file is req to place database in NOMOUNT state and what happens in that phase?
Ans. Pfile or spfile is required to bring database to NOMOUNT state and instance will be started (background processes will be started and memory will be allocated to SGA from RAM) in this phase.
53. Which file is required to bring into MOUNT phase and what is the use of this phase?
Ans. Control file is required and it is for maintenance of some database actions.
54. What files are needed to open the database and How oracle knows the locations of them?
Ans. Data files and redo log files are required to open the database and oracle will get that information from control files.
55. What you will do when SHUTDOWN IMMEDIATE command hanging for last 30 min?
Ans. We can open another terminal and issue shut abort. Then once again startup and do shut immediate.
56. What could be reason for SHUTDOWN IMMEDIATE command hanging for long time?
Ans. Might be there is a transaction which is large and rollback is happening for the same.
57. What is server result cache? What benefit we get out of it?
Ans. It is a new component introduced in 11g. It will store the rows of a query directly thus avoids the need of executing a statement.
58. Explain how a select statement will get the benefit by using server result cache?
Ans. Read how a select statement will process in 11g from class notes.
59. What parameters to be used to make 11g database use server result cache?
Ans. SERVER_RESULT_CACHE.
60. How to increase the size of server result cache?
Ans. By increasing the size specified by SERVER_RESULT_CACHE or by increasing MEMORY_TARGET parameter if AMM is used.
61. Where all the trace files located in 11g?
Ans. It is in a single location defined by DIAG_DEST parameter.
62. Which background process clears sessions and releases locks when system fails?
Ans. SMON (here system means database).
63. What is OFA? Do you recommend to implement it?
Ans. It is a rule which says database related files should split across multiple disks and yes I will recommend to implement it.
64. Why oracle recommends OFA? How it is related to OS?
Ans. As one disk will have only one I/O header, it will be burden to the database if we place all the files in single hard disk. So oracle recommends OFA.
65. What is DISPATCHER in shared server architecture?
Ans. It is a service which server multiple user requests.
66. As a DBA, when you will take decision to enable shared server architecture?
Ans. When we observed ORA-04030 or ORA-04031 errors very frequently in alert log file.
67. You configured all the parameters to enable shared server architecture, but still users facing memory allocation issues. What you would do?
Ans. We need to check if SERVER=SHARED is mentioned in client TNS entry or not.
68. What are the parameters you use to configure shared server architecture?
Ans.
DISPATCHERS
MAX_DISPATCHERS
SHARED_SERVER_PROCESSES
MAX_SHARED_SERVER_PROCESSES.
69. How many slave process we can have for DBWR and SMON?
Ans. DBWR – 20, SMON – 16 .
70. I connected to database as sysdba, but it’s not allowing me to shut down the database, what may be the reason?
Ans. The connection would have been shared server connection in which case oracle will not allow to shutdown/startup the database.


Saturday, December 7, 2019

How to Install Oracle 12c Database on Red Hat/Cent OS

Additionally note that an Oracle account is required to download the Oracle Database 12c installation file (3.2 GB). Don’t worry about this, though, as you can create an account for free.

Finally, make sure your server has at least 2 GB of RAM and 30 GB of available disk space. These hardware requirements are safe for a testing environment such as ours, but will need to increase if you consider using Oracle in production.

#To begin, make sure that all the packages currently installed on your RED HAT/Cent OS  system are updated to their latest versions.
 yum update -y

#Add the following lines to the "/etc/sysctl.conf" file
 vi /etc/sysctl.conf
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
kernel.panic_on_oops = 1
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500

#Run one of the following commands to change the current kernel parameters, depending on which file you edited.

     /sbin/sysctl -p

#Add the following lines in "/etc/security/limits.conf"
    vi /etc/
security/limits.conf

oracle   soft   nofile    1024
oracle   hard   nofile    65536
oracle   soft   nproc    16384
oracle   hard   nproc    16384
oracle   soft   stack    10240
oracle   hard   stack    32768
oracle   hard   memlock    134217728
oracle   soft   memlock    134217728
#Please install following packages .
yum install binutils -y
yum install compat-libstdc++-33 -y
yum install compat-libstdc++-33.i686 -y
yum install gcc -y
yum install gcc-c++ -y
yum install glibc -y
yum install glibc.i686 -y
yum install glibc-devel -y
yum install glibc-devel.i686 -y
yum install ksh -y
yum install libgcc -y
yum install libgcc.i686 -y
yum install libstdc++ -y
yum install libstdc++.i686 -y
yum install libstdc++-devel -y
yum install libstdc++-devel.i686 -y
yum install libaio -y
yum install libaio.i686 -y
yum install libaio-devel -y
yum install libaio-devel.i686 -y
yum install libXext -y
yum install libXext.i686 -y
yum install libXtst -y
yum install libXtst.i686 -y
yum install libX11 -y
yum install libX11.i686 -y
yum install libXau -y
yum install libXau.i686 -y
yum install libxcb -y
yum install libxcb.i686 -y
yum install libXi -y
yum install libXi.i686 -y
yum install make -y
yum install sysstat -y
yum install unixODBC -y
yum install unixODBC-devel -y
yum install zlib-devel -y
yum install zlib-devel.i686 -y
#Create the new groups and users.
groupadd -g 54321 oinstall
groupadd -g 54322 dba
groupadd -g 54323 oper
#groupadd -g 54324 backupdba
#groupadd -g 54325 dgdba
#groupadd -g 54326 kmdba
#groupadd -g 54327 asmdba
#groupadd -g 54328 asmoper
#groupadd -g 54329 asmadmin

useradd -u 54321 -g oinstall -G dba,oper oracle
#Set the password for the "oracle" user.
passwd oracle
Set secure Linux to permissive by editing the "/etc/selinux/config" file, making sure the SELINUX flag is set as follows.
SELINUX=permissive
#Once the change is complete, restart the server or run the following command.

# setenforce Permissive
#If you have the Linux firewall enabled, you will need to disable or configure it, as shown here or here. To disable it, do the following.

# systemctl stop firewalld
# systemctl disable firewalld
#Create the directories in which the Oracle software will be installed.

mkdir -p /u01/app/oracle/product/12.1.0.2/db_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01
Unless you are working from the console, or using SSH tunnelling, login as root and issue the following command.

xhost +<machine-name>
#Add the following lines at the end of the "/home/oracle/.bash_profile" file.

/home/oracle/.bash_profile

# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP

export ORACLE_HOSTNAME=ol7.localdomain
export ORACLE_UNQNAME=cdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2/db_1
export ORACLE_SID=cdb1

export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
#Installation
Log into the oracle user. If you are using X emulation then set the DISPLAY environmental variable.
DISPLAY=<machine-name>:0.0; export DISPLAY
 #Open a GUI session in the RED HAT/Cent OS  server and launch the installation script.
     unzip file and run script
/home/database/runInstaller
# Enter the email address associated with your Oracle account (optional).



#Choose Create and configure a database.

#Select Desktop class since we are setting up a minimal configuration and a starter database.

#Select the following options for basic configuration.
  • Oracle base: /u01/app/oracle
  • Software location: /u01/app/oracle/product/12.1.0.2/db_1
  • Database file location: /u01
  • OSDBA group: dba
  • Global database name: your choice. 
  • Take note of the password, as you will be using it when you first connect to the database.
  • Uncheck Create as Container database.
#Leave the default Inventory Directory as /u01/app/oraInventory.


#Verify that the installation pre-checks are completed without errors.


#Wait until the Oracle 12c installation completes.

It is possible that at some point during the installation you will be asked to run a couple of scripts to set up further permissions or correct issues. This is illustrated here:



Thursday, November 21, 2019

Working With Vi Editor In Unix

Vi is the standard editor that is available on Unix systems.
This visual editor enables manipulation of text while showing a screenful of text unlike ‘sed’ that works at the line level. 

Modes of Unix Vi Editor

The vi editor has three modes of operation viz. the command mode, the insert mode, and the ex-command mode.

#1) Command mode:

In this mode, all the keys work as commands. These keys are used for inserting, appending, deleting, opening new lines, moving the cursor over the paragraphs and sentences, etc. In this mode, the keys are not displayed but each key performs an operation.
By default the vi editor is in command mode, hence we cannot type text in command mode. In order to write programs or text in vi editor, we need to switch to the insert mode which can be done by pressing the escape button.

#2) Insert mode:

In this mode, we can insert, append, edit or replace texts. We can switch from the command mode to Insert mode by pressing the escape button and then press I or A to enter into insert mode.

#3) Ex command mode:

This mode is used for entering commands at the bottom line of the vi editor called as a command line. To switch to Ex command mode press escape key then type: (colon). In order to save the contents and quit from the vi editor press wq after the : (colon). i.e :wq.
Vi editor saving  and quitting commands:
:w -Save the contents of the file.
:q – Quit from vi editor.
:q! -quit from vi editor by discarding any changes.
:wq -Save the file and quit from the vi editor.
This tutorial will cover the various commands that are used in the command and ex-command modes. This includes commands to navigate around the screen by paragraph, line, word or character.
We will also cover commands for switching the mode, deleting characters, words, lines or paragraphs.

Replication and auto-failover

  Step 1. Make sure MySQL Servers are configured correctly For some of the utilities, it’s important that you’re using Global Transaction ID...