Oracle Database

Oracle Database

傻逼甲骨文公司出的傻逼数据库软件

启动 db

# su - oracle # 切换到数据库用户
# export ORACLE_SID=dbname # 使用非默认db时需要
$ lsnrctl start
$ sqlplus /nolog
SQL> conn /as sysdba
SQL> startup

开机自启动

/usr/bin/oracle.sh

#!/bin/sh

# Usage: su oracle -c /usr/bin/oracle.sh

export ORACLE_HOME=/app/oracle/product/11g/db_1
export PATH=$PATH:$ORACLE_HOME/bin

lsnrctl start
dbstart $ORACLE_HOME

Tips & Solutions

ORA-00845: MEMORY_TARGET not supported on this system

You will get a ORA-00845 error if your shared memory file system is not big enough to accommodate memory_target and memory_max_target. There are two possible ways to remove the ORA-00845 error:

  • Reduce the value for the memory_target parameter
  • Increase the temporary memory allocation on the server. This should fix the ORA-00845 error:
umount tmpfs
mount -t tmpfs shmfs -o size=16384m /dev/shm

vim /etc/fstab

#tmpfs                   /dev/shm                tmpfs   defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults,size=16G        0 0

ORA-01653: unable to extend table by in tablespace APUBTBS

Just add a new datafile for the existing tablespace

ALTER TABLESPACE APUBTBS ADD DATAFILE '/u01/oradata/userdata03.dbf' SIZE 2000M;
ALTER TABLESPACE APUBTBS add datafile '/oradata/dbs/apubtbs_new1.dbf'
   size 5000M autoextend on;

To find out the location and size of your data files:

SELECT FILE_NAME, BYTES FROM DBA_DATA_FILES WHERE TABLESPACE_NAME = 'APUBTBS';

"ORA-28001: The password has expired" Fix

# su - oracle
$ lsnrctl start
$ sqlplus /nolog
SQL> conn /as sysdba
SQL> alter user {{username}} identified by {{password}} account unlock;
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;

我就想说所有“强制密码有效期”的设定都是傻逼。

傻逼 Java Driver

傻逼 Oracle 的 傻逼 Java 驱动在 傻逼 maven 等仓库都没有,只能到傻逼 Oracle 官网下载。而且傻逼 Oracle 的官网下载文件竟然还要注册。

// 傻逼 Oracle 有好几个版本的 傻逼 Java 驱动,什么 ojdbc6.jar ojdbc7.jar ojdbc14.jar 等等等等。
// 分别对应的是傻逼 Java 6, 傻逼 Java 7, 傻逼 Java 1.4 等。

// ojdbc7.jar

import java.sql.*;
import java.io.*;
import java.util.*;

try {
  // no need for JDBC 4.0+ drivers, which are automatically loaded if found in class path
  // Class.forName("oracle.jdbc.driver.OracleDriver")
  // DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
  // connection string format: (port part omit-table; user / pass can be provided separately)
  // "jdbc:oracle:thin:username/password@host:1521:sid
  // or "jdbc:oracle:thin:username/password@host:1521/service_name"
  Connection con = DriverManager.getConnection("jdbc:oracle:thin:username/password@1.2.3.4:db");
  // Connection con = DriverManager.getConnection("jdbc:oracle:thin:@1.2.3.4:db","username","password");
} catch( Exception e) {
  e.printStackTrace();
}

Dummy table

Use for connection verification

select 1 from DUAL


Last update: 2020-08-17 04:52:25 UTC