Showing posts with label oracle. Show all posts
Showing posts with label oracle. Show all posts

Tuesday, June 16, 2009

Oracle/Sybase Discovery

I'm not sure I can bring you a lot of value today, but maybe just this one small bit of info will help you discover a wealth of information. After doing Oracle and SQL Server for many years, I am now learning Sybase as well. Here's today's discovery:

What is called an "inline view" in Oracle is called a "derived table" in Sybase. Derived Tables have been available in Sybase since ASE 12.5.2.

I was happily surprised to find that the column aliases can be used to select from the derived table.

Another thing I learned was that the derived table must have a name. Here's a simple example:

select * from
(select sum(advance) from total_sales) dt

"dt" is the name in this example.

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

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, April 2, 2007

Wasted

NOTE: If you are completely reloading data warehouse tables in an Oracle database then you should truncate the tables first instead of deleting the rows because just deleting the rows doesn't adjust the high water mark and your table can just keep expanding and expanding.

Here are some suggestions for finding out if a table is wasting space:

The following script came from http://www.dbasupport.com/oracle/scripts/ and it will show you the allocated, used and unused space for a particular object.

set echo off
set serveroutput on
set verify off
accept v_user prompt 'Schema: '
accept v_object prompt 'Object: '
accept v_object_type prompt 'Object Type: '
declare
VAR1 number;
VAR2 number;
VAR3 number;
VAR4 number;
VAR5 number;
VAR6 number;
VAR7 number;
VAR8 number;
vtable varchar2(30);

begin
dbms_space.unused_space(upper('&v_user'),upper('&v_object'),upper('&v_object_type'),VAR1,VAR2,VAR3,VAR4,V

AR5,VAR6,VAR7);
VAR2 := (VAR2)/1024/1024;
VAR4 := (VAR4)/1024/1024;
VAR8 := (VAR2-VAR4);
dbms_output.put_line('OBJECT_NAME = ' upper('&v_object'));
dbms_output.put_line('------------------------------');
dbms_output.put_line('TOTAL_BLOCKS = 'VAR1);
dbms_output.put_line('TOTAL_MBYTES = 'VAR2);
dbms_output.put_line('UNUSED_BLOCKS = 'VAR3);
dbms_output.put_line('UNUSED_MBYTES = 'VAR4);
dbms_output.put_line('LAST_USED_EXTENT_FILE_ID = 'VAR5);
dbms_output.put_line('LAST_USED_EXTENT_BLOCK_ID = 'VAR6);
dbms_output.put_line('LAST_USED_BLOCK = 'VAR7);
dbms_output.put_line('TOTAL_USED_MBYTES = 'VAR8);
end;
/
set verify on
set echo on

+++

If you have enough space in the current tablespace, you can clear up the wasted space like this:

alter table table_name move;

This will invalidate the indexes and you will have to rebuild them like this:

alter index index_name rebuild;

I'll meet you further on up the road.

Jim