Wednesday, April 29, 2015

Database Upgrade from 12.1.0.1 to 12.1.0.2

VARCHAR2(32K) -- 12 c New Feature

VARCHAR2(32K) -- 12 c New Feature

Oracle has made a few changes to the database to allow organizations to reduce the cost of migrating to Oracle 12c.  One of these changes is with the size limits that have been placed on the VARCHAR2, NVARCHAR2 and RAW data types.  In past versions of Oracle database the maximum size for these data types were 4,000 bytes.  In Oracle 12c, these data types can now  be increased to 32,767 bytes.

In order to set these data types to use the larger setting, the MAX_STRING_SIZE parameter needs to be set.  The only values that this parameter can take is STANDARD and EXTENDED.  Once the parameter has been set to EXTENDED, you cannot go back to STANDARD.

Note: Altering MAX_STRING_SIZE will update database objects and possibly invalidate them To increase the size of the VARCHAR2, NVARCHAR2 and RAW columns for a non-CDB database,  these steps need to be followed:


                  1. Shutdown the database
                  2. Restart in UPGRADE mode
                  3. Change the setting of MAX_STRING_SIZE to EXTENDED
                  4. Run $OH/rdbms/admin/utl32k.sql  <- must be connected as SYSDBA
                  5. Restart in NORMAL mode.

The same procedure can be followed and applied against an Oracle PDB, Oracle RAC database, Oracle Data Guard Logical Standby Databases. 


Extended Statistics

Extended Statistics

In real-world data, there is often a relationship or correlation between the data stored in different columns of the same table. For example, in the customers table, the values in the cust_state_province column are influenced by the values in the country_id column, as the state of California is only going to be found in the United States. Until now, the Optimizer had no way of knowing about these real-world relationships and could potentially miscalculate the cardinality estimate if multiple columns from the same table are used in the where clause of a statement. With extended statistics you now have an opportunity to tell the Optimizer about these real-world relationships between the columns.

By creating extended statistics on a group of columns, the Optimizer can determine a more accurate cardinality estimate when the columns are used together in a where clause of a SQL statement.You can use DBMS_STATS.CREATE_EXTENDED_STATS to define the column group you want to have statistics gathered on as a whole. Once the group has been established Oracle will automatically maintain the statistics on that column group when statistics are gathered on the table.

If we continue with the initial example of the customers table, When the value of cust_state_province is 'CA' we know the value of country_id will be 52790 or the USA. There is also a skew in the data in these two columns; because the company used in the SH is based in San Francisco so the majority of rows in the table have the values 'CA' and 52790. Both the relationship between the columns and the skew in the data can make it difficult for the optimizer to calculate the cardinality of these columns correctly when they are used together in a query.

initial_query_and_plan.png



With just basic statistics we see the optimizer thinks there will only be 127 row returned because it assumes both columns will reduce the number of rows returned (# of rows in the table X 1/NDV of column1 X 1/NDV of column2). We know that this is not true in this case. We must provide better statistic to the optimizer so it can determine the correct cardinality estimate. Prior to Oracle Database 11g the only option open to us would be to make the optimizer aware of the data skew in both the country_id column (most rows have 52790 as the value) and the cust_state_province column (most rows have 'CA' as the value). We can do this by gathering histograms on the skewed columns.

histogram_stats.png


Now that we have histograms on both the country_id and the cust_state_province columns let's see if the optimizers estimate is more accurate.

histogram_plan.png


There is a slightly improvement in the estimate since we have histograms for the individual columns. However the optimizer is still not aware that there is a relationship or correlation between these two columns. In Oracle Database 11g we can tell the optimizer about this correlation by creating extended statistics on these two columns as a group. Once the extended statistics have been created the next time statistics are gathered on the CUSTOMERS table an extra set of statistics, for the combine group of country_id and cust_state_province, will be collected. The DBMS_STATS.CREATE_EXTENDED_STATS function can be used to create the extended statistics or a 'column group' for country_id and cust_state_province.

create_extended_stats.png


After creating the extended statistics and regather statistics, you will see a system generated column name in USER_TAB_COL_STATISTICS, which represents the new column group. A subset of statistics are maintained for column groups including;
  • Number of distinct values
  • Number of Nulls
  • Histograms

system_generated_stats.png


So now we have statistics on the column group lets confirm that is enough information for the optimizer to get the correct estimation.


Not_working.png

The cardinality estimate is still off. Why did the extended statistics not help in this case? The extended statistics were not actually used here. If you look back at the output from USER_TAB_COL_STATISTICS you can see there is a histogram created on the country_id and cust_state_province columns. However, there is no histogram created on the column group. Because a histogram provides the Optimizer with more information than standard statistics the Optimizer ignores the extended statistics and uses the individual column statistics instead.

Since we have executed the query again, the optimizer will have recorded that a histogram on the created extension is beneficial for the query. A histogram will be automatically created on the column group the next time statistics are gathered on the table

p1.png


With the histogram in place on the column group, the Optimizer will now use the extended statistics and the cardinality estimates is now accurate.

working.png


Extended Statistics are used even if we have them for only a subset of predicates in the statement. Lets say there is a column group created on (c1, c2) and we have a SQL statement with a where clause that contains c1 = 1 and c2 =1 and c3 = 1. The optimizer will use the extended statistics on C1,C2 and multiply  that by the selectivity of third predicate. It will use all the available statistics on column group, including histograms. The optimizer will also use the extended statistics (in a limited way) if a subset of the column group is present in the query.

Oracle In-Memory Advisor

Oracle In-Memory Advisor

 

Oracle Database In-Memory can be used to improve queries on a variety of OLTP and/or data warehouse operations. The In-Memory Advisor helps to optimize performance with recommendations to run analytics processing faster. It gives customers insight into the sizing of the workload and offers actionable recommendations for running workloads at peak performance. The Advisor analyzes workloads and related objects making specific recommendations to which objects would give you the greatest benefit and performance if they were placed In-Memory.

Key Capabilities:
  • Assists with In-Memory size selection
  • Recommendations for tables, partitions and sub-partitions for a given In-Memory size
  • Uses workload and performance data to prioritize objects
  • Takes into account differences in disk and memory footprint, as well as compression ratios
Actionable Recommendations
  • Workload based cost/benefit analysis
    • Cost: Offers estimated memory size with various compression options
    • Benefit: Offers estimated database time reduction metrics for workload processing
  • In-memory area population plan
Reporting
  • Ability to vary In-Memory size to receive specific loading plan
  • Generates DDL scripts with all the tables/partitions/sub-partitions recommended
  • Top SQL benefits from any given configuration

 MOS Note: https://support.oracle.com/epmos/faces/DocumentDisplay?id=1965343.1

It can be run on Oracle Database 11.2.0.3 and above. And of course the recommendations can be implemented on Oracle Database 12.1.0.2. (and newer). Important to know: The In-Memory Advisor is licensed as part of the Database Tuning Pack

Configuration Of In Memory Advisor

1. Download the advisor zip file from  MOS (1965343.1)

2. Install the Advisory Pack

$ unzip imadvisor.zip
$ sqlplus sys/<password> as sysdba

SQL> @instimadv

3. Running the advisor

$ sqlplus sys/<password> as sysdba
SQL> @imadvisor_analyze_and_report

4. Generate the Output

exec DBMS_INMEMORY_ADVISOR.GENERATE_RECOMMENDATIONS();





 

Oracle In Memory Column Store

Oracle In Memory Column Store

Let’s start by doing a clean install of 12.1.0.2 and allowing the installer to create a typical single instance database.

So, has In-Memory been installed?
Yes, Oracle Database In-Memory is installed. How do I know? Oracle Database In-Memory is not a bolt on technology to the Oracle Database. It has been seamlessly integrated into the core of the database as a new component of the Shared Global Area (SGA). When the Oracle Database is installed, Oracle Database In-Memory is installed. They are one and the same. You can’t unlink it or choose not to install it.
The more important question is if In-Memory is automatically enabled or not?
The answer is NO. In order to prove this we are going to need to look at some of the new initialization parameters that control In-Memory.

Six new initialization parameters with the INMEMORY prefix have been introduced to directly control the different aspects of the new in-memory functionality. There is also a new optimizer parameter that controls whether queries can use the INMEMORY or not.
Right now we are only interested in one of these parameters, INMEMORY_SIZE to determine if In-Memory is enabled.
Database In-Memory uses an In-Memory column store (IM column store), which is the new component of the SGA, called the In-Memory Area. Data in the IM column store does not reside in the traditional row format used by the Oracle Database; instead it uses a new column format. The size of the IM column store is controlled by the INMEMORY_SIZE parameter. As you can see the INMEMORY_SIZE parameter is set to 0 and therefore Database In-Memory is not enabled, as there is no IM column store allocated. We can also confirm the In-Memory Area is not allocated by querying v$SGA.

Still don't trust me? Let’s confirm Database In-Memory is not enabled by examining the feature tracking information. I’m going to force the feature-tracking table to be updated before I query it.

If Database In-Memory isn’t enabled out of the box how do you enable it?
Enabling Database In-Memory is actually a multi-step process.
Step1: First we must allocate memory for the IM column store by setting the INMEMORY_SIZE parameter to a non-zero value that is greater than 100MB.
ALTER SYSTEM SET inmemory_size = 20G scope=spfile;
Since the IM column store is part of the SGA, we also need to ensure the SGA_TARGET parameter is set large enough to accommodate the new IM column store and all of the other existing components (buffer cache, shared pool, large pool etc.). By default, the installer set the SGA_TARGET to 71G, so I’m going to bump it by 20G.
ALTER SYSTEM SET sga_target = 91G scope=spfile;
Now let’s bounce the database so these parameter changes can take effect.

As you can see, we now have an IM column store. But Database In-Memory is still not in use because no objects have been populated into the IM column store. To confirm this we can look at two new v$ views, v$IM_SEGMENTS and v$IM_USER_SEGMENTS that indicate what objects are in the In-Memory Column Store.

We can also confirm it by checking the feature tracking information again.


Step 2: Unlike a pure In-Memory database, not all of the objects in an Oracle database need to be populated in the IM column store. The IM column store should be populated with the most performance-critical data in the database. Less performance-critical data can reside on lower cost flash or disk. Of course, if your database is small enough, you can populate all of your tables into the IM column store. Only objects with the INMEMORY attribute are populated into the IM column store. The INMEMORY attribute can be specified on a tablespace, table, (sub)partition, or materialized view. In this case let's enable the INMEMORY attribute on one of the user tables CUSTOMERS.
ALTER TABLE SSB.customers INMEMORY;
By default Oracle automatically decides when to populate the table into the In-Memory Column Store. This is also referred to as “on demand”, as Oracle typically populates the table after it has been accessed for the first time. So, let’s run a query on the CUSTOMERS table.
SELECT cust_valid, Count(*)
FROM customers
GROUP BY cust_valid
;
Now if we check v$IM_SEGMENTS we see the CUSTOMERS table has been populated in the IM column store.

If we check the feature tracking information now, we will see Database In-Memory is enabled and being used.

If you want to remove a table from the IM column store you simply need to specify the NO INMEMORY attribute.
ALTER TABLE SSB.customers NO INMEMORY;
In next week's post, I will explain in a lot more detail all of the different sub-clause of the INMEMORY attribute and what all of the columns in the new v$ views represent.

Wednesday, October 2, 2013

Verifying pre requistes before installing Oracle on Linux

Oracle Installation on RHEL

As we all now before installing oracle on any Unix flavor OS we need to verify the pre requisites, Oracle has provided some RPM's to verify the pre requisites like Oracle_validated for prior 11gR2 and oracle-rdbms-server-11gR2-preinstall for 11gR2 64 bit version.

We can  configure public YUM(oracle public yum)  as specified in the URL. but some of the organizations doesn't allow us to use public yum or to use oracle provided packages, then we need to verify the pre requisites manually.

we can see the functionality of oracle provided packages here in this link (Oracle Packages).

If we need to verify the pre requisites manually we can use the below script to pull the required information and verify the requirements manually. copy the below script to a note pad and run it form your shell.

vi verify_pre_req.sh
------------------------------------------------------------------------------------------------------------
#!/bin/bash 
echo -e "\nServerName\n" > Pre_check.log
hostname >> Pre_check.log
echo -e "\nMemory Information" >> Pre_check.log
echo -e "\nMinimum RAM required 1GB(Server), \nSwap memory as below table \n1-2GB of RAM: 1.5*RAMsize\n2-16GB of RAM: As RAM Size\n>16GB of RAM: 16GB\n" >> Pre_check.log
echo -e "Available memory" >> Pre_check.log
grep SwapTotal /proc/meminfo >> Pre_check.log
grep MemTotal /proc/meminfo >> Pre_check.log
echo -e "\nKernema and OS information" >> Pre_check.log
echo -e "\nMinimu Kernel version required for 11.2\n2.6.32-71.el6.x86_64 or later\n" >> Pre_check.log
uname -a >> Pre_check.log
echo -e "\nOS Version\n"  >> Pre_check.log
cat /etc/redhat-release >> Pre_check.log
echo -e "\nDisk requirements" >> Pre_check.log
echo -e "\ntmp=1GB \nu01=10GB \n"  >> Pre_check.log
echo -e "\nAvailable disk space" >> Pre_check.log
df -h >> Pre_check.log
echo -e "\npackage requirements" >> Pre_check.log
echo -e "\nMinimum package and version requirements as per below, if you have a higher version its not an issue"  >> Pre_check.log
echo -e "\nbinutils-2.20.51.0.2-5.11.el6 (x86_64) \ncompat-libcap1-1.10-1 (x86_64) \ncompat-libstdc++-33-3.2.3-69.el6 (x86_64) \ncompat-libstdc++-33-3.2.3-69.el6.i686 \ngcc-4.4.4-13.el6 (x86_64) \ngcc-c++-4.4.4-13.el6 (x86_64) \nglibc-2.12-1.7.el6 (i686) \nglibc-2.12-1.7.el6 (x86_64) \nglibc-devel-2.12-1.7.el6 (x86_64) \nglibc-devel-2.12-1.7.el6.i686 \nksh \nlibgcc-4.4.4-13.el6 (i686) \nlibgcc-4.4.4-13.el6 (x86_64) \nlibstdc++-4.4.4-13.el6 (x86_64) \nlibstdc++-4.4.4-13.el6.i686 \nlibstdc++-devel-4.4.4-13.el6 (x86_64) \nlibstdc++-devel-4.4.4-13.el6.i686 \nlibaio-0.3.107-10.el6 (x86_64) \nlibaio-0.3.107-10.el6.i686 \nlibaio-devel-0.3.107-10.el6 (x86_64) \nlibaio-devel-0.3.107-10.el6.i686 \nmake-3.81-19.el6 \nsysstat-9.0.4-11.el6 (x86_64)\n"  >> Pre_check.log
echo -e "\nPackages available in the server\n" >> Pre_check.log
rpm -qa unix* >> Pre_check.log
rpm -qa binutils* >> Pre_check.log
rpm -qa compat-libcap* >> Pre_check.log
rpm -qa compat-libstdc* >> Pre_check.log
rpm -qa gcc* >> Pre_check.log
rpm -qa gcc-c* >> Pre_check.log
rpm -qa glibc* >> Pre_check.log
rpm -qa libgcc* >> Pre_check.log
rpm -qa libstdc* >> Pre_check.log
rpm -qa libaio* >> Pre_check.log
rpm -qa make* >> Pre_check.log
rpm -qa sysstat* >> Pre_check.log
rpm -qa ksh* >> Pre_check.log
echo -e "\nuser and Gropus information" >> Pre_check.log
echo -e "\nGroups required dba, oinstall \nUser required oracle assigned to oinstall and dba(oinstall prmary, dba secondary)\n" >> Pre_check.log
echo -e "Avialble user and groups" >> Pre_check.log
grep dba /etc/group >> Pre_check.log
grep oinstall /etc/group >> Pre_check.log
id oracle >> Pre_check.log
echo -e "\nKernel Parameters\n" >> Pre_check.log
cat /etc/sysctl.conf  >> Pre_check.log
echo -e "\nShell limits" >>  Pre_check.log
echo -e "\nPage_Size limits\n" >>  Pre_check.log
getconf PAGE_SIZE >> Pre_check.log
echo -e "\nSHMALL can be calculated \n(RAM_SIZE in KB * 1024 * 0.8)\PAGE_SIZE)\n" >> Pre_check.log
echo -e "\nResource limits \nOpen file descriptors(nofile) \t\t1024 \t65536 \nNumber of proccesses for a user(nproc) \t2047 \t16384 \nSize of stack segment(stack) \t\t10240 \t32768\n" >> Pre_check.log
cat /etc/security/limits.conf >>  Pre_check.log
echo -e "\nStack soft limit and Hard limit as follows\n" >>  Pre_check.log
ulimit -Ss >>  Pre_check.log
ulimit -Hs >>  Pre_check.log
------------------------------------------------------------------------------------------------------------

chmod +x verify_pre_req.sh
sh verify_pre_req.sh
cat Pre_check.log

Thanks,
Mohan Gosu.