sábado, 26 de abril de 2014

ORA-00845: MEMORY_TARGET not supported on this system




ORA-00845: MEMORY_TARGET not supported on this system

, by
Simon Krenger
There is always something that gets in the way. One problem I regularly stumble upon when installing a new Oracle 11g R2 installation is the following error when I try to start the database:
SQL> startup nomount;
ORA-00845: MEMORY_TARGET not supported on this system
So I keep this post mainly for my own reference when installing a new database on a Linux system.
This error comes up because you tried to use the Automatic Memory Management (AMM) feature of Oracle 11g R2. Well done, but it seems that your shared memory filesystem (shmfs) is not big enough. So let’s look at the steps necessary to enlarge your shared memory filesystem to avoid the error above.
First of all, login as root and have a look at the filesystem:
[root@oracle-em oracle]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_oracleem-lv_root
                       93G   19G   69G  22% /
tmpfs                 5.9G  112K  5.9G   1% /dev/shm
/dev/sda1             485M   99M  362M  22% /boot
So we can see that tmpfs has a size of 6GB. We can change the size of that filesystem by issuing the following command (where “12g” is the size I want for my MEMORY_TARGET):
[root@oracle-em oracle]# mount -t tmpfs shmfs -o size=12g /dev/shm
This command (re)mounts the shmfs filesystem (check this post for more information about shmfs) with the option “size=12g“.
The shared memory file system should be big enough to accommodate the MEMORY_TARGET and MEMORY_MAX_TARGET values, or Oracle will throw the ORA-00845 error. Note that when changing something with the mount command, the changes are not permanent.
To make the change persistent, edit your /etc/fstab file to include the option you specified above:
[root@oracle-em ~]# cat /etc/fstab
[..]
tmpfs                   /dev/shm                tmpfs   size=12g        0 0
[..]
In my case, I replaced the “defaults” option with the size=12g option. After saving the file, the changes should be permanent. Now back to Oracle. Let’s see if we can start the database now…
SQL> startup nomount
ORACLE instance started.

lunes, 21 de abril de 2014

Oracle Startup and Role Change Triggers

Oracle Startup and Role Change Triggers
# Triggers to change service name for Dataguard Standby databases.

# Create the services

alter system set service_names = 'a';
alter system set service_names = 'b';

exec DBMS_SERVICE.CREATE_SERVICE('PROD','PROD');
exec DBMS_SERVICE.CREATE_SERVICE('STANDBY','STANDBY');

# Role Change Trigger

CREATE OR REPLACE TRIGGER service_name_trg AFTER DB_ROLE_CHANGE ON DATABASE DECLARE
role VARCHAR(30);
BEGIN
SELECT DATABASE_ROLE INTO role FROM V$DATABASE;
IF role = 'PRIMARY' THEN
DBMS_SERVICE.START_SERVICE('PROD');
ELSE
DBMS_SERVICE.START_SERVICE('STANDBY');
END IF;
END;

# Startup Trigger - will only fire after the database is open.
CREATE OR REPLACE TRIGGER startup_trg
after startup on database
DECLARE
role VARCHAR(30);
BEGIN
SELECT DATABASE_ROLE INTO role FROM V$DATABASE;
IF role = 'PRIMARY' THEN
DBMS_SERVICE.START_SERVICE('PROD');
ELSE
DBMS_SERVICE.STOP_SERVICE('STANDBY');
END IF;
END;

# Diagnostics scripts for service status

SELECT name, network_name FROM dba_services;
SELECT service_id, name, network_name FROM gv$active_services;

# Assorted scripts
exec DBMS_SERVICE.STOP_SERVICE('PROD');
exec DBMS_SERVICE.STOP_SERVICE('STANDBY');
exec DBMS_SERVICE.DELETE_SERVICE('PROD');
exec DBMS_SERVICE.START_SERVICE('PROD');

jueves, 3 de abril de 2014

CREATE TABLE AS

The Create table as select (CTAS) statement can be used to change storage parameters for a table (INITIAL, NEXT, FREELISTS) and also change the physical sequence of the table rows. Create table as select (CTAS) has the following syntax:

create table xxx_new
tablespace new_tablespace_name
storage (initial new_initial next new_next freelists new_freelist_number )
as
select * from xxx
order by primary_index_key_values;


There are several way to execute CTAS to reorganize table; many of the options depend upon the version of Oracle and the particular configuration of the Oracle database.

Parallel CTAS

Running a create table as select (CTAS) in parallel can dramatically speed up SAP table reorganization. As a rule of thumb, the parallel option is used only on SAP database servers that have multiple CPUs (for example, SMP processor CPUs), but there will be some performance improvement when invoking parallelism, even on a uni-processor CPU. Note that the UNRECOVERABLE clause can be used in conjunction with the parallel clause, or you can run UNRECOVERABLE CTAS without using parallelism. Here is an example of a parallel CTAS:

create table
   vbap_sorted
tablespace
   vbap_copy
storage (
   initial 500m
   next 50m
   maxextents unlimited
   )
parallel (degree 4)
as
select *
from
sapr3.vbap
order by
mandt,
vbeln,
posnr;


CTAS using INDEX hint

This is an excellent way of reorganizing a table to physically re-sequence the rows in the table. It is commonly known that Oracle deliberately omitted the ORDER BY clause in their implementation of CREATE TABLE AS SELECT. This is because of Oracle?s early philosophy (pre-release 7.3.4 on AIX) that the physical sequence of rows within a table should not matter to the performance of the system. Unfortunately, this is not the case. As any DB2 professional is aware, ?clustering? the rows in a table in the same order as the primary key index can greatly improve the performance of the queries.

Note: Some releases of Oracle prior to 7.3.4 may support ORDER BY with CTAS, but for AIX 7.3.3 and before generate a syntax error when ORDER BY is used with CTAS.  Oracle does allow the use of the INDEX ?hint? to request an ordered copy of the table.

Here is an example of INDEX hint with CTAS.

create table vbap_sorted
tablespace vbap_copy
storage (initial 500m
next 50m
freelists 30
maxextents unlimited
)
as
select /*+ index(vbap vbap___0) */
*
from
sapr3.vbap
;


CTAS with ORDER BY

In some Oracle releases you can add the ORDER BY clause to the CTAS statement to physically re-sequence the table rows. Unlike CTAS with an index hint, the ORDER BY method can be run in parallel since a full-table scan will be invoked. Following the gathering of the table rows, all rows will be sorted in the PSAPTEMP tablespace before populating the new table.

create table vbap_sorted
tablespace vbap_copy
storage (initial 500m
next 50m
maxextents unlimited
)
as
select *
from
sapr3.vbap
order by
mandt,
vbeln,
posnr;