启动Oracle报 ORA-00845: MEMORY_TARGET not supported on this system

今天晚上新装一台Oracle 11g的数据库,打算将SGA设大一点,知道 11g 中有一个新特新 MEMORY_TARGET,于是尝一下鲜,谁知报了个 ORA-00845,报错比较容易迷惑人,不借助Google真得想半天:

1
2
3
4
5
6
7
8
9
10
11
SQL> alter system set memory_max_target=3G scope=spfile ;
System altered.
SQL> alter system set memory_target=2G scope=spfile ;
System altered.
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup ;
ORA-00845: MEMORY_TARGET not supported on this system

###来自Oracle的官方解析是:

Starting with Oracle Database 11g, the Automatic Memory Management feature requires more shared memory (/dev/shm)and file descriptors. The size of the shared memory should be at least the greater of MEMORY_MAX_TARGET and MEMORY_TARGET for each Oracle instance on the computer. If MEMORY_MAX_TARGET or MEMORY_TARGET is set to a non zero value, and an incorrect size is assigned to the shared memory, it will result in an ORA-00845 error at startup.

错误原因:

简单来说就是 MEMORY_MAX_TARGET 的设置不能超过 /dev/shm 的大小:

1
2
[oracle@FWDB FWDB]$ df -h | grep shm
tmpfs 2.0G 0 2.0G 0% /dev/shm

还真是撞到这个枪口上了,马上把它加大:

1
2
[root@FWDB ~]# cat /etc/fstab | grep tmpfs
tmpfs /dev/shm tmpfs defaults,size=4G 0 0

现在可以通过重启使这个配置生效,也可以通过重新挂载来修改其大小:

1
2
3
[root@FWDB ~]# mount -o remount,size=4G /dev/shm
[root@FWDB ~]# df -h | grep shm
tmpfs 4.0G 0 4.0G 0% /dev/shm

再次启动数据库,没有报错了:

1
2
3
4
5
6
7
8
9
su - oracle
lsnrctl stop
ps -ef|grep $ORACLE_SID|grep -v ora_|grep LOCAL=NO|awk '{print $2}'|xargs kill
sqlplus / as sysdba
shutdown immediate
exit
lsnrctl start
sqlplus / as sysbda
startup

Spring Jpa Date 基础用法

. = = 首先得有Spring和Hibernate环境,不再赘述.

第一步

创建一个实体类 MsgMeassage,IdEntity类里面的CreateTime和Id

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@Entity
@Table(name = "msg_meassage")
@DynamicInsert(true)
@DynamicUpdate(true)
public class MsgMeassage extends IdEntity {
private Doctor doctor;
private String info;
public MsgMeassage() {
}
@ManyToOne(cascade = CascadeType.REFRESH, optional = true)
@JoinColumn(name = "doctor_id")
public Doctor getDoctor() {
return this.doctor;
}
public void setDoctor(Doctor doctor) {
this.doctor = doctor;
}
@Column(name = "info")
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}

第二步

创建MsgMeassageDao,继承JpaRepository和JpaSpecificationExecutor

1
2
3
public interface MsgMeassageDao extends JpaRepository<MsgMeassage, Long>, JpaSpecificationExecutor<MsgMeassage> {
}

第三步

创建MsgMeassageServiceImpl,然后自动注入 MsgMeassageDao ,接下来我们要查询数据的时候就
可以这样写了
* 比如我想查询所有的MsgMeassage,因为JpaRepository封装了很多常用的方法,我们可以直
接调用 findAll,findOnd,delete,save 等等常用的方法,列子如下:

1
2
3
4
5
6
@Resource
private MsgMeassageDao msgMeassageDao;
//直接保存 MsgMeassage 对象
public void save(MsgMeassage msgMeassage) {
msgMeassageDao.save(msgMeassage);
}

比如我想加入条件查询,比如 查询某一个医生的MsgMeassage就可以这样:
SQL代码如下
1
select * from MsgMeassage ms where ms.doctor=XXX
Java 代码这样写 达到同样的功能
1
2
3
4
5
6
7
8
9
10
11
12
@Resource
private MsgMeassageDao msgMeassageDao;
public MsgMeassage getMeassageByDoctor(final Doctor doctor) {
return msgMeassageDao.findOne(new Specification<MsgMeassage>() {
@Override
public Predicate toPredicate(Root<MsgMeassage> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = Lists.newArrayList();
predicateList.add(cb.equal(root.get(MsgMeassage_.doctor), doctor));
return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
}
});
}
= = 并且连删除方法都可以这样做(反面教材,很影响性能,千万别这么干)
1
2
3
4
5
6
7
8
9
10
public void delMeassageByDoctor(final Doctor doctor) {
msgMeassageDao.delete(msgMeassageDao.findAll(new Specification<MsgMeassage>() {
@Override
public Predicate toPredicate(Root<MsgMeassage> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = Lists.newArrayList();
predicateList.add(cb.equal(root.get(MsgMeassage_.doctor), doctor));
return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
}
}));
}
本文暂时聊到这里 下一次更新 会详细说明下 怎么使用 Specification 来 用面向对象

的方式来替换sql.

= = 2333

平时会不定期分享学习中的心得,互相交流,希望能够为大家提供一点点小心的帮助.

关于我

= =,同事给的定义是逗逼一个.性格开朗/喜欢编码/见啥都喜欢学 被雷击过几次
之后就明白还是先学好JAVA才行.前台的布局是我最讨厌的东西,特别是兼容性的问
题.不过对JS方面相关东西很是热爱,哈哈 在我看来JS各种框架的代码写起来摊比后
端代码一样爽了.

喜欢LOL,守望屁股.

JAVA 方面也是停留在菜鸟级别

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
xxxxDao.findAll(new Specification<Emr>() {
@Override
public Predicate toPredicate(Root<Emr> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = Lists.newArrayList();
if (StringUtils.isNotEmpty(patientName)) {
//root.get("patientName").as(String.class) 无需创建 类_
predicates.add(cb.like(root.get("patientName").as(String.class), "%" + patientName + "%"));
}
if (null != dateFilter && dateFilter.isValid()) {
predicates.add(cb.between(root.get("createOn").as(Date.class), dateFilter.getStartDate(), dateFilter.getRealEndDate()));
}
if (Numbers.isNotNullOrZero(doctorId)) {
predicates.add(cb.equal(root.get("doctor").as(Doctor.class), new Doctor(doctorId)));
}
if (null != diagonsisName && !"".equals(diagonsisName)) {
// 需要创建 类_
predicates.add(cb.like(root.get(Emr_.diagnosisResult), "%" + diagonsisName + "%"));
}
if (null != ageFilter && ageFilter.isValid()) {
predicates.add(cb.between(root.get(Emr_.patient).get(Patient_.birthday), ageFilter.getStartDate(), ageFilter.getRealEndDate()));
}
if (null != genderSex && genderSex != Gender.All) {
predicates.add(cb.equal(root.get(Emr_.patient).get(Patient_.gender), genderSex));
}
query.orderBy(cb.desc(root.get(Emr_.createOn)));
if (!predicates.isEmpty()) {
query.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
}
query.groupBy(root.get(Emr_.patient), root.get(Emr_.doctor));
return query.getGroupRestriction();
}
});

不定期更新IDEA的使用心的和JAVA以及JS方面的东西,互相学习.

Anyway 感谢你进入我的博客.如果我写的任何东西对你有帮助的话,也让我欣慰万分.