1.监听启动监听lsnrctl start停止监听 lsnrctl stop 查看监听状态 lsnrctl status 2.启动用oracle用户进入su - oracle运行sqlplus命令,进入sqlplus环境,nolog参数表示不登录;sqlplus /nolog以管理员模式进入conn /as sysdba启动数据库startup;停止数据库SHUTDOWN IMMEDIATE远程连接数据库sqlplus /nologconn sys/sys@IP:1521/orainstance as sysdba
也可以直接运行:dbstart //启动数据库脚本 dbshut //停止数据库脚本
参考:STARTUP [FORCE][RESTRICT][NOMOUNT][MIGRATE][QUIET][PFILE=][MOUNT [EXCLUSIVE] x |OPEN ]
SHUTDOWN
3.用户管理创建用户create user "username" identified by "userpassword" ;注:后面可带表空间删除用户drop user “username” cascade;注:cascade 参数是级联删除该用户所有对象,经常遇到如用户有对象而未加此参数则用户删不了的问题,所以习惯性的加此参数 授权grant connect,resource,dba to "username" ;查看当前用户的角色select * from user_role_privs;select * from session_privs; 查看当前用户的系统权限和表级权限select * from user_sys_privs;select * from user_tab_privs;查询用户表select username from dba_users; 修改用户口令alter user "username" identified by "password"; 显示当前用户show user;
4.表及表空间创建表空间CREATE TABLESPACE data01 DATAFILE '/oracle/oradata/db/DATA01.dbf' SIZE 500M;删除表空间DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;修改表空间大小alter database datafile '/path/NADDate05.dbf' resize 100M;增加表空间 ALTER TABLESPACE NEWCCS ADD DATAFILE '/u03/oradata/newccs/newccs04.dbf' SIZE 4896M; 查询数据库文件select * from dba_data_files; 查询当前存在的表空间select * from v$tablespace;表空间情况select tablespace_name,sum(bytes)/1024/1024 from dba_data_files group by tablespace_name;查询表空间剩余空间select tablespace_name,sum(bytes)/1024/1024 from dba_free_space group by tablespace_name;查看表结构desc table;
修改连接数:要重启数据库alter system set processes=1000 scope=spfile;shutdown immediate;startup;查看用户当前连接数select count(*) from sys.v_$session;
PL/SQL
[DECLARE/*申明部分,一般是变量及常量*/][ BEGIN/*执行部分,流程结构控制,SQL部分*/][EXCEPTION/*异常处理部分*/]END
SET SERVEROUTPUT ON //打开输出开关BEGINDBMS_OUTPUT.PUT_LINE('Hello world!'); //输出结果END;
5 EM
使用OTK工具安装的Oracle默认没有配置EM,下面记录下配置和启动过程!
首先创建EM,执行下面的命令
$ emca -config dbcontrol db -repos recreate
我第一次运行报如下错误:
Mar 31, 2012 4:16:06 PM oracle.sysman.emcp.EMReposConfig createRepository
CONFIG: ORA-00604: error occurred at recursive SQL level 1
ORA-01653: unable to extend table SYS.SOURCE$ by 128 in tablespace SYSTEM
oracle.sysman.assistants.util.sqlEngine.SQLFatalErrorException: ORA-00604: error occurred at recursive SQL level 1 www.2cto.com
ORA-01653: unable to extend table SYS.SOURCE$ by 128 in tablespace SYSTEM
at oracle.sysman.assistants.util.sqlEngine.SQLEngine.executeImpl(SQLEngine.java:1650)
at oracle.sysman.assistants.util.sqlEngine.SQLEngine.executeScript(SQLEngine.java:1000)
at oracle.sysman.assistants.util.sqlEngine.SQLPlusEngine.executeScript(SQLPlusEngine.java:339)
at oracle.sysman.assistants.util.sqlEngine.SQLPlusEngine.executeScript(SQLPlusEngine.java:380)
at oracle.sysman.emcp.EMReposConfig.createRepository(EMReposConfig.java:510)
at oracle.sysman.emcp.EMReposConfig.invoke(EMReposConfig.java:228)
at oracle.sysman.emcp.EMReposConfig.invoke(EMReposConfig.java:157)
at oracle.sysman.emcp.EMConfig.perform(EMConfig.java:253)
at oracle.sysman.emcp.EMConfigAssistant.invokeEMCA(EMConfigAssistant.java:589)
at oracle.sysman.emcp.EMConfigAssistant.performConfiguration(EMConfigAssistant.java:1448)
at oracle.sysman.emcp.EMConfigAssistant.statusMain(EMConfigAssistant.java:573)
at oracle.sysman.emcp.EMConfigAssistant.main(EMConfigAssistant.java:521)
Mar 31, 2012 4:16:06 PM oracle.sysman.emcp.EMReposConfig invoke
SEVERE: Error creating the repository www.2cto.com
解决办法
使用SYS用户登录sqlplus,然后执行下面的语句:
SQL> SELECT * FROM DBA_DATA_FILES where TABLESPACE_NAME = 'SYSTEM';
FILE_NAME FILE_ID TABLESPACE_NAME
BYTES BLOCKS STATUS RELATIVE_FNO AUT MAXBYTES MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS
ONLINE_ /data01/rdbms/wcdb/datafile/wcdb_system_01.dbf 1 SYSTEM 536870912 65536 AVAILABLE
1 NO 0 0 0 535822336 65408
SYSTEM
然后新定义个空间文件wcdb_system_02.dbf,注意不要重名
然后新定义个空间文件*wcdb_system_02.dbf*,注意不要重名
SQL> ALTER TABLESPACE SYSTEM ADD DATAFILE '/data01/rdbms/wcdb/datafile/wcdb_system_02.dbf' SIZE 500M; Tablespace altered.
然后再次执行EM创建成功!
EM的访问地址:https://localhost:1158/em
删除一个EM资料库
$ emca -repos drop
配置数据库的 Database Control
$ emca -config dbcontrol db
删除数据库的 Database Control配置
$ emca -deconfig dbcontrol db
重新配置db control的端口,默认端口在1158
$ emca -reconfig ports $ emca -reconfig ports -dbcontrol_http_port 1160 $ emca -reconfig ports -agent_port 3940 www.2cto.com
先设置ORACLE_SID环境变量后,启动EM console服务
$ emctl start dbconsole
先设置 ORACLE_SID环境变量后,停止EM console服务
$ emctl stop dbconsole
先设置ORACLE_SID环境变量后,查看EM console服务的状态
$ emctl status dbconsole
linux Oracle11G 归档模式su - oracle
sqlplus /nolog
SQL> conn / as sysdba
SQL> --查看是否归档模式
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
...
SQL> --关闭归档模式
SQL> alter system set log_archive_start=false scope=spfile; #禁用自动归档
SQL> shutdown immediate;
SQL> startup mount; #数据库启动到mount,打开控制文件
SQL> alter database noarchivelog; #将数据库改为非归档模式
SQL> alter database open; #打开数据文件
SQL> archive log list; #查看当前归档模式