ALTER SESSION | ALTER SYSTEM | |
---|---|---|
affects | parameters related to the current connection to the DB | any instance parameter |
changes are visible | until you disconnect from the database | as long as the database is mounted |
major options | SCOPE=value, with value :
|
oracle 8573 1 0 2019 ? 00:27:44 ora_pmon_instance1 oracle 23661 1 0 2019 ? 00:26:23 ora_pmon_instance2
oracle 8609 1 0 2019 ? 00:12:59 ora_smon_instance1 oracle 23697 1 0 2019 ? 00:15:04 ora_smon_instance2
export ORACLE_SID=ORACLE_SID; sqlplus -s '/ as sysdba' << EOSQL
SET LINESIZE 200
COLUMN username FORMAT A10
COLUMN IP_ADDRESS FORMAT A15
SELECT
username,
utl_inaddr.get_host_address(terminal) IP_ADDRESS,
sid,
serial#,
program
FROM
v\$session
WHERE
username is not null
ORDER BY
username;
EOSQL
USERNAME IP_ADDRESS SID SERIAL# PROGRAM --------------- --------------- ------- --------------- -------------------------------------------- SYS 10.203.2.28 708 27 sqlplus@hostname (TNS V1-V3)
This query also returns the SQL*Plus session in which it's being executed.
In this context, sid stands for session identifier, and must not be mistaken with the system identifier (aka ORACLE_SID).
export ORACLE_SID=ORACLE_SID; sqlplus -s '/ as sysdba' << EOSQL alter system kill session 'sid, serial#'; EOSQL
truncate table tableName
delete from tableName where [SQL condition]
SET pagesize 50 select distinct owner from dba_objects order by owner;
export ORACLE_SID=oracleSid; sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Oct 16 11:21:37 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SQL>
sqlplus /nolog SQL*Plus: Release 11.2.0.3.0 Production on Fri Oct 16 11:03:33 2015 Copyright (c) 1982, 2011, Oracle. All rights reserved. SQL> connect sys@tnsName Enter password: wrong password ERROR: ORA-01017: invalid username/password; logon denied SQL> connect sys@tnsName Enter password: right password ERROR: ORA-28009: connection as SYS should be as SYSDBA or SYSOPER SQL> connect sys@tnsName as SYSDBA Enter password: wrong password ERROR: ORA-01017: invalid username/password; logon denied SQL> connect sys@tnsName as SYSDBA Enter password: right password Connected. SQL>
This command line assumes there is a /home/oracle/network/admin/tnsnames.ora entry matching the ORACLE_SID.
dbName='MYDB'; sysPassword='password'; echo -n "'sys' connection on '$dbName' : "; echo 'select * from dual;
' | sqlplus sys@$dbName/$sysPassword as sysdba &>/dev/null && echo 'ok' || echo 'ko'
looks like the ...where owner = 'bob'
, ...where grantee = 'bob'
clauses are case-sensitive.
List user privileges : SELECT * FROM USER_SYS_PRIVS; SELECT * FROM USER_TAB_PRIVS WHERE GRANTEE='RECAPE_fct'; SELECT TABLE_NAME, GRANTOR, PRIVILEGE FROM USER_TAB_PRIVS WHERE GRANTEE='RECAPE_fct'; SELECT * FROM USER_ROLE_PRIVS; http://stackoverflow.com/questions/15066408/how-to-find-the-privileges-and-roles-granted-to-a-user-in-oracle select * from USER_ROLE_PRIVS where USERNAME='RECAPE_fct'; select * from USER_TAB_PRIVS where Grantee = 'RECAPE_fct'; select * from USER_SYS_PRIVS where USERNAME = 'RECAPE_fct'; describe DBA_SYS_PRIVS select * from DBA_SYS_PRIVS where GRANTEE = 'RECAPE_fct'; column GRANTEE format a30 column PRIVILEGE format a40 select * from DBA_SYS_PRIVS where GRANTEE = 'RECAPE_FCT'; set pagesize 50; column OBJECT_TYPE format a30 column TABLE_NAME format a30 select DISTINCT DBA_OBJECTS.OBJECT_TYPE, auc.TABLE_NAME, auc.UPDATABLE, auc.INSERTABLE, auc.DELETABLE from all_updatable_columns auc join DBA_OBJECTS on auc.TABLE_NAME=DBA_OBJECTS.OBJECT_NAME where auc.OWNER='RECAPE'; select distinct grantee, table_name from TABLE_PRIVILEGES where grantee='RECAPE'; select distinct grantee, table_name from TABLE_PRIVILEGES where grantee='RECAPE_fct'; no rows selected :-((( col "GRANTEE" format a10 col "OWNER" format a10 col "TABLE_NAME" format a30 col "GRANTOR" format a10 SELECT * FROM table_privileges WHERE grantee = 'RECAPE_FCT';
http://www.oracle-dba-online.com/sql/grant_and_revoke_privileges.htm http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9020.htm echo "revoke select, insert, update, delete on RECAPE from RECAPE_fct" | sqlplus / as sysdba
STATUS ------------------------------------ OPEN
STATUS ------------------------------------ OPEN
echo "${ORACLE_SID}:${ORACLE_HOME}:Y" >> /etc/oratab
All the commands described below must be run as oracle.
This file is $ORACLE_BASE/admin/SID/pfile/initSID.ora, SID being the instance name.
/u01/app/oracle /u01/app/oracle/product/12.1.0/dbhome_1/
db_name = MYDB db_block_size = 8192 control_files = /u01/app/oracle/oradata/MYDB/control01.ctl sga_target = 320M pga_aggregate_target = 80M
]\[ZORACLE Remote Password fileYS99A5C02080C9A1EB8▒▒se▒hE▒▒I@▒y{B ▒̑▒sC>▒(dt▒[▒▒▒?▒˨▒▒'z▒4Hg▒sK▒BƬ▒'▒▒1▒Bp|&ܟ▒@▒▒1▒Hw㑳^B5▒N`▒▒5▒u\( )m▒▒▒▒
create database MYDB character set AL32UTF8 national character set AL16UTF16 logfile group 1 '/u01/app/oracle/oradata/MYDB/redo01a.log' size 50M, group 2 '/u01/app/oracle/oradata/MYDB/redo02a.log' size 50M datafile '/u01/app/oracle/oradata/MYDB/system01.dbf' size 500M extent management local sysaux datafile '/u01/app/oracle/oradata/MYDB/sysaux01.dbf' size 500M undo tablespace UNDO_TBS datafile '/u01/app/oracle/oradata/MYDB/undo_tbs01.dbf' size 100M default temporary tablespace TEMP tempfile '/u01/app/oracle/oradata/MYDB/temp01.dbf' size 50M;
Connected to an idle instance.
ORACLE instance started. Total System Global Area 335544320 bytes Fixed Size 2924160 bytes Variable Size 117440896 bytes Database Buffers 209715200 bytes Redo Buffers 5464064 bytes
File created.
ORACLE instance shut down.
ORACLE instance started. Total System Global Area 335544320 bytes Fixed Size 2924160 bytes Variable Size 117440896 bytes Database Buffers 209715200 bytes Redo Buffers 5464064 bytesThe Oracle instance starts and reads the spfile, ignoring the pfile.
Database created.
User altered.
User altered.
MYDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = oracle1)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = MYDB) ) )
MYDB is a free text label referring to a DB (?), even though there is no such DB yet.
TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 25-JUN-2015 17:05:28 Copyright (c) 1997, 2014, Oracle. All rights reserved. Used parameter files: /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.ora Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = oracle1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = MYDB))) OK (50 msec)
Oracle Net Services Configuration: Configuring Listener:LISTENER_ORACLESID Listener configuration complete. Oracle Net Listener Startup: Running Listener Control: /home/oracle/app/oracle/product/12.1.0/dbhome_1/bin/lsnrctl start LISTENER_ORACLESID Listener Control complete. Listener started successfully. Oracle Net Services configuration successful. The exit code is 0
# listener.ora Network Configuration File: /home/oracle/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER_ORACLESID =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
line to improve security.LISTENER_ORACLESID = (DESCRIPTION_LIST = (DESCRIPTION (ADDRESS=(PROTOCOL = TCP)(HOST = hostname)(PORT = 1521)) ) )should be enough.
SID_LIST_LISTENER_ORACLESID = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = ORACLESID) (ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1/) (SID_NAME = ORACLESID) ) )
Item | Minimum | Recommended | My choice |
---|---|---|---|
CPU | Pentium 500MHz or faster | any modern CPU will do the trick | |
RAM | 1GB | 4GB | 1GB |
HDD | 500MB | 10GB | 15GB |
SWAP | See calculation rules | 2GB |
echo "sem: "; echo "min 250 32000 100 128"; echo "is " $(cat /proc/sys/kernel/sem); echo; \ echo "shmall: "; echo "min 2097152"; echo "is " $(cat /proc/sys/kernel/shmall); echo; \ echo "shmmax - should be able to hold the SGA - max 4G-1byte: "; echo "is " $(cat /proc/sys/kernel/shmmax); echo; \ echo "shmmni: "; echo "min 4096"; echo "is " $(cat /proc/sys/kernel/shmmni); echo; \ echo "file-max: "; echo "min 6815744"; echo "is " $(cat /proc/sys/fs/file-max); echo; \ echo "ip_local_port_range: "; echo "min/max 9000 65500"; echo "is " $(cat /proc/sys/net/ipv4/ip_local_port_range); echo; \ echo "rmem_default: "; echo "min 262144"; echo "is " $(cat /proc/sys/net/core/rmem_default); echo; \ echo "rmem_max: "; echo "min 4194304"; echo "is " $(cat /proc/sys/net/core/rmem_max); echo; \ echo "wmem_default: "; echo "min 262144"; echo "is " $(cat /proc/sys/net/core/wmem_default); echo; \ echo "wmem_max: "; echo "min 1048576"; echo "is " $(cat /proc/sys/net/core/wmem_max); echo; \ echo "aio-max-nr: "; echo "max 1048576"; echo "is " $(cat /proc/sys/fs/aio-max-nr); echo
echo "kernel.sem = 250 32000 100 128" >> /etc/sysctl.conf echo "kernel.shmall = 2097152" >> /etc/sysctl.conf (2097152 means 2GB) Needs to fit your SGA (=main memory for database, be sure to have enough ram for PGA etc.)!!!! echo "kernel.shmmax = 1200000000" >> /etc/sysctl.conf # echo "kernel.shmmni = 4096" >> /etc/sysctl.conf echo "fs.file-max = 6815744" >> /etc/sysctl.conf # echo "net.ipv4.ip_local_port_range = 1024 65000" >> /etc/sysctl.conf echo "net.core.rmem_default = 262144" >> /etc/sysctl.conf echo "net.core.rmem_default = 262144" >> /etc/sysctl.conf echo "net.core.rmem_max = 4194304" >> /etc/sysctl.conf echo "net.core.wmem_default = 262144" >> /etc/sysctl.conf echo "net.core.wmem_max = 1048576" >> /etc/sysctl.conf echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
echo "oracle soft nproc 2047" >> /etc/security/limits.conf echo "oracle hard nproc 16384" >> /etc/security/limits.conf echo "oracle soft nofile 1024" >> /etc/security/limits.conf echo "oracle hard nofile 65536" >> /etc/security/limits.conf
X11Forwarding yes
oracle1/unix:11 MIT-MAGIC-COOKIE-1 3ed6a232f4c564301b53b25e58faa6d9 oracle1/unix:10 MIT-MAGIC-COOKIE-1 e2413d3e20f44284ae33e60f5415fea0
touch /home/oracle/.Xauthority xauth add oracle1/unix:10 MIT-MAGIC-COOKIE-1 e2413d3e20f44284ae33e60f5415fea0
Don't forget this step when making a silent install.
Changing permissions of /home/oracle/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /home/oracle/app/oraInventory to oinstall.
The execution of the script is complete.
Performing root user operation.
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /home/oracle/app/oracle/product/12.1.0/dbhome_1
Enter the full pathname of the local bin directory: [/usr/local/bin]: /usr/bin
Copying dbhome to /usr/bin ...
Copying oraenv to /usr/bin ...
Copying coraenv to /usr/bin ...
Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1/ export ORACLE_OWNER=oracle export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export PATH=$PATH:$ORACLE_HOME/binAnd reload changes (as oracle) : source ~/.bash_profile
SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 25 12:16:25 2015 Copyright (c) 1982, 2014, Oracle. All rights reserved. SQL>
column OWNER format a15; column OBJECT_NAME format a25; SELECT DISTINCT OWNER, OBJECT_NAME FROM DBA_OBJECTS WHERE OBJECT_TYPE = 'TABLE' AND OWNER = 'mySchema';Or equivalent :
set pagesize 50;
column OWNER format a15;
column TABLE_NAME format a25;
SELECT DISTINCT
OWNER,
TABLE_NAME
FROM
DBA_TABLES
WHERE
OWNER = 'mySchema'
ORDER
BY TABLE_NAME;
column OBJECT_TYPE format a25;
column OBJECT_NAME format a25;
column OWNER format a15;
SELECT DISTINCT
OBJECT_TYPE,
OBJECT_NAME,
OWNER
FROM
DBA_OBJECTS
WHERE
(OBJECT_TYPE = 'TABLE' OR OBJECT_TYPE = 'VIEW')
AND OWNER = 'mySchema';
If the listener is started before the database, the database will register automatically onto the listener.
All actions below are run as oracle.
Action | DB type | Step-by-step | All-in-one |
---|---|---|---|
start | primary |
|
export ORACLE_SID=ORACLE_SID; echo startup | sqlplus -s / as sysdba |
start | standby |
If both the primary and standby databases are offline, then always (if possible) start the standby database before starting the primary database.
|
export ORACLE_SID=ORACLE_SID; echo -e "startup nomount;\nalter database mount standby database;\nalter database recover managed standby database disconnect from session;" | sqlplus -s / as sysdba |
stop | primary + standby |
|
export ORACLE_SID=ORACLE_SID; echo 'shutdown immediate' | sqlplus -s / as sysdba
Database closed. Database dismounted. ORACLE instance shut down. |
SET linesize 300 COL "USERNAME" FORMAT A15 COL "ACCOUNT_STATUS" FORMAT A20 COL "CREATED" FORMAT A10 SELECT username, account_status, created, lock_date, expiry_date, profile FROM dba_users;
where
clause :
WHERE account_status != 'OPEN';
If a user you've just manually unlocked is still LOCKED, this may be because of too many attempts with a wrong password (thank you, WebLogic!)
dbca -silent -deleteDatabase -sourceDB myDatabase
dbca is a GUI tool, the silent flag enables the CLI usage.
In the example paths above, we use ORACLE_DBNAME = ORACLE_SID
control files : /appli/oracle/$ORACLE_SID/oractl01/$ORACLE_SID_ctrl01.ctl log archive : /appli/oracle/$ORACLE_SID/oraarch initParamFileName : /home/oracle/admin/$ORACLE_SID/dbs/init$ORACLE_SID.ora spfile : /home/oracle/admin/$ORACLE_SID/dbs/spfile$ORACLE_SID.ora
Use this method when the instance you're trying to remove is FUBAR (probably already broken via massive and irresponsible use of rm by a n00b who shouldn't have been given access to this server...).
UID PID PPID C STIME TTY TIME CMD
oracle 25835 1 0 Oct22 ? 00:00:04 /logiciels/oracle/oradb/11.2.0/ora/bin/tnslsnr listenerName -inherit
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp6 0 0 [::]:1521 [::]:* LISTEN oracle 14991 1749/tnslsnr
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 25-JUN-2015 15:18:11 Copyright (c) 1991, 2014, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production Start Date 25-JUN-2015 15:00:55 Uptime 0 days 0 hr. 17 min. 18 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /home/oracle/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora Listener Log File /home/oracle/app/oracle/diag/tnslsnr/oracle1/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle1)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) The listener supports no services The command completed successfully
$ORACLE_HOME/bin/lsnrctl stop listenerName
Be careful with $ORACLE_HOME when switching Oracle versions.
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 12-NOV-2014 16:33:55 Copyright (c) 1991, 2011, Oracle. All rights reserved. Starting /logiciels/oracle/oradb/11.2.0.a/ora/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 11.2.0.3.0 - Production System parameter file is /home/oracle/network/admin/listener.ora Log messages written to /logiciels/oracle/diag/tnslsnr/hostname/listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname.example.com)(PORT=1521))) Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) STATUS of the LISTENER ------------------------ Alias listenerName Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production Start Date 12-NOV-2014 16:33:55 Uptime 0 days 0 hr. 0 min. 0 sec Trace Level off Security ON: Local OS Authentication SNMP ON Listener Parameter File /home/oracle/network/admin/listener.ora Listener Log File /logiciels/oracle/diag/tnslsnr/hostname/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname.example.com)(PORT=1521))) The listener supports no services The command completed successfully
NAME TYPE VALUE
------------------------------- ------- -------
log_archive_dest_state_2 2 defer