2009-12-17

ORACLE CREATE

create database manualy:


* create PFILE
main changes:
- db_name
- control_files
- audit_file_dest
- background_dump_dest
- user_dump_dest
- core_dump_dest

example init[dbname].ora
*.__db_cache_size=939524096
*.__java_pool_size=16777216
*.__large_pool_size=16777216
*.__shared_pool_size=587202560
*.__streams_pool_size=33554432
*.control_files='[path]/control1.ora','[path]/control2.ora','[path]/control3.ora'
*.audit_file_dest='[path]/admin/adump'
*.core_dump_dest='[path]/admin/cdump'
*.user_dump_dest='[path]/admin/udump'
*.background_dump_dest='[path]/admin/bdump'
*.compatible='10.2.0.1'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_files=1500
*.db_name='[dbname]'
*.global_names=FALSE
*.job_queue_processes=10
*.log_archive_format='[dbname]%t%s%r.arc'
*.log_checkpoint_interval=10000
*.max_dump_file_size='10240'
*.open_cursors=1000
*.optimizer_mode='CHOOSE'
*.pga_aggregate_target=629145600
*.processes=400
*.query_rewrite_enabled='true'
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='[dbname]'
*.session_max_open_files=40
*.sga_target=1610612736
*.shared_pool_reserved_size=0
*.undo_management='AUTO'
*.undo_retention=100000
*.undo_tablespace='UNDO_TS'

* create password file for new database:
orapwd file=orapw[dbname] password=[pass]

* add new database to listener.ora and tnsnames.ora,

* create dirs for new database file,

* create dirs for trace logs as admin with subdirectories: adump, udump, cdump, bdump,

* set $ORACLE_HOME,$ORACLE_SID

* startup nomount

* run script:
spool crt_db.spool
startup nomount
create database [dbname]
user sys identified by [pass]
user system identified by [pass]
maxinstances 5
maxloghistory 5
maxlogfiles 10
maxlogmembers 5
maxdatafiles 1000
character set EE8ISO8859P2
national character set AL16UTF16
datafile '[path]/system01.dbf' size 512M autoextend on next 10M maxsize unlimited
sysaux datafile '[path]/sysaux01.dbf' SIZE 1024M
logfile group 1 ('[path]/redo01.log') size 100m,
group 2 ('[path]/redo02.log') size 100m,
group 3 ('[path]/redo03.log') size 100m
default temporary tablespace TEMP tempfile '[path]/temp01.dbf' size 2048M
undo tablespace UNDO_TS datafile '[path]/undotbs01.dbf' size 3000M autoextend off,
'[path]/undotbs02.dbf' size 512M autoextend on next 10M maxsize unlimited;
spool off
* run script:
spool catalog.spool
@$ORACLE_HOME/rdbms/admin/catalog.sql
spool off
spool catproc.spool
@$ORACLE_HOME/rdbms/admin/catproc.sql
spool off
spool catrep.spool
@$ORACLE_HOME/rdbms/admin/catrep.sql
spool off
spool initjvm.spool
@$ORACLE_HOME/javavm/install/initjvm.sql
spool off
spool dbmsrand.spool
@$ORACLE_HOME/rdbms/admin/dbmsrand.sql
spool off
spool utlrp.spool
@$ORACLE_HOME/rdbms/admin/utlrp.sql
spool off

2009-11-10

POSTGRESQL

all informations are inside great documentation
psql
psql [option] -d [dbname] -h [hostname] -U [username]
psql -ldb list
psql syntax:
\timingset show sql execution time
\qquit
\passwordset password
\psetchange psql settings
\lshow databases
\d [table]table desc
\c [database]connect to db
\daagregation functions
\db+tablespaces
\dcconversions
\df+functions
\dg+ \du+roles
\di+indexes
\ds+sequences
\dt+tables
\dv+views
\dSvtis+system views,tables,indexes,sequences
\dn+schemas
\dooperators
\dpprivileges
\encodingdb encoding
\l+db description
\zobjects with privileges
\o [file]spool file
\![command]run OS command
help commands:
\?info about commands with backslash
\hsql help
parameters:
show all;db parameters
show [parametr];show search_path
show search_pathcurrent schama
set search_path to [other_schema]now you can see objects from other schema

administrating:

variable PGDATA point to cluster catalog
pg_ctl status #db state
pg_ctl -D [directory] [action]
pg_ctl start | stop |restart #db start,stop you can add -l [logfile]
pg_ctl stop -m [smart | fast | immediate] #db stop smart(default), fast(with rolleback transactions, immediate(shutdown abort)
pg_controldata [cluser_dir] #cluster info
SELECT pg_database_size('[dbname]'); #show db size SELECT pg_size_pretty(pg_database_size('[dbname]')); #show db size SELECT pg_size_pretty(pg_total_relation_size('[table]')); #show table size with index SELECT pg_size_pretty(pg_relation_size('[table]')); #show table without index

DUMP:

-- export:
pg_dump [db_name] > [file] #dump in plaintext format
pg_dump -t '[table]' [db_name] > [file]
pg_dump -Fc #dump in pg_restore format
pg_dumpall > [file] #dump all databases
-- import:
psql [db] < [plik] #import from plaintext format
psql -f [file] postgres #import from plaintext format
pg_restore -d [baza] [plik] #import from pg_restore format
pg_restore -l [plik] #content of dumpfile

CREATE:

initdb --pgdata | -D [cluster_dir] [-E encoding] #cluster initialization,create template1 and postgres database
createdb [dbname] [-D tablespace] [-E encoding] [-O owner] [-T template to create new database]

change host database IP:

change in $PG_DATA/postgresql.conf
change in $PG_DATA/pg_hba.conf (according manual - chapter 20: Client Authentication)

misc:

ALTER TABLE [table] ALTER COLUMN [column] TYPE int USING [column]::int; #change column type from char to int

MANAGE ROLES:

--check
\dg #check system privs
SELECT * FROM pg_roles;
create role [role_name]; #create role
--change
ALTER ROLE [role_name] SUPERUSER | NOSUPERUSER | CREATEDB | NOCREATEDB | CREATEROLE | NOCREATEROLE | CREATEUSER | NOCREATEUSER | INHERIT | NOINHERIT | LOGIN | NOLOGIN | CONNECTION LIMIT [connlimit] | PASSWORD [password] | ENCRYPTED | UNENCRYPTED | VALID UNTIL [timestamp]
--change password
ALTER ROLE [role] PASSWORD '[pass]';

change object privs:

\z #check privs
=xxxx #privileges granted to PUBLIC
uname=xxxx #privileges granted to a user
group gname=xxxx #privileges granted to a group
r -- SELECT ("read")
w -- UPDATE ("write")
a -- INSERT ("append")
d -- DELETE
R -- RULE
x -- REFERENCES
t -- TRIGGER
X -- EXECUTE
U -- USAGE
C -- CREATE
T -- TEMPORARY
arwdRxt -- ALL PRIVILEGES (for tables)
* -- grant option for preceding privilege

GRANT [privs] ON [object] TO [role];

2009-10-23

LINUX PACKAGES

Packages

RPMYUMDPKGDESCRIPTION
rpm -q –changelog [package]changelog
rpm -U/-i –test [package].rpmtest before install
rpm -qa –last | headinstallation time of last packages
rpm -ql [package]dpkg -L [package]file list installed by package
rpm -qf [file]yum provides [file]dpkg -S [file]package name which is owner of file
rpm -qi [package]yum info [package]dpkg -s [package]info
rpm -q [package]dpkg-query -W [package]package version
rpm -qayum list installeddpkg –listinstalled packages
yum list [package]available packages in repository (about 15000), or package version in repo
rpm -q –whatrequires [package]package needs
rpm -q –provides [package]search missing libs, files
rpm -q –whatprovides libc.so.6yum list provides [shared_obj]
yum whatprovides "\*bin/[file]"search in which package is file
yum whatprovides libpthread*
yum list extrasunoficial repo packages list
rpm -qR [pakiet]yum deplist [pakiet]dependency list
yum check-updateupdate check
yum list updates
rpm -qp –scripts [package].rpmscripts check
rpm -qlp [package].rpmrpm content check
yum -Cusing cache
yum search [string]search by names, descriptions, summaries
yum list [string]\*search by [string]
yum history
yum-complete-transactioncomplete transaction after power crash etc.
yum-complete-transaction –cleanup-onlyclean transaction without resume the aborted transactions
yum clean allremove all traces of the version from /var/cache/yum
yum –releasever=[release_nr_to_sync] distro-sync
yum –rebuilddbrebuild rpm database, recreate database index

yum history

yum history listlast 20 transactins
yum history list allall transactions
yum history list [ID]
yum history info [ID]all info about transaction
yum history package-list [package_name]

Action column

DDowngradeAt least one package has been downgraded to an older version.
EEraseAt least one package has been removed.
IInstallAt least one new package has been installed.
OObsoletingAt least one package has been marked as obsolete.
RReinstallAt least one package has been reinstalled.
UUpdateAt least one package has been updated to a newer version.

Altered column

<Before the transaction finished, the rpmdb database was changed outside Yum.
>After the transaction finished, the rpmdb database was changed outside Yum.
*The transaction failed to finish.
#The transaction finished successfully, but yum returned a non-zero exit code.
EThe transaction finished successfully, but an error or a warning was displayed.
PThe transaction finished successfully, but problems already existed in the rpmdb database.
sThe transaction finished successfully, but the –skip-broken command line option was used and certain packages were skipped.

Misc

rpmreapertool for removing packages and find dependencies
package-cleanup –orphansunsupported packages
yumdownloader [package]get rpm package
yumdownloader –source [package]getsource package
rpm2cpio [package].rpm | cpio -idvunpack rpm2cpio
rpm2cpio [package].rpm | cpio -twhat is inside rpm
yum grouplistzainstalowane i dostepne grupy
yum groupinstall '[group]'instalacja grupy
yum groupinfo '[group]'
yum groupremove '[group]'
yum –downloadonly updatedownload only
rpm –querytagsshow all tags
rpm -qa –queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n"
rpm -qa –queryformat "%{NAME}-%{VERSION}-%{RELEASE}\t%{INSTALLTIME:date}"
rpm -qa –queryformat "%-40{NAME}%-20{VERSION}%-20{RELEASE}%{INSTALLTIME:date}\n"

Remarks

  • For RPM repos main database is located in /var/lib/rpm, it is BerkleyDB.

2009-10-21

LINUX RRDTOOL

describe database creation:
rrdtool create base.rrd -s 240 \
DS:DS-NAME:GAUGE | COUNTER | DERIVE | ABSOLUTE:HEARTBEAT:0:U \
RRA:CF:XFF:3:840
-s # step default is 300 sec
DS # DATA SOURCE
DS-NAME # variable name
RRA # ROUND ROBIN ARCHIVE - one archive in database
CF # CONSOLIDATION FUNCTION - MAX | MIN | AVERAGE | LAST
PDP # PRIMARY DATA POINT
XFF # XFILES FACTOR - factor, from 0 to 1 describe how many PDP can be   UNKNOWN before record will be write to database as UNKNOWN

example:
rrdtool create base.rrd -s 240 \
DS:input:COUNTER:600:0:U \
RRA:AVERAGE:0.5:3:840

base.rrd #database file
-s 240 #record step in database are set to 240 sec
input #data chain name
COUNTER #counter type
(COUNTER - best for increasing values as network interfaces counters, you take into account that interface network counters is roll back when achieve top value 232 or 2 64 and start from zero value
GAUGE - best for non increasing values)

example of counting data:
value of first probe = 100
value of second probe = 150
value of third probe = 180

for counter type - COUNTER
will be calculate difference 150-100=50 and 180-150=30
then depends on RRA ( AVERAGE, MAX, MIN or LAST),
values will be:
for AVERAGE=(50+30)/2=40,
for MAX=50,
for MIN=30,
for LAST=30

for counter type - GAUGE
will not be calculate difference
then depends on RRA
for AVERAGE= (100+150+180)/3=143,
for MAX=180,
for MIN=100,
for LAST=180

600 #600 sec, between each probe before probe will be marked as UNKNOWN,
0 #minimal value
U #maximal value "U" is UNKNOWN
0.5 #ratio of UNKNOWN probes 0-1, 0.5 means 50%
3 #result of CF function will be get from 3 probes but 50% from them can be UNKNOWN
840 #maximal amount of probes which can be store in database (amount of records), you can not resize database file so it must be set at startup.

let's calculate how many probes should be store in our database during week:

from previous settings we assume that value is generated from 3 probes which are collected every 240 sec
3*240=720 sec.
so final value will be store in database every 720 sec
720/60=12 min.
means that every value in our html chart will be refresh every 12 min.

3600/720=5 probes per hour
24*3600/720=120 probes per day,
7*24*3600/720=840 probes per week

other:
rrdtool dump [baza.rrd] [plik.xml] #export database to xml file
rrdtool fetch [baza.rrd] AVERAGE -s -6[min | h] #get records from last 6 min | hour.

OTHER LINKS

CSS
gs.statcounter.com
regex tester

2009-10-13

ORACLE BINARY CLONE

How to copy binaries to other server:
  1. turn off database and all services
  2. make backup of ORACLE_HOME dir
    at new server:
  3. make new ORACLE_HOME
  4. set other system variables
  5. put ORACLE_HOME from previous backup
  6. set user and group ORACLE_HOME dir
  7. remove .ora files from ORACLE_HOME/network/admin
  8. run command:
    ORACLE_HOME/oui/bin/runInstaller -clone -silent ORACLE_HOME=$ORACLE_HOME ORACLE_HOME_NAME=new_Oracle_home_name
  9. run script root.sh
  10. try run dbca

2009-10-01

ORACLE SCRIPTS

podane za Oracle® Database Reference 10g Release 2 (10.2) Part Number B14237-04

Table B-1 Creating the Data Dictionary Scripts

Script Name Needed For Description

catalog.sql

All databases

Creates the data dictionary and public synonyms for many of its views

Grants PUBLIC access to the synonyms

catproc.sql

All databases

Runs all scripts required for, or used with PL/SQL

catclust.sql

Real Application Clusters

Creates Real Application Clusters data dictionary views


Table B-2 Creating Additional Data Dictionary Structures

Script Name Needed For Run By Description

catblock.sql

Performance management

SYS

Creates views that can dynamically display lock dependency graphs

catexp7.sql

Exporting data to Oracle7

SYS

Creates the dictionary views needed for the Oracle7 Export utility to export data from the Oracle Database in Oracle7 Export file format

caths.sql

Heterogeneous Services

SYS

Installs packages for administering heterogeneous services

catio.sql

Performance management

SYS

Allows I/O to be traced on a table-by-table basis

catoctk.sql

Security

SYS

Creates the Oracle Cryptographic Toolkit package

catqueue.sql

Advanced Queuing


Creates the dictionary objects required for Advanced Queuing

catrep.sql

Oracle Replication

SYS

Runs all SQL scripts for enabling database replication

catrman.sql

Recovery Manager

RMAN or any user with GRANT_RECOVERY_CATALOG_OWNER role

Creates recovery manager tables and views (schema) to establish an external recovery catalog for the backup, restore, and recovery functionality provided by the Recovery Manager (RMAN) utility

dbmsiotc.sql

Storage management

Any user

Analyzes chained rows in index-organized tables

dbmspool.sql

Performance management

SYS or SYSDBA

Enables DBA to lock PL/SQL packages, SQL statements, and triggers into the shared pool

userlock.sql

Concurrency control

SYS or SYSDBA

Provides a facility for user-named locks that can be used in a local or clustered environment to aid in sequencing application actions

utlbstat.sql and utlestat.sql

Performance monitoring

SYS

Respectively start and stop collecting performance tuning statistics

utlchn1.sql

Storage management

Any user

For use with the Oracle Database. Creates tables for storing the output of the ANALYZE command with the CHAINED ROWS option. Can handle both physical and logical rowids.

utlconst.sql

Year 2000 compliance

Any user

Provides functions to validate that CHECK constraints on date columns are year 2000 compliant

utldtree.sql

Metadata management

Any user

Creates tables and views that show dependencies between objects

utlexpt1.sql

Constraints

Any user

For use with the Oracle Database. Creates the default table (EXCEPTIONS) for storing exceptions from enabling constraints. Can handle both physical and logical rowids.

utlip.sql

PL/SQL

SYS

Used primarily for upgrade and downgrade operations. It invalidates all existing PL/SQL modules by altering certain dictionary tables so that subsequent recompilations will occur in the format required by the database. It also reloads the packages STANDARD and DBMS_STANDARD, which are necessary for any PL/SQL compilations.

utlirp.sql

PL/SQL

SYS

Used to change from 32-bit to 64-bit word size or vice versa. This script recompiles existing PL/SQL modules in the format required by the new database. It first alters some data dictionary tables. Then it reloads the packages STANDARD and DBMS_STANDARD, which are necessary for using PL/SQL. Finally, it triggers a recompilation of all PL/SQL modules, such as packages, procedures, and types.

utllockt.sql

Performance monitoring

SYS or SYSDBA

Displays a lock wait-for graph, in tree structure format

utlpwdmg.sql

Security

SYS or SYSDBA

Creates PL/SQL functions for default password complexity verification. Sets the default password profile parameters and enables password management features.

utlrp.sql

PL/SQL

SYS

Recompiles all existing PL/SQL modules that were previously in an INVALID state, such as packages, procedures, and types.

utlsampl.sql

Examples

SYS or any user with DBA role

Creates sample tables, such as emp and dept, and users, such as scott

utlscln.sql

Oracle Replication

Any user

Copies a snapshot schema from another snapshot site

utltkprf.sql

Performance management

SYS

Creates the TKPROFER role to allow the TKPROF profiling utility to be run by non-DBA users

utlvalid.sql

Partitioned tables

Any user

Creates tables required for storing output of ANALYZE TABLE ...VALIDATE STRUCTURE of a partitioned table

utlxplan.sql

Performance management

Any user

Creates the table PLAN_TABLE, which holds output from the EXPLAIN PLAN statement


Table B-4 Upgrade and Downgrade Scripts

Script Name Needed For Description

catdwgrd.sql

Downgrading

Provides a direct downgrade path from the new Oracle Database 10g release

catupgrd.sql

Upgrading

Provides a direct upgrade path to the new Oracle Database 10g release

utlu102i.SQL

Pre-Upgrade Information

Analyzes the database to be upgraded, detailing requirements and issues for the upgrade to release 10.2

utlu102s.SQL

Post-Upgrade Status

Displays the component upgrade status after an upgrade to release 10.2


Table B-5 Java Scripts

Script Name Description

initjvm.sql

Initializes JServer by installing core Java class libraries and Oracle-specific Java classes

rmjvm.sql

Removes all elements of the JServer

catjava.sql

Installs Java-related packages and classes

2009-09-28

ORACLE RMAN CLONE

how to clone database by RMAN:
it depends on recovering files from previous backup

  1. create PFILE for new database based on PFILE from source database
    init[db_new].ora
    main changes:
    • db_name
    • control_files
    • audit_file_dest
    • background_dump_dest
    • user_dump_dest
    • core_dump_dest
  2. create password file for new database:
    orapwd file=orapw[db_new] password=[pass]

  3. add new database to listener.ora and tnsnames.ora,

  4. create dirs for new database file,

  5. create directories for trace logs as admin with subdirectories: adump, udump, cdump, bdump,

  6. startup new auxiliary database in nomout mode(! then exit from your session because it will be hang on)

  7. start rman with ORACLE_SID = auxiliary database:

  8. at the auxiliary server run command:
    rman auxiliary / target sys/[sys_pass]@[targetdb_tnsalias] catalog rman/[rman_pass]@[catalogdb_tnsalias]
    you should get an output:
    connected to target database: [db_name] (DBID=[db_id])
    connected to recovery catalog database
    connected to auxiliary database: [db_name] (not mounted)



  9. run script:
    run {
    set newname for datafile 4 to '/oracle/oradata/[db_new]/users01.dbf';
    set newname for datafile 3 to '/oracle/oradata/[db_new]/sysaux01.dbf';
    set newname for datafile 2 to '/oracle/oradata/[db_new]/undotbs01.dbf';
    set newname for datafile 1 to '/oracle/oradata/[db_new]/system01.dbf';
    set newname for datafile 5 to '/oracle/oradata/[db_new]/example01.dbf';
    set newname for tempfile 1 to '/oracle/oradata/[db_new]/temp.dbf';
    duplicate target database to [db_new]
    pfile=/oracle/product/10.2.0/db_1/dbs/init[db_new]aux.ora
    logfile
    '/oracle/oradata/[db_new]/redo01.log' size 50m,
    '/oracle/oradata/[db_new]/redo02.log' size 50m,
    '/oracle/oradata/[db_new]/redo03.log' size 50m;}

    to generate script above use sql at source db:
    spool clonescript.rcv
    select 'set newname for datafile '||file_id||' to '''||file_name||''';' from dba_data_files order by file_id;
    select 'set newname for tempfile '||file_id||' to '''||file_name||''';' from dba_temp_files order by file_id;
    spool off;
    and next modify output in vim:
    :% s/ora6\/oradata\/DBSRC/u01\/oradata\/DBAUX\/datafile
    or another script:
    run {
    set until time "to_date('2010-07-02:01:00','yyyy-mm-dd:hh24:mi')";
    configure default device type to sbt;
    configure device type sbt parallelism 2;
    configure auxiliary channel 1 device type sbt parms 'ENV=(NB_ORA_SERV=server_name,NB_ORA_CLIENT=server_target_name)';
    configure auxiliary channel 2 device type sbt parms 'ENV=(NB_ORA_SERV=server_name,NB_ORA_CLIENT=server_target_name)';
    duplicate target database to [db_new]
    DB_FILE_NAME_CONVERT=('[target_path1]/','[aux_path]',
    '[target_path2]/','[aux_path]')
    pfile=[pfile_aux_path]/[db_new].ora
    logfile
    '[logfile_aux_path]/redo01.log' size 100m,
    '[logfile_aux_path]/redo02.log' size 100m,
    '[logfile_aux_path]/redo03.log' size 100m;
    }


ERRORS:

if you get an output error: "...segmentation fault..." you have to check the alertlog file, and if you get "...database must be open in upgrade mode...", it means that you have tried clone between diferent versions of databases, so you shoud: alter databse recover; alter database open upgrade; @$ORACLE_HOME/rdbms/admin/catupgrd.sql @$ORACLE_HOME/rdbms/admin/utlrp.sql for more read documentation

2009-09-09

ORACLE JOBS

1 Views

  • SELECT * FROM dba_jobs
  • SELECT * FROM dba_jobs_running
  • column TOTAL_TIME determine the time which system spend run this job from first initialization, it is not time of present
  • column THIS_DATE is filled when job is still executing and show time present execution time

2 Create new job

declare
  jobnr number;
begin
  dbms_job.submit(
    job=>jobnr,
    what=>'dbms_output.put_line(''ble'');',
    next_date=>to_date('10:00 09/09/2009','HH24:MI DD/MM/YYYY'),
    interval=>'SYSDATE+1');
end;
/

3 Starting job by hand

  • must be run by job owner, otherwise ORA-23421, even for user sys, beware on change next_date which will by calculated from now
  • sql> exec DBMS_JOB.RUN(JOB => [nr]);

4 Turn off

  • set state BROKEN
  • sql> exec DBMS_JOB.BROKEN(JOB => [nr], BROKEN => TRUE);

5 Turn on

  • unset state BROKEN
  • sql> exec DBMS_JOB.BROKEN(JOB => [nr], BROKEN => FALSE, NEXT_DATE => TO_DATE(’10:00 01/01/09′, ‘HH24:MI MM/DD/YY’));

6 Changing job params

  • must be set all arguments, if any is unchange we set NULL:
  • sql> exec DBMS_JOB.CHANGE(JOB => [nr], NEXT_DATE => to_date('2011-01-01 10:00','YYYY-MM-DD HH24:MI'), WHAT => null, INTERVAL => ‘SYSDATE + 3′);

7 Removing job:

  • exec DBMS_JOB.REMOVE(JOB => [nr]);

8 dbms_ijob

  • DBMS_IJOB is a package included with Oracle that allows a sys or system user to manipulate other user's jobs.

9 How to set time:

sysdate+1from present time + 1day
trunc(sysdate)+1from 12.00 AM + 1day
trunc(sysdate)+17/2417:00 PM today<br />
trunc(sysdate)+60/14401:00 AM (60min/60min*24=1440)
  • sql> SELECT to_char(trunc(sysdate+1) + 90/1440, 'MM/DD/YYYY HH:MI AM') FROM dual;

10 ERRORs

10.1 ORA-23421

  • procedure dbms_job must by run by owner even sys user cant do that check dbms_ijob

10.2 ORA-12012

  • search above string ORA-12012 in alertlogs due to problem with previous jobs

2009-08-13

LINUX LVM

1 Create LVM partition

1.1 Create LVM partition:

  • fdisk /dev/[disk]
  • change partition type from LINUX to LVM

1.2 Initialize LVM partition:

  • pvcreate /dev/[disk_partiton1] /dev/[disk_partition2]
  • verifycommands:
    • pvs
    • pvdisplay

1.3 Create LVM group:

  • vgcreate [group_name] /dev/[disk_partition1] /dev/[disk_partition2]
  • verify commands:
    • vgs
    • vgdisplay

1.4 Create logical volumes which is attached to group:

  • lvcreate -L[size]M -n [vol_name] [group_name]
  • verify commands:
    • lvs
    • lvdisplay

1.5 Volume format:

  • mkfs.ext3 [lv_name_from_lvdisplay]

2 Snapshot

2.1 Desc

  • Snapshot covers process of writing block to special area before writing to this block, so if you want to make changes to block at first you must copy this block to special area
  • So it is neccesary to set volume snapshot size, and when it will be full the snapshot is broken

2.2 Steps

  1. lvcreate -s -L[size]G -n [lv_snap] /dev/[vg_name]/[lv_2snap]
  2. dd if=/dev/[vg_name]/[lv_snap] of=[file_name].img
    • The size of file is similar to "lvdisplay /dev/[vg_name]/[lv_snap]"
    • If snapshot size is oversized the warning is "input/ouput error"
  3. lvcreate -n [lv_new] -L[size_bigger_then_above] [vg_name]
    • It is possible to expand by resize2fs
  4. dd if=[file_name].img of=/dev/[vg_name]/[lv_new]
  5. lvremove /dev/[vg_name]/[lv_snap]

3 Move data inside group

  1. pvs
  2. pvmove /dev/sd...
  3. pvs

4 Remove disk from group

  • lvreduce [vg_name] /dev/sd...

5 Add disk to group

  1. pvcreate /dev/sd...
  2. pvs
  3. vgextend [vg_name] /dev/sd...

6 Reduce volume size

  1. umount...
  2. e2fsck -f /dev/[vg_name]/[lv_name]
  3. resize2fs /dev/[vg_name]/[lv_name] [nr]G
  4. lvreduce -L[nr]G /dev/[vg_name]/[lv_name]
  5. mount...

7 Extend volume size

  1. lvextend /dev/[vg_name]/[lv_name]
  2. e2fsck -f /dev/[vg_name]/[lv_name]
  3. resize2fs /dev/[vg_name\/[lv_name]

8 Activate group

  • vgscan
  • vgchange -ay

9 Extend partition

  • fdisk
  • d #remove partition
  • n #make a new one with start section at the same point

2009-08-03

ORACLE WAITS

TIME_STATISTICS = true

v$event_name #describe events with parameters P and share to 12 wait_class

v$system_event #based on events which was collected when instance was started for all sessions (please check TIME_WAITED regard to  STARTUP_TIME.v$instance)
  • TOTAL_WAITS #how many times session was waiting on this event
  • TOTAL_TIMEOUTS #how often default time was reached, default time is set for each event
  • TIME_WAITED # time used by event (1/100 sek)
  • TIME_WAITED_MICRO #as above (/1000000 sek)
  • AVERAGE_WAIT #average time TIME_WAITED/TOTAL_WAITS (1/100 sek)
v$session_event #the same as v$system_event but for session, added SID column

v$session_wait #present events which was expected by session
  • SEQ #internal seqence nr for any event, it is increased any time when session wait at event
  • STATE #value WAITING and WAITED UNKNOWN TIME show that TIMES_STATISTICS is FALSE
  • SECONDS_IN_WAIT #time spending by session

from 10g
v$session_wait_history #the same as v$session_wait but there is last 10 wait events for any session but col SEQ# means something diferent
v$active_session_history #last 30 min probes which was collected every 1 sec., more probes than at v$session_wait_history

v$system_wait_class #waits grouped by class category
v$session_wait_class #waits grouped by class and session category

v$event_histogram #share between events which spend less than 1,2,4,8,16 ms

2009-07-24

LINUX MUTT

2 .muttrc

  • http://dev.mutt.org/trac/wiki/ConfigLits
    CONFIGURATIONDESCRIPTION
    set move=nodont ask about moving message to mbox
    set imap_user =imap username
    set imap_pass =imap password
    set folder =main folder like "imaps://[hostname]"
    set ssl_starttls = yes
    set smtp_url =url lik smtp://[hostname]:25/
    set smtp_pass ="$imap_pass"
    set spoolfile ="+INBOX"
    set realname =name
    set from =name
    set record =folder for outgoing messages
    set copy = nocopy outgoing messages to above folder
    set pager_stop = yesdo not move to the next message during reading
    my_hdr From: <mail@domain>set header
    #my_hdr CC: <mail@domain>
    my_hdr Reply-to: <mail@domain>
    my_hdr User-Agent: Mutt
    set header_cache=~/.hcacheset file for source headers
    source /[path]/[filename]split config for many files
    set date_format="%b-%d %H:%M:%S"
    set index_format="%-4C%-5Z%-17d%-30a%s"index format
    auto_view text/html
    bind index "q" noop
    bind index "x" exit
    save-hook '~s [title]' "$folder/[folder]"set filter for saving directory
    alias [alias] email@domainset alias recipients, during sending put TAB
    color header brightyellow default "^date:"header coloers
    color header brightred default "^from:"
    color header white default "^to:"
    color header white default "^cc:"
    color header brightyellow red "^subject:"
    color status white black


3 OS mode

mutt -f imap://[IMAP_server]/inboxlogon to IMAP server

4 Main mode (index)

COMMANDDESCRIPTION
source [config_file]reload config
$run command, save mailbox, refresh
@show sender address
osort
entershow message
dmark to delete
Dmark to delete based on regexp
uunmark delete
Uunmark delete based on regexp
rreply
greply all
msend
=first message
kprevious message
fnext message
jnext message
*last message
nmessage nr [n]
C-gclean command line
cchange directory, ? - directory list
ssave message
vshow attachement
wset flag
Wunset flag
ttag message
Ttag messag based on regexp

4.1 index_format

  • default: %4C %Z %{%b %d} %-15.15L (%4l) %s
  • my: set index_format="%-5Z%-17d%-30a%s"
  • set date_format="%m-%d %H:%M:%S" #zgodne z strftime
    %aaddress of the author
    %bfilename of the original message folder (think mailBox)
    %Bthe list to which the letter was sent, or else the folder name (%b).
    %cnumber of characters (bytes) in the message
    %Ccurrent message number
    %ddate and time of the message in the format specified by ``date_format'' converted to sender's time zone
    %Ddate and time of the message in the format specified by ``date_format'' converted to the local time zone
    %ecurrent message number in thread
    %Enumber of messages in current thread
    %fentire From: line (address + real name)
    %Fauthor name, or recipient name if the message is from you
    %imessage-id of the current message
    %lnumber of lines in the message
    %LIf an address in the To or CC header field matches an address defined by the users ``lists'' command, this displays "To <list-name>", otherwise the same as %F.
    %mtotal number of message in the mailbox
    %Mnumber of hidden messages if the thread is collapsed.
    %Nmessage score
    %nauthor's real name (or address if missing)
    %O(_O_riginal save folder) Where mutt would formerly have stashed the message: list name or recipient name if no list
    %ssubject of the message
    %Sstatus of the message (N/D/d/!/r/*)
    %t`to:' field (recipients)
    %Tthe appropriate character from the $to_chars string
    %uuser (login) name of the author
    %vfirst name of the author, or the recipient if the message is from you
    %y`x-label:' field, if present
    %Y`x-label' field, if present, and (1) not at part of a thread tree, (2) at the top of a thread, or (3) `x-label' is different from preceding message's `x-label'.
    %Zmessage status flags

5 Message mode(pager)

iexit
[SPC]next page
-prev page
vattach

6 Flags

FLAGDESCRIPTION
Dmark to delete
Nnew, not read
Oold, but not read
*marked
PPGP included
rreplied to
+message only for you
Tmessage for you with CC field
Cyou are at CC field
Fmessage from you
Lmassage from subscribe list

7 Tagging

Ttag message based on regexp
;(semi-colon)apply operation form tagged messages
Wchange flag

8 Keybinding

  • edit muttrc ex.
    bind index "q" noop #means not bind "q" key with index mode

9 Patterns for messages

~Aall messages
~b EXPRmessages which contain EXPR in the message body
~B EXPRmessages which contain EXPR in the whole message
~c USERmessages carbon-copied to USER
~C EXPRmessage is either to: or cc: EXPR
~Ddeleted messages
~d [MIN]-[MAX]messages with ``date-sent'' in a Date range
~Eexpired messages
~e EXPRmessage which contains EXPR in the ``Sender'' field
~Fflagged messages
~f USERmessages originating from USER
~gPGP signed messages
~GPGP encrypted messages
~h EXPRmessages which contain EXPR in the message header
~kmessage contains PGP key material
~i IDmessage which match ID in the ``Message-ID'' field
~L EXPRmessage is either originated or received by EXPR
~lmessage is addressed to a known mailing list
~m [MIN]-[MAX]message in the range MIN to MAX *)
~n [MIN]-[MAX]messages with a score in the range MIN to MAX *)
~Nnew messages
~Oold messages
~pmessage is addressed to you (consults $alternates)
~Pmessage is from you (consults $alternates)
~Qmessages which have been replied to
~Rread messages
~r [MIN]-[MAX]messages with ``date-received'' in a Date range
~Ssuperseded messages
~s SUBJECTmessages having SUBJECT in the ``Subject'' field.
~Ttagged messages
~t USERmessages addressed to USER
~Uunread messages
~vmessage is part of a collapsed thread.
~x EXPRmessages which contain EXPR in the `References' field
~y EXPRmessages which contain EXPR in the `X-Label' field
~z [MIN]-[MAX]messages with a size in the range MIN to MAX *)
~=duplicated messages (see $duplicate_threads)

10 Keybinding patterns

\ttab
<tab>tab
\rcarriage return
\nnewline
\eescape
<esc>escape
<up>up arrow
<down>down arrow
<left>left arrow
<right>right arrow
<pageup>Page Up
<pagedown>Page Down
<backspace>Backspace
<delete>Delete
<insert>Insert
<enter>Enter
<return>Return
<home>Home
<end>End
<space>Space bar
<f1>function key 1
<f10>function key 10

2009-07-15

ORACLE VIEWS

view
description
dba_db_links
links
v$dba_registry
installed components
v$transportable_platform
big-endian,little-endian bytes orientation
nls_database_parameters
encoding
v$pwfile_users
users from password file

2009-06-03

LINUX VSFTPD

before run check module path in file /etc/pam.d/vsftpd
vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES

#xferlog_enable=YES #wlaczenie logowania
xferlog_std_format=NO
#xferlog_file=/var/log/vsftpd.log
vsftpd_log_file=/var/log/vsftpd.log
#log_ftp_protocol=YES

connect_from_port_20=YES

#idle_session_timeout=600
#data_connection_timeout=120
#nopriv_user=ftpsecure

ftpd_banner=Welcome to ftp server

chroot_local_user=YES
secure_chroot_dir=/usr/share/empty

# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/vsftpd.chroot_list

# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd.ftpusers
# for users that are denied.

pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd/vsftpd.user_list

#enable for standalone mode
listen=YES
tcp_wrappers=YES

MIDNIGHT COMMANDER

Shortkeys:

"key1" & "key2" - means - put key1 and after that put key2
"key1" + "key2" - means - put key1 and hold on put key2

"esc" & "o" #the same directory on neighbor window
"ctrl" + "x" & "q" #show file content
"ctrl" + "x" & "s" #make symbolic link
"ctrl" + "x" & "c" #chmod
"ctrl" + "x" & "o" #chown

Connections:

/#sh:[username]:[pass]@[server]:[path]
/#ftp:[username]:[pass]@[server]


~/.mc/ini

navigate_with_arrows=1 #change dirs with arrows
use_internal_edit=1 #internal editor mcedit when set 0 it dependes from environment variable $EDITOR

ETHERNET FRAME

IP CLASS

/25(128) /26(192) /27(224) /28(240) /29(248) /30(252)
-----------------------------------------------------
0-127    0-63     0-31     0-15     0-7      0-3
4-7
8-15     8-11
12-15
16-31    16-23    16-19
20-23
24-31    24-27
28-31
32-63    32-47    32-39    32-35
36-39
40-47    40-43
44-47
48-63    48-55    48-51
52-55
56-63    56-59
60-63
64-127   64-95    64-79    64-71    64-67
68-71
72-79    72-75
76-79
80-95    80-87    80-83
84-87
88-95    88-91
92-95
96-127   96-111   96-103   96-99
100-103
104-111  104-107
108-111
112-127  112-119  112-115
116-119
120-127  120-123
124-127
128-255  128-191  128-159  128-143  128-135  128-131
132-135
137-143  136-139
140-143 
144-159  144-151  144-147
149-151
153-159  153-155
157-159 
160-191  160-175  160-167  160-163
164-167
168-175  168-171
172-175
176-191  176-183  176-179
180-183
180-191  184-187
188-191
192-255  192-223  192-207  192-199  192-195
196-199
200-207  200-203
204-207
208-223  208-215  208-211
212-215
216-223  216-219
220-223
224-255  224-239  224-231  224-227
228-231
232-239  232-235
236-239
240-255  240-247  241-243
244-247
248-255  248-251
252-255

2009-05-05

LINUX RAID

1. Disk partioning:
fdisk /dev/sda
n - create new partition
t - create partition with type RAID (fd - Linux raid autodetect)

2. Create array:
mdadm --create /dev/md[nr] --level=[0|1|etc] --raid-devices=2 /dev/sda1 /dev/sdb1
3. Format array:
mkfs.ext3 /dev/md[nr]
4. Create directory
5. Mount array
6. Add to /etc/fstab
echo "/dev/md[nr] /[katalog] defaults 0 2" >>etc/fstab
7. Create file /etc/mdadm.conf
echo "DEVICE /dev/sda1 /dev/sdb1" > /etc/mdadm.conf
mdadm --detail --scan >> /etc/mdadm.conf

General:
mdadm --add /dev/md[nr] /dev/sda2 #add disk to synchronize with array
mdadm -E /dev/sda1 #info about device inside array
cat /proc/mdstat #present state of array
mdadm --stop /dev/md[nr] #stop array, free devices
mdadm --assemble #mount arrary
mdadm --detail --scan #info about components from /proc/mdstat

2009-05-03

ORACLE STARTUP

Startup mode:

STARTUP NOMOUNT

  • startup instance and occupy memory
  • read pfile in order:
    • spfile$ORACLE_SID.ora or
    • spfile.ora or
    • init$ORACLE_SID.ora
    • init.ora

STARTUP MOUNT

  • mount database to instance,
  • read controlfile,
  • allocating database structure

STARTUP OPEN

  • open database for all users

STARTUP READ ONLY

  • open database for all users but read only

STARTUP FORCE

  • restart database as SHUTDOWN ABORT and startup again

STARTUP RESTRICT

  • open database for users with privilege RESTRICTED SESSION, if you want to open for all put ALTER SYSTEM DISABLE RESTRICTED SESSION

STARTUP UPGRADE

  • open database for AS SYSDBA, prepare database to upgrade

Shutdown mode:

SHUTDOWN

  • disallow new connections and wait for finish session for present users

SHUTDOWN TRANSACTIONAL

  • disallow new connections, disallow new transactions, when transactions was finished, all users are disconnected

SHUTDOWN IMMEDIATE

  • disallow new connections, all transactions which was not commit are rollback and users are disconnected

SHUTDOWN ABORT

  • disallow new connections, all transactions are interupted, not rollback, users are disconnected, during next startup database allow recovery

2009-04-30

ORACLE PATCH

download opatch

  1. download patch
  2. unpack
  3. shutdown instance
  4. read README file
  5. change directory to unpacked archive
  6. opatch apply
  7. run Post Installation Instructions

check patches allready install:
opatch lsinventory
opatch lsinventory -detail
check patch:
opatch query -all /[path_to_patch_directory]
check opatch options
opatch -help [option]
logs:
[ORACLE_HOME]/cfgtoollogs/opatch
[ORACLE_HOME]/cfgtoollogs/opatch/opatch_history.txt
rollback:
opach rollback -id [nr_patcha]
check invalid objects:
SELECT object_name FROM dba_objects WHERE status = 'INVALID';
compile all invalid objects:
[ORACLE_HOME]/rdbms/admin/utlrp.sql
which launch script [ORACLE_HOME]/rdbms/admin/utlprp.sql z parametrem=0
- parametr=0 - run parallel with CPU_COUNT
- parametr=1 - run in one process
- parametr=N - number of parallel run

2009-04-17

LINUX CDRECORD

burn DVD:
1. create ISO file
mkisofs -r -o plik.iso /[directory_to_burn/
- DVD+RW
2. disk format (only once in case of new disk):
cdrecord -v dev=/dev/hdc -format
3. burn:
cdrecord -v dev=/dev/hdc speed=4 -dao -data file.iso
4. next record do not need erase disk
- DVD-RW
2. format is not necessary
3. burn:
cdrecord -v dev=/dev/hdc speed=4 -dao -data file.iso
4. next record need erase disk:
cdrecord -v dev=/dev/hdc blank=fast
options:
-dao - write Disk At Once
-tao - write Track At Once (for multisesion, default)
share (files up to 2GB for ISO format):
tar -cf - /[dir_to_tar] |split -b 2000m - FILE.tar

2009-04-03

LINUX SCREEN

1 OS commands

screen -lssession list
screen -r [session]attach to active session
screen -xattach multiply users to active session
screen -dmS [session] [app]run app without start screen

2 Screen Commands

COMMANDDESCRIPTION
C-a ddeatach
C-a "window list
C-a wwindow list
C-a :number [0-9]change window nr
C-a Achange window name
C-a shift+nshow window nr
C-a cnew window
C-a kkill window
C-a [0-9]go to window nr
C-a [SPC]next window
C-a [BPC]previous window
C-a C-alast active window
C-a [ESC]turn on mode scrollback/copy
[SPC]start/stop buffer copy
C-a ]paste from buffer
C-a ?help
C-a :command line

3 .screenrc

startup_message off
deflogin off
defnonblock 5
termcapinfo xterm*|rxvt* 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
termcapinfo xterm*|rxvt* ti@:te@
#defbce "on"
vbell off
altscreen on
bindkey -k F1 prev
bindkey -k F2 next
bind ^v screen -t ROOT su -
hardstatus alwayslastline
hardstatus string '%{= KM}[ %{G}%H %{M}][%= %{c}%?%-Lw%?%{C}(%{C}%n*%f%t%{C})%{c}%?%+Lw%?%? %=%{M}][%{G} %c %{M}]'
defscrollback 1024
screen 0

2009-03-27

LINUX MAILX

1 Command line

mailread
mail -fread from mbox file
mail -s "[title]"send mail with title option

2 Help:

  • ? | l[ist] | hel[p] #list commands

3 Mesages list

n[nr]Show message number nr.
+The next undeleted message, or the next deleted message for the undelete command.
-The next previous undeleted message, or the next previous deleted message for the undelete command.
.The current message.
$The last message.

4 Move:

z+screen forward
z-screen backward
=show number of current message
+next message
$last message

5 Main

h[eaders]show headers of all
f[rom] *list all mails with headers
folderdirectory list
to [msglist]list top of message
q[uit]save and exit
rreply to all
xexit without save
e[dit] [msglist]edit
si[ze]size current message
p[rint]print current message
p 3print 3-rd message
folist directories
setshow variables
set name=stringdefine variable
uns[et]unset

6 Manipulation:

d[elete] [msglist]delete current message
u[ndelete] [msglist]undelete message
Uset message as unread
s[ave] [msglist]save

7 All messages.

n-mrange of message numbers.
addressAll messages from address
/stringAll messages with string in the subject line (case ignored).
:cAll messages of type c, where c shall be one of:
dDeleted messages.
nNew messages.
oOld messages (any not in state read or new).
rRead messages.
uUnread messages.

2009-03-17

ORACLE FLASHBACK

1 Prerequisites

  • database ARCHIVELOG mode
  • UNDO_MANAGEMENT=auto

2 Configuration steps

  1. setting param DB_RECOVERY_FILE_DEST which point to flashback logs location
  2. setting param DB_RECOVERY_FILE_DEST_SIZE which specify summary size of all logs
  3. setting param DB_FLASHBACK_RETENTION_TARGET which specify logs store time in miutes
  4. startup database in mount mode
  5. turn on flashback
    • sql> ALTER DATABASE FLASHBACK ON;
  6. check:
    • sql> SELECT log_mode,flashback_on FROM v$database;
  7. open database

3 Estimating log store space

  1. setting DB_FLASHBACK_RETENTION_TARGET
  2. sql> SELECT estimated_flashback_size FROM v$flashback_database_log;

4 Recover from flashback logs

  1. startup database in mount mode
  2. sql> FLASHBACK DATABASE TO…
    • TIMESTAMP SYSDATE-1]
    • TO TIMESTAMP to_timestamp('2009-09-28 11:00','yyyy-mm-dd hh24:mi')
    • TO SCN [scn#];
  3. sql> ALTER DATABASE OPEN READ ONLY;
    • at READ-ONLY mode it is possible to verify data
    • if data are not correct, so repeat steps from 1 to 3
  4. turn off database
  5. startup database in mount mode
  6. sql> ALTER DATABASE OPEN RESETLOGS;

5 Views

  • sql> SELECT oldest_flashback_scn,oldest_flashback_time,flashback_size FROM v$flashback_database_log;
    oldest_flashback_scn, oldest_flashback_timeoldest timestamp when data can be recovered
    (To verify this operation, try delete oldest flashback log then put above SELECT command and oldest point was changed)
    estimated_flashback_sizethe neccessary space to ensure DB_FLASHBACK_RETENTION_TARGET
    flashback_size
  • sql> SELECT * FROM v$flash_recovery_area_usage;
  • sql> SELECT * FROM v$recovery_file_dest;
  • sql> SELECT SCN_TO_TIMESTAMP(10213123) FROM DUAL;

6 Recyclebin

6.1 Show recyclebin

  • sql> SHOW RECYCLEBIN

6.2 Recover table from recyclebin

  • sql> DROP TABLE [table_name]
  • sql> FLASHBACK TABLE [table_name] TO BEFORE DROP;

6.3 Droping table without recyclebin

  • sql> DROP TABLE [table_name] PURGE;

6.4 Purging recyclebin

  • sql> PURGE TABLE [table_name];
  • sql> PURGE TABLESPACE [ts_name];
  • sql> PURGE TABLESPACE [ts_name] USER [user];
  • sql> PURGE RECYCLEBIN
  • sql> PURGE DBA_RECYCLEBIN;

7 ERRORs

[ symptom ]

  • ORA-38729: Not enough flashback database log data to do FLASHBACK

[ solution ]

  • timestamp older then oldest_flashback_time

2009-03-16

LINUX CRYPTSETUP

create:
cryptsetup --verbose --verify-passphrase luksFormat /dev/sda1
open:
cryptsetup luksOpen /dev/sda1 usb
format:
mkfs.ext2 /dev/mapper/usb
mount:
mount /dev/mapper/usb /usb
umount:
umount /usb
close:
crypsetup luksClose usb

on disk

cryptsetup luksFormat [partition]
cryptsetup luksOpen [partition] [name]
mkfs.ext4 /dev/mapper/[name]
mount /dev/mapper/[name]
cryptsetup luksClose [name]
start during boot:
cryptsetup luksDump /dev/mapper/vg_euplnb1001-lv_01 |grep UUID >> /etc/crypttab
/etc/crypttab
[name] /dev/disk/by-uuid/220ec734-ccbd-497a-8632-eae4f28608ae none luks
/etc/fstab
/dev/mapper/[name] /mnt/[mount_point] ext4 defaults 0 0