Wednesday, May 23, 2007

ORACLE - No Table Owner in Indexfile

I was trying to use an indexfile generated from Oracle's "imp" command to create the indexes on a database after the table rows were imported but I ran into a problem with the way the table names were specified in the "on" clause of the index create statements. They were in the form tablename instead of owner.tablename. This was giving me:

ORA-00942: table or view does not exist

The default indexfile has "connect username;" statements in it, but these statements prompt a request for a password, so that wouldn't work for me.

In order to solve this problem I set the "current_schema" in the indexfile script to the correct table owner whenever the owner changed for a group of index creation statements.

Here's the statement that I used:

alter session set current_schema = owner;

I had to manually put the statements in the script, but it was a lot faster for me to do it that way than trying to come up with a script to do the same thing.

I'll meet you further on up the road.

Jim

Friday, May 18, 2007

ORACLE - Clearing Out the Recycle Bin in 10g

I was trying to delete a group of tables in a 10.2.0.3 database and I noticed that the table count didn't decrease after the drop statements. Then I remembered the flashback recovery feature and figured I'd better check the names of the existing tables to see if they had been logically moved to a recycle bin that I'd heard about.

Well my next question was, "How do I clear the recycle bin?", and here's what I found:

PURGE RECYCLEBIN;

This clears everything in your recycle bin.

If you want to bypass the recycle bin in the original drop, you can use a statement like:

DROP TABLE RECYCLETEST PURGE;

For more tips about Flashback table and the recycle bin go to:
http://www.oracle.com/technology/pub/articles/10gdba/week5_10gdba.html

I'll meet you further on up the road.

Jim Hill

Thursday, May 17, 2007

ORACLE - Splitting Long Lines in an Indexfile

====================================================
vi commands
====================================================

------------------------
Issue
------------------------
I have an indexfile from Oracle that has some really long lines in it that I need to break into several lines. Whenever I see ", PARTITION" in a line, I need to break the line there.

For example:

BEFORE:

characters words, PARTITION characters words, PARTITION characters words, PARTITION

AFTER:

characters words
, PARTITION characters words
, PARTITION characters words
, PARTITION

------------------------------
vi Solution
------------------------------

:%s/, PARTITION/^M, PARTITION/g

(NOTE: I got the ^M by holding down Ctrl-v and pressing 'm'. This will insert the newline.)

---

I'll meet you further on up the road.
Jim

Friday, May 11, 2007

SQL - Finding the SQL Server Version

SELECT SERVERPROPERTY('ProductLevel')


OR

select @@version

(NOTE: The output on the above command was too big to see in my remote terminal session, so I cut and pasted it to notepad to see it all.)

I confirmed that I was on SQL2000 SP3 (or SP3a) when I found version number 8.00.760; but how do I know if I have SP3 or SP3a? Here's how you find out...

Distinguishing between SQL2000 SP3 and SP3a

To figure out whether you have SP3 or SP3a installed, you have to figure out the version number of the Net-Library file, ssnetlib.dll. This file can be found in one of these locations:

Default instance: C:\Program Files\Microsoft SQL Server\MSSQL\Binn\ssnetlib.dll

Named instance: C:\Program Files\Microsoft SQL Server\MSSQL$\Binn\ssnetlib.dll

Once I found the file I was able to just mouse over it and a box that included the version popped up. You might have to right-click on the file, select "properties", and then click on the version tab.

If you see version 2000.80.760.0, you have SP3; but if the version is 2000.80.766.0, you have SP3a.

I have version SP3a, so I'm happy.

Here are some links to some more good info about SQL Server versions:

http://rage.against.org/DeterminingSQLServerVersion

This one has a nice chart of versions for SQL 2005 and SQL 2000:

http://soulsolutions.com.au/Blog/tabid/73/EntryID/18/Default.aspx

I'll meet you further on up the road.

Jim Hill

Thursday, May 10, 2007

Oracle - Temporarily Changing a User's Password

Another interesting, undocumented command syntax is the "alter user ... using values ..."

To temporarily change a user's password then set it back, take a note of the PASSWORD field in DBA_USERS. Change the password and then set it back to what it was:

SQL> select username, password from dba_users where username='BUBBA';

USERNAME PASSWORD
------------------------------ ------------------------------
BUBBA 3104BC5BB78B55BE

SQL> alter user bubba identified by bubba;
User altered.

SQL> conn bubba/bubba
Connected.

SQL> conn / as sysdba
Connected.

SQL> select username, password from dba_users where username='BUBBA';

USERNAME PASSWORD
------------------------------ ------------------------------
BUBBA 7D2D7383FC9288B7

SQL> alter user bubba identified by values '3104BC5BB78B55BE';
User altered.

SQL> select username, password from dba_users where username='BUBBA';

USERNAME PASSWORD
------------------------------ ------------------------------
BUBBA 3104BC5BB78B55BE

Tuesday, May 8, 2007

Oracle - Getting “ORA-01031: insufficient privileges” when trying to logon as sysdba

Here's a little background:

I set up 2 new databases and I couldn't logon as sysdba without providing the password. I was trying:

sqlplus "/as sysdba"

It gave me this:

ORA-01031: insufficient privileges

Instead I had to do this:

sqlplus sys/password as sysdba

This problem was also preventing "rman" from working as it should.

Here's a full description of the error:

ORA-01031: insufficient privileges

Connect Internal has been issued
with no password. For local connections the user is NOT in the DBA group
as compiled into the 'oracle' executable.
For remote connections you must always supply a
password.

This error can also
occur after a successful connect internal/password
if there REMOTE_LOGIN_PASSWORDFILE is either unset or set to NONE
in
the init.ora file.

The problem that I was having turned out to be related to the fact that the wrong OSDBA group got compiled into the Oracle software.

I found the following instructions on the Oracle Metalink website and the described process fixed my problems.

OSDBA & OSOPER Groups on Unix/Linux

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The 'OSDBA' and 'OSOPER' groups are chosen at installation time and usually both default to the group 'dba'. These groups are compiled into the 'oracle' executable and so are the same for all databases running from a given ORACLE_HOME directory.The actual groups being used for OSDBA and OSOPER can be checked thus:

cd $ORACLE_HOME/rdbms/lib

cat config.[cs]

The line '#define SS_DBA_GRP "group"' should name the chosen OSDBA group.

The line '#define SS_OPER_GRP "group"' should name the chosen OSOPER group.

If you wish to change the OSDBA or OSOPER groups this file needs to be modifiedeither directly or using the installer. Eg: For an OSDBA group of 'mygroup' If your platform has config.c (this is the case for HP-UX, Compaq Tru64 Unixware and Linux):

Change: #define SS_DBA_GRP "dba"

to: #define SS_DBA_GRP "mygroup"

If your platform has config.s:

Due to the way different compilers under different architectures generate assembler code, it's not possible to give a universal rule. Here are some examples:

Sun SPARC Solaris:

------------------

Change both ocurrences of

.ascii "dba\0" to .ascii "mygroup\0"

IBM AIX/Intel Solaris:

----------------------

Change both ocurrences of

.string "dba" to .string "mygroup"

To effect any changes to the groups and to be sure you are using the groupsdefined in this file relink the Oracle executable.Be sure to shutdown all databases before relinking:

Eg: mv config.o config.o.orig

make -f ins_rdbms.mk ioracle

(Note config.o will be re-created by make because of dependencies automatically)

For a group to be accepted by Oracle as the OSDBA or OSOPER group it must:

- Be compiled into the Oracle executable

- The group name must exist in /etc/group (or in 'ypcat group' if NIS is being used)

- It CANNOT be the group called 'daemon'

Note: The commands above are examples and may vary between platforms.

Note: Some Oracle documentation refers to the ability to define OSDBA and OSOPER roles using group names of the form 'ORA_sid_OSDBA'. This functionality has not been implemented on Unix.

+++

I'll see you further on up the road.

Jim

Monday, May 7, 2007

Oracle - Dealing with a Full Flash Recovery Area

Finding the current status of the flash_recovery_area:

COL name FORMAT A32 HEADING 'File Name'
COL spc_lmt_mb FORMAT 99999.99 HEADING 'SpaceLimit(MB)'
COL spc_usd_mb FORMAT 99999.99 HEADING 'SpaceUsed(MB)'
COL spc_rcl_mb FORMAT 99999.99 HEADING 'ReclmSpace(MB)'
COL number_of_files FORMAT 99999 HEADING 'Files'

SELECT name ,space_limit /(1024*1024) spc_lmt_mb ,space_used /(1024*1024) spc_usd_mb ,space_reclaimable /(1024*1024) spc_rcl_mb ,number_of_files FROM v$recovery_file_dest;

+++

Increasing the space allocated to the Flash Recovery Area:

ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE = '6G' SCOPE=BOTH SID='*';

+++

Clearing up the archive logs from the flash recovery area:

NOTE: You will need to take a full backup after doing the following...

1) Delete the ones that aren't needed.
2) Connect to RMAN
a) CROSSCHECK ARCHIVELOG ALL;
b) DELETE EXPIRED ARCHIVELOG ALL;

---

I'll meet you further on up the road.

Jim Hill