Oracle

Материал из noname.com.ua
Перейти к навигацииПерейти к поиску


Заметки по установке и работе с Oracle

Установка ORACLE 10 на Solaris

Подготовка к установке

  • добавить пользователя oracle, задать ему пароль
useradd -d /export/home/oracle -m -s /usr/bin/bash oracle
passwd oracle
  • создать 2 группы, dba и oinstall (назначение второй - мне не ясно), добавить пользователя в группы
grouppadd dba
grouppadd oinstall
usermod -g dba -G oinstall oracle
  • проверить наличие свободного места. (в моем случае - в разделе /export)
  • установить значения переменных окружения (я вписал их как в .profile так ив .bashrc):
# su - oracle
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
-bash-3.00$ env
HZ=
SHELL=/usr/bin/bash
TERM=xterm
TMPDIR=/tmp
ORACLE_SID=orcl
ORACLE_BASE=/export/home/oracle
MAIL=/usr/mail/oracle
PATH=/export/home/oracle/10g/bin:/usr/bin:
PWD=/export/home/oracle
TZ=EET
SHLVL=1
HOME=/export/home/oracle
TMP=/tmp
LOGNAME=oracle
DISPLAY=localhost:0.0
ORACLE_HOME=/export/home/oracle/10g
  • Заливаю инсталляционные файлы по ftp (сразу в каталог oracle, вся инсталляция будет проходить под аккаунтом oracle)
  • Запускаю инсталлятор.

Установка

В процессе установки инсталлятор проверит парамеры системы (отдельно параметры ядра, править в файле /etc/system), место на диске и прочее. После чего запуститься процесс установки.
Инсталлятор попросит запустить от рута 1 файл (скрипт) для установки бинарников в /usr/local/bin
Внимание: Обязательно убедиться что переменные окружения и особенно ORACLE_SID установлены верно. Без этого скрипт

bash-3.00$ /export/home/oracle/10g/bin/emctl start dbconsole

завершиться с ошибкой. Мне пришлось подправить переменную на ходу и перезапустить скрипт.

Сама установка заняла у меня около 1 часа.

Post-install

В файле /$ORACLE_HOME/10g/bin/dbstart (строка 77)

#ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle
ORACLE_HOME_LISTNER=$ORACLE_HOME

Создание базы данных

Насколько я смог понять (ошибаюсь?) в отличии от MySQL каждая база данных обслуживается своим процессом (instance)

В моем случае я делал это для пользователя oracle (в противном случае, вероятно, не получиться подключиться к базе как sysdba)

Вариант один

export ORACLE_SID=test
export ORACLE_HOME=/path/to/oracle/home

Create a minimal init.ora

# $ORACLE_HOME/dbs/init<sid>.ora
control_files = (/path/to/control1.ctl,/path/to/control2.ctl,/path/to/control3.ctl)
undo_management = AUTO
undo_tablespace = UNDOTBS1
db_name = test
db_block_size = 8192
sga_max_size = 1073741824 #one gig
sga_target = 1073741824 #one gig


Create a password file

$ORACLE_HOME/bin/orapwd file=$ORACLE_HOME/dbs/pwd<sid>.ora password=oracle entries=5


Start the instance

sqlplus / as sysdba
startup nomount

Create the database

create database test
logfile group 1 ('/path/to/redo1.log') size 100M,
            group 2 ('/path/to/redo2.log') size 100M,
            group 3 ('/path/to/redo3.log') size 100M
character set WE8ISO8859P1
national character set utf8
datafile '/path/to/system.dbf' size 500M autoextend on next 10M maxsize unlimited extent management local
sysaux datafile '/path/to/sysaux.dbf' size 100M autoextend on next 10M maxsize unlimited
undo tablespace undotbs1 datafile '/path/to/undotbs1.dbf' size 100M
default temporary tablespace temp tempfile '/path/to/temp01.dbf' size 100M;


Note: there's some other things you can do here, like "ARCHIVELOG" "SET TIME_ZONE =" and "USER SYS IDENTIFIED BY password" and "USER SYSTEM IDENTIFIED BY password"


6. Run catalog and catproc

@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql


7. Change passwords

alter user sys identified by whatever;
alter user system identified by whatever;


OMF: minimal manual Oracle create database syntax

Set your ORACLE_SID

export ORACLE_SID=test
export ORACLE_HOME=/path/to/oracle/home

Create a minimal init.ora

# $ORACLE_HOME/dbs/init<sid>.ora
 
control_files = (/path/to/control1.ctl,/path/to/control2.ctl,/path/to/control3.ctl)
undo_management = AUTO
db_name = test
db_block_size = 8192
sga_max_size = 1073741824 #one gig
sga_target = 1073741824 #one gig
db_create_file_dest = /path/to/datafile/location #OMF
db_create_online_log_dest_1 = /path/to/first/redo_and_control_file/location #OMF
db_create_online_log_dest_2 = /path/to/second/redo_and_control_file/location #OMF
db_recovery_file_dest = /path/to/flash/recovery/area #OMF
#note it’s a good idea to also have background_dump_dest, user_dump_dest, and core_dump_dest here as well


3. Create a password file

$ORACLE_HOME/bin/orapwd file=$ORACLE_HOME/dbs/pwd<sid>.ora password=oracle entries=5


4. Start the instance

sqlplus / as sysdba
startup nomount


5. Create the database

create database test
character set WE8ISO8859P1
national character set utf8
undo tablespace undotbs1
default temporary tablespace temp;

You can even do this and it will work, the ultimate in minimalism:

create database test;


Note: There's some other things you can do here, like "ARCHIVELOG" "SET TIME_ZONE =" and "USER SYS IDENTIFIED BY password" and "USER SYSTEM IDENTIFIED BY password"

Note 2: This is so minimal because you are using Oracle Managed Files as seen in #2


6. Run catalog and catproc

@?/rdbms/admin/catalog.sql

@?/rdbms/admin/catproc.sql

Standard create Oracle database syntax

After creating your init.ora file with the appropriate parameters you can use the "create database" command in SQL*Plus to create a database:

Make sure that your have your $ORACLE_HOME and $ORACLE_SID set properly and that you sign-on as SYSDBA:

startup nomount;
CREATE CONTROLFILE REUSE DATABASE "OLDLSQ" NORESETLOGS
NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 2
MAXDATAFILES 240
MAXINSTANCES 1
MAXLOGHISTORY 113
LOGFILE
GROUP 1 ('/u03/oradata/oldlsq/log1a.dbf',
'/u03/oradata/olslsq/log1b.dbf') SIZE 30M,
GROUP 2 ('/u04/oradata/oldlsq/log2a.dbf',
'/u04/oradata/oldlsq/log2b.dbf') SIZE 30M
DATAFILE
'/u01/oradata/oldlsq/system01.dbf',
'/u01/oradata/oldlsq/mydatabase.dbf'
;

Полезные комманды

Все комманды вводить после su - oracle

lsnrctl status
bash-3.00$ lsnrctl status

LSNRCTL for Solaris: Version 10.2.0.1.0 - Production on 27-MAY-2010 10:55:05

Copyright (c) 1991, 2005, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Solaris: Version 10.2.0.1.0 - Production
Start Date                27-MAY-2010 09:25:39
Uptime                    0 days 1 hr. 29 min. 25 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/10g/network/admin/listener.ora
Listener Log File         /oracle/10g/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=solaris-test)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
bash-3.00$ tnsping test-solaris
TNS Ping Utility for Solaris: Version 10.2.0.1.0 - Production on 27-MAY-2010 11:00:22

Copyright (c) 1997, 2005, Oracle.  All rights reserved.

Used parameter files:
/oracle/10g/network/admin/sqlnet.ora

TNS-03505: Failed to resolve name
bash-3.00$ tnsping solaris-test

TNS Ping Utility for Solaris: Version 10.2.0.1.0 - Production on 27-MAY-2010 11:00:29

Copyright (c) 1997, 2005, Oracle.  All rights reserved.

Used parameter files:
/oracle/10g/network/admin/sqlnet.ora

Used EZCONNECT adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=solaris-test.))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.2.2)(PORT=1521)))
OK (10 msec)

Файлы и их назначение

/var/opt/oracle/oratab
#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcl:/export/home/oracle/10g:Y

Термины

  • Схема (Schema) - коллекция объектов БД. (аналог database в mysql ? )

Использованное место

select  tsu.tablespace_name, ceil(tsu.used_mb) "size MB"
,       decode(ceil(tsf.free_mb), NULL,0,ceil(tsf.free_mb)) "free MB"
,       decode(floor(tsu.used_mb- tsf.free_mb), NULL,0,floor(tsu.used_mb- tsf.free_mb)) "used MB"
,       decode(100 - ceil(tsf.free_mb/tsu.used_mb*100), NULL, 100,
               100 - ceil(tsf.free_mb/tsu.used_mb*100)) || ' %' "% used"
from    (select tablespace_name, sum(bytes)/1024/1024 used_mb
        from    dba_data_files group by tablespace_name ) tsu
,       (select tablespace_name, sum(bytes)/1024/1024 free_mb
        from    dba_free_space group by tablespace_name) tsf
where   tsu.tablespace_name = tsf.tablespace_name (+)
order   by (decode(100 - ceil(tsf.free_mb/tsu.used_mb*100), NULL, 100, 100 - ceil(tsf.free_mb/tsu.used_mb*100))) desc
[15:08:00] Oleg YUrchenko: http://www.dba.az/index.php?option=com_content&view=article&id=58:dbafreespace-misunderstanding-how-oracle-populates-it&catid=35:oracle-articles&Itemid=65

Ссылки