2010-05-02 32 views
1

我正在爲使用postgresql的DAO做一些單元測試。我的DAO使用的一些SQL查詢涉及DATE函數。是否有內存數據庫支持與postgresql相似的功能?有支持DATE功能的內存數據庫嗎?

目前我正在尋找對DATE功能的支持,但是,我明顯可以在將來看到自己使用其他功能。

+0

出於好奇 - 你在說什麼樣的DATE函數? (到Postgres手冊中的適當頁面的鏈接將會很有幫助。) – 2010-05-02 18:36:08

回答

0

在linux中,您可以使用ramdisk在postgresql中創建一個「內存數據庫」。在PostgreSQL的郵件列表從a thread報價:

In my opinion very nice solution is building part of PostgreSQL database in memory - below it is instruction how to build PostgreSQL schema in memory in Linux. I tested this with my ROLAP solution for recalculation MOLAP cubes in memory and then join with master cube (this speeds up proces about 10 times!!! - but in other solution may be different).

In grub (or other bootloader) you must declare ramdisk and then in OS:

mke2fs /dev/ram0 
mkdir /mnt/ram0 
mount /dev/ram0 /mnt/ram0 
mkdir /mnt/ram0/pgspace 
chown postgres:postgres mnt/ram0/pgspace 

The "/mnt/ram0/pgspace" folder must be empty (ERROR: directory "/mnt/ram0" is not empty)

And then you may create tables (in this schema of course) and write to them.

我沒試過,我不是100%肯定這工作沒有任何問題。還要注意的是,在同一個線程中,他們建議其他數據庫引擎在內存支持,但沒有提到關於DATE函數。其他rdbms也可以受益於ramdisk,如果它們支持表空間。

編輯

例:現在

CREATE TABLESPACE inram LOCATION '/mnt/ram0/pgspace'; 
CREATE TABLE foo(i int) TABLESPACE inram; 

foo表應該是在內存中的表。

+0

我真的不知道如何將它應用於單元測試。 – 2010-05-02 15:28:09

+0

@Chris J:我希望我能更好地回答你的問題。無論如何,這將是「這是你的一個,這只是一個替代」的答案。 – 2010-05-02 16:05:22

1

查看TimesTen內存數據庫。非常快,並有TO_DATE功能:

Command> SELECT TO_DATE ('1999, JAN 14', 'YYYY, MON DD') FROM dual; 
< 1999-01-14 00:00:00 > 
1 row found.