Tuesday, December 13, 2016

Oracle Passwords - how to unlock and change

Oracle passwords - changing, expiring and locking users

Oracle Tips by Steve Karam, OCM

See these important notes on how to un-lock a database and make_a password_not_expire.

Change Oracle passwords, expire, and lock unnecessary usersThere are many users on a full installation of Oracle, most of which you probably won't need. To lock an Oracle user account, you can use the following command:
alter user username account lock;
To unlock the user, simply replace 'lock' with 'unlock.'
Oracle comes with a few default accounts that should never be locked or dropped. These include: SYS, SYSTEM, SYSMAN (Oracle 10g), OUTLN. However, you do want always to change the password for these users. The default password for SYS is change_on_install. It is important that you follow these directions. To change the password for a user:
alter user username identified by new_password;
For non-critical users, you can always lock and expire the account. We can change the password for, lock, and expire the account CTXSYS all at once:
alter user ctxsys identified by 0bscur3 account lock password expire;
This will ensure that CTXSYS password has been changed from the self evident default of CTXSYS; on a successful login the password will have to be changed (because it is expired); and because it is locked, he account can't be logged into under any circumstances.
To aid you in this task, here is a list of users that come with a full database installation that are safe to expire and lock if you are not using their functionality:
  1. AURORA$ORB$UNAUTHENTICATED - Jserver user
  2. BI - demo user
  3. CTXSYS - Oracle Text/interMedia administrator
  4. DBSNMP - Oracle Intelligent Agent
  5. DSSYS - Dynamic Services and Syndication Server
  6. HR - demo user
  7. MDSYS - Spatial administrator
  8. ORDSYS/ORDPLUGIN - Object Relational Data user
  9. OE - demo user
  10. PERFSTAT - Statspack administrative user
  11. SCOTT - demo user
  12. SH - demo user
  13. TRACESVR - Oracle trace server
  14. WKSYS - Ultrasearch administrator
The best rule of thumb is to install only the features you need when you install Oracle. If you are not going to use Spatial, interMedia, or UltraSearch, don't install them. Then you will not have to worry about those three users.
Once an account has been expired, it can only be revived by assigning it a new password.  You can save the old password.

ALTER USER scott IDENTIFIED BY tiger;

You can then re-add the original password, provided that password_reuse_max is greater than zero.

Also see our notes on:

Friday, December 9, 2016

SQLDeveloper - How to change SAVE AS default path for files and Export

2
Is there a way to configure the directory SQL Developer uses to save SQL scripts?
When I do ... File, New, SQL File ... the directory is always set to the \AppData\Roaming\ for my user.
I'd like to set the default to a directory in my dev source code tree.
shareimprove this question
  
If it is hardcoded, you should think about just dropping a symlink to your desired directory in Appdata\roaming. – surfasb Mar 6 '12 at 14:57
  
Checked the registry and can't find any setting – SteveC Mar 8 '12 at 16:15

3 Answers


When you go to save your sql file you can change where the save defaults to. Change it in Tools>Preferences>Database>Worksheet Parameters. You can browse to a new location under "Select default path to look for scripts"
Can also change the Export Data so that it defaults to somewhere else. Go to Tools>Preferences>Database>Export and Browse to the location you want to export to for "Directory"
This used to annoy me bad before I changed it. Now all my saves and exports default to a folder I actually use.
shareimprove this answer


Found it ...
In the Choose Directory dialog, the left hand side has a number of commonly used short cuts, e.g. Desktop, Documents, but you can also have your own directories in there
shareimprove this answer

There is a post about this in OTN, and AlexAnd's solution opens the specified folder when I do File => Open.
The post is @
AlexAnd is saying that locate "\sqldeveloper\sqldeveloper\bin\sqldeveloper.conf" and simply add "AddVMOption -Dide.user.dir=" (where " is the full folder path that you like to use) to that file.
The disadvantage of this solution is that it will also move your settings folders to the specified folder (for me it was about 34MB), I use drop box to keep my queries so that is a wasted space.

Wednesday, December 7, 2016

How to find a session in Oracle DB and kill it.

select inst_id,sid,serial# from gv$session where username='HYP_CCC'; alter system kill session '70,5,@1' ; ---------- Other code that works: SELECT 'alter system kill session'||chr(39)||sid||','||serial#||','||chr(64)||inst_id||chr(39)||';' FROM gv$session where username = 'HYP_CCC'; SELECT 'alter system kill session'||chr(39)||sid||','||serial#||','||chr(64)||inst_id||chr(39)||';' FROM gv$session where type = 'USER'; SELECT 'alter system kill session'||chr(39)||sid||','||serial#||','||chr(64)||inst_id||chr(39)||';' FROM gv$session WHERE username IS NOT NULL OR username <> 'SYS'; alter system kill session'5,13,@1'; alter system kill session'6,107,@1'; alter system kill session'8,11,@1'; alter system kill session'9,5521,@1'; alter system kill session'14,2221,@1'; alter system kill session'15,2233,@1'; alter system kill session'16,692,@1'; alter system kill session'68,3,@1'; alter system kill session'70,5,@1'; alter system kill session'73,2270,@1'; alter system kill session'74,3350,@1'; alter system kill session'75,3255,@1'; alter system kill session'130,7,@1'; alter system kill session'133,2867,@1'; alter system kill session'134,1234,@1'; alter system kill session'145,1937,@1'; alter system kill session'146,902,@1'; alter system kill session'191,23,@1'; alter system kill session'192,11,@1'; alter system kill session'199,6839,@1'; alter system kill session'200,1959,@1'; alter system kill session'201,1694,@1';

Wednesday, November 16, 2016

Oracle Loader with SQL Developer

http://www.thatjeffsmith.com/archive/2012/08/using-oracle-sql-developer-to-setup-sqlloader-runs/
URL - Click Me That is all.

Friday, March 25, 2016

Rebuild targets.xml for Oracle Enterprise Manager Grid Control Agent

 1. Agents installations before 10.2.0.3 have a bug in the 'agentca' command
that prevents the targets.xml file from getting populated with the initial
parameters (AGENT_TOKEN, ORACLE_EMD, and/or HOST) when the file does not
already exist. To work around this we will need to manually create a targets.xml
file if it does not exist.

Windows create the new file in the Agent %ORACLE_HOME%\sysman\emd\ directory.
(Where %ORACLE_HOME% is the agent's home)

Unix$
$ cd $ORACLE_HOME/sysman/emd (where $ORACLE_HOME is the Agent's home)
$ touch targets.xml.
 2. Once you have created the targets.xml file, view the Agent's
$ORACLE_HOME/sysman/config/emd.properties file. 
Copy the values for:
agentSeed=12345 EMD_URL=http://hostname.oracle.com:9876/emd/main
3. Manually update the new targets.xml and add the following entries to the file following
the syntax exactly:
<targets agent_seed="agentseed from emd.properties">
  <target name="hostname and port from emd.properrties EMD_URL" type="oracle_emd">
  <target name="hostname as it appears in the emd_url" type="host">
</targets>
  <targets agent_seed="agentseed from emd.properties">
  <target type="oracle_emd" name="hostname and port from emd.properties EMD_URL">
  <target type="host" name="hostname as it appears in the emd_url">
</targets>
For example:

<targets agent_seed="12345">
  <target type="oracle_emd" name="hostname.domain.com:port">
  <target type="host" name="hostname.domain.com">
</targets>
<targets agent_seed="12345">
  <target name="hostname.domain.com:port" type="oracle_emd">
  <target name="hostname.domain.com" type="host">
</targets>

4. Force target re-discovery:

a. Verify that the environment variables are setup for the Management Agent:
$ORACLE_HOME set$ORACLE_HOME/bin in $PATH
b. The agentca utility is expecting the oraInst.loc to be located in the root of the Agent's $ORACLE_HOME

NOTE: Solaris puts the oraInst.loc in /var/opt/oracle.
Agentca will not fine the oraInst.loc on a Solaris platform.
For Solaris platforms you need to create a soft link:
$ORACLE_HOME/oraInst.loc to /var/opt/oracle/oraInst.loc

c. Run agentca -d to force a new discovery of the targets on the host
agentca -d 

Thursday, February 18, 2016

Another Corrupt Block in Oracle 11g - fixed

2016_06_13 update
Another bad block located:
SQL Error: ORA-01578: ORACLE data block corrupted (file # 8, block # 61663)ORA-01110: data file 8: '/home/oracle/app/oracle/oradata/orcl/HYP_DM_TBL_3.DBF'

Then to fix this one I had to find the problem using:
select owner, segment_type, segment_namefrom dba_extentswhere file_id=8  and 61663  between block_id and block_id+blocks-1;
Located the ROWS that were good with this command:

select * from entity_Hour_fact where ROWNUM <2127000 order by 2;
Anything more would error with this:
SQL Error: ORA-01578: ORACLE data block corrupted (file # 8, block # 61663)ORA-01110: data file 8: '/home/oracle/app/oracle/oradata/orcl/HYP_DM_TBL_3.DBF'01578. 00000 -  "ORACLE data block corrupted (file # %s, block # %s)" *Cause:    The data block indicated was corrupt. This was a physical           corruption, also called a media corruption. The cause is unknown           but is most likely external to the database. If ORA-26040 is also           signaled, the corruption is due to NOLOGGING or UNRECOVERABLE           operations.
Will copy the old file to a new filename:
with a CTAS command:

Create Table As Select...

scroll down to see older examples.

------------------------------------------------
2016_02_18

After more bad blocks...I replaced the SSD drive.

Error in Enterprise Manager:
ORA-1578 [ORA-01578: ORACLE data block corrupted (file # 2, block # 35170)]

Error in CCC.LOG file was this:
----
### The error may exist in com/hyperformix/pb/server/mapper/IAnalyzeMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: call DATAMART_LIB.Analyze_pb_objects()
### Cause: java.sql.SQLException:
ORA-01578: ORACLE data block corrupted (file # 2, block # 35170)
ORA-01110: data file 2: '/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf'
ORA-06512: at "SYS.DBMS_STATS", line 20337
ORA-06512: at "SYS.DBMS_STATS", line 20360
ORA-06512: at "HYP_CCC9.DATAMART_LIB", line 2472
----

Then to fix this one I had to find the problem using:

select owner, segment_type, segment_name
from dba_extents
where file_id=2  and 35170  between block_id and block_id+blocks-1;
This returns:
OWNER                          SEGMENT_TYPE   SEGMENT_NAME                                               
------------------------------ ------------------       -------------------------------------------------------
SYS                                  TABLE                   WRI$_OPTSTAT_HISTGRM_HSTRY_BAD         
Using this I found that it was in the SYSAUX tablespace.

So I moved it to the SYSAUX1 tablespace, which was empty.

So I renamed the table to have a _ on the end and copied the Index definitions.

Then I use a CTAS method to copy the table.
SELECT * FROM TABLENAME WHERE ROWNUM < 410000
This allows me to get most of the table and stop pulling data before I hit the Corrupted Block.

select * from SYS.WRI$_OPTSTAT_HISTGRM_HISTORY_ where rownum < 410000 order by 3;

It was trial and error using first ROWNUM of 1000, 5000, 100000, 1000000 till I hit the error and then backed down until I got no error.

This was the CTAS command I used:

CREATE    TABLE SYS.WRI$_OPTSTAT_HISTGRM_HISTORY TABLESPACE SYSAUX1 STORAGE    (      INITIAL 500m NEXT 50m maxextents unlimited    )    parallel    (      degree 4    ) ASSELECT    *  FROM    SYS.WRI$_OPTSTAT_HISTGRM_HISTORY_  WHERE    rownum < 410000  ORDER BY    3;
These are the indexes:

  CREATE INDEX "SYS"."I_WRI$_OPTSTAT_H_OBJ#_ICOL#_ST" ON "SYS"."WRI$_OPTSTAT_HISTGRM_HISTORY" ("OBJ#", "INTCOL#", SYS_EXTRACT_UTC("SAVTIME"), "COLNAME")   PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS   STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)  TABLESPACE "SYSAUX1" ; 
  CREATE INDEX "SYS"."I_WRI$_OPTSTAT_H_ST" ON "SYS"."WRI$_OPTSTAT_HISTGRM_HISTORY" (SYS_EXTRACT_UTC("SAVTIME"))   PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS   STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)  TABLESPACE "SYSAUX1" ;
I did NOT delete the original table space I just kept it and renamed it to:

alter table "SYS"."WRI$_OPTSTAT_HISTGRM_HISTORY_" rename to WRI$_OPTSTAT_HISTGRM_HSTRY_BAD;
If I delete the bad table then the Corrupt block may get used again...

Thursday, February 11, 2016

LOADER -- overcoming problems when bringing in staging data from other Data Manager instances.

Problems with bringing in Staging data from customer site.

1.  Transaction ID
2.  Data Source Types ID's
3.  Data Source Definitions
4.  Data Type Tables
5.  Migration status tables


6. Sequence numbers.

a. Get a list from both systems with this query:

-- Find last value for all Sequences in the Schema.
-- Be sure you have all the Sequences in the sequence_name list.

SELECT  * FROM  user_sequences WHERE  sequence_name IN ('APPLICATION_DIM_ID_SEQ','BASELINES_SEQ','CLUSTER_DIM_ID_SEQ',  'CLUSTER_ENTITY_MOTION_ID_SEQ','CONFIG_ID_SEQ','CONFIG_METRIC_DIM_ID_SEQ','DIVERSE_METRIC_SEQ',  'ENTITY_ID_SEQ','ENTITY_TYPE_ID_SEQ','GLOBAL_ID_SEQ','GROUP_ENTITY_CONFIG_ID_SEQ',  'GROUP_ENTITY_TMP_CONFIG_ID_SEQ','GROUP_XML_DOCUMENT_ID','HYFY_TPP_CONFIG_ID_SEQ',  'JOB_ACTIVITY_ERROR_SEQ','JOB_ACTIVITY_MIGRATE_SEQ','JOB_DGE_DETAIL_SEQ','JOB_ID_SEQ',  'METRIC_DIM_ID_SEQ','METRIC_RANGE_ID_SEQ','MIGRATION_SESSION_ID_SEQ','PROCESS_DIM_ID_SEQ',  'PROCESS_LOG_ID_SEQ','PURGE_LOG_CONFIG_SEQ','RESOURCE_POOL_ID_SEQ','ROLLUP_ID_SEQ',  'ROLLUP_TRANS_ID_SEQ','SERVER_DIM_ID_SEQ','SERVER_VIRTUAL_DIM_ID_SEQ','SOURCE_PARAMS_CONFIG_SEQ',  'SOURCE_TYPE_CONFIG_SEQ','STANDARD_METRICS_SEQ','SUBSYSTEM_DIM_ID_SEQ','WORKLOAD_LOG_DIM_ID_SEQ',  'WORKLOAD_LOG_ID_SEQ','WORKLOAD_TRANS_DIM_ID_SEQ','WORKLOAD_TRANS_ID_SEQ','PRECALC_TYPE_SEQ'); 

b. Compare them and adjust your Data Manager with the values that are LARGER from the customers system.  Only adjust the ones that need be moved up to match the customer's system.

c.  Use this to drop a list of sequences.  This only creates the commands to run in another database session, it does not execute the changes.

--- Drop Sequence numbers

SELECT
 -- Drop SEQUENCE
'drop sequence "HYP_CCC9"."'||column_value||'";' as p
FROM
  TABLE(sys.dbms_debug_vc2coll('GROUP_XML_DOCUMENT_ID','JOB_ACTIVITY_ERROR_SEQ',
  'JOB_ACTIVITY_MIGRATE_SEQ','METRIC_DIM_ID_SEQ','MIGRATION_SESSION_ID_SEQ','PROCESS_DIM_ID_SEQ',
  'PROCESS_LOG_ID_SEQ','PURGE_LOG_CONFIG_SEQ','ROLLUP_TRANS_ID_SEQ','SERVER_DIM_ID_SEQ',
  'SERVER_VIRTUAL_DIM_ID_SEQ','SOURCE_PARAMS_CONFIG_SEQ','SOURCE_TYPE_CONFIG_SEQ',
  'CLUSTER_ENTITY_MOTION_ID_SEQ','CONFIG_ID_SEQ','DIVERSE_METRIC_SEQ','ENTITY_ID_SEQ',
  'ENTITY_TYPE_ID_SEQ','GROUP_ENTITY_CONFIG_ID_SEQ'));
  
  
d. Use this to recreate a list of sequences. This only creates the commands to run in another database session, it does not execute the changes.

-- Create Sequence number
-- Create SEQUENCE
with
part1 as
(
Select
   'CREATE SEQUENCE  "HYP_CCC9"."'||column_value||'" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH ' as p,
   ROWNUM  rn
FROM
  TABLE(sys.dbms_debug_vc2coll('GROUP_XML_DOCUMENT_ID','JOB_ACTIVITY_ERROR_SEQ',
  'JOB_ACTIVITY_MIGRATE_SEQ','METRIC_DIM_ID_SEQ','MIGRATION_SESSION_ID_SEQ','PROCESS_DIM_ID_SEQ',
  'PROCESS_LOG_ID_SEQ','PURGE_LOG_CONFIG_SEQ','ROLLUP_TRANS_ID_SEQ','SERVER_DIM_ID_SEQ',
  'SERVER_VIRTUAL_DIM_ID_SEQ','SOURCE_PARAMS_CONFIG_SEQ','SOURCE_TYPE_CONFIG_SEQ',
  'CLUSTER_ENTITY_MOTION_ID_SEQ','CONFIG_ID_SEQ','DIVERSE_METRIC_SEQ','ENTITY_ID_SEQ',
  'ENTITY_TYPE_ID_SEQ','GROUP_ENTITY_CONFIG_ID_SEQ'))
  ),
  part2 as
  (
  select column_value||' CACHE 20 NOORDER  NOCYCLE ;' p,
  ROWNUM  rn
  from table( sys.odcinumberlist(1233,377498,1200,100751,334,201,8282,5692,258,167141,20089,100320,100140,2989,195842,153293,36641,10025,2812438))
  
  )
  select distinct p1.p||p2.p
  from part1 p1,part2 p2
  where p1.rn=p2.rn
  order by p1.p||p2.p;
  
The values are in the second part of the query and the sequence names are in the first part.
The join is matched on rownumbers.

LOADER - sqlldr - error File missing oranfsodm12.dll

This was originally from:
http://blogs.developpeur.org/jeremyjeanson/archive/2014/11/10/oracle-fichier-oranfsodm12-dll-absent-du-package-client.aspx

[Oracle] File missing oranfsodm12.dll client package

A small bug exists in the Oracle Database Client Package (12.1.0.2.0) for Microsoft Windows (32-bit) that is on the following download page :

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/database12c-win64-download-2297732.html

Oranfsodm12.dll the file is missing, preventing the use of SQL * Loader.
When checking the documentation, we discover that this is a modified version of the oraodm library.

https://docs.oracle.com/database/121/NTDBI/postcfg.htm

Oraodm12.dll by copying and renaming the oranfsodm12.dll we get a usable replacement dll without NFS. It can therefore be used on a client machine, but will not benefit from features of Direct NFS Client documented here (in version 11):

http://www.oracle.com/technetwork/articles/directnfsclient-11gr1-twp-129785.pdf
If the solution is acceptable in an environment of development to a production environment, it is best to get this DLL in the package DataBase.Only problem, this package does not exist in 32-bit.