Thread: Embedded Database

Embedded Database

From
"Richard Connamacher"
Date:
I have two questions about PostgreSQL:

Does anybody know if it can be used as an embedded database engine within an application,
so the application doesn't have to connect to an external server? (I have looked at SQLite, and
I'd rather use PostgreSQL for my app, footprint be damned.)

And, does anybody know if it's possible for PostgreSQL to run a database entirely in RAM
without saving the file out to disk?

Thanks,
Richard

Re: Embedded Database

From
"Scott Marlowe"
Date:
On Mon, 2004-08-09 at 02:30, Richard Connamacher wrote:
> I have two questions about PostgreSQL:
>
> Does anybody know if it can be used as an embedded database engine within an application,
> so the application doesn't have to connect to an external server? (I have looked at SQLite, and
> I'd rather use PostgreSQL for my app, footprint be damned.)
>
> And, does anybody know if it's possible for PostgreSQL to run a database entirely in RAM
> without saving the file out to disk?

Neither of those are strong points of PostgreSQL.

However, if you're willing to take an ax to the template0/1 system and
chop off the parts you don't need, you can get a default database down
fairly small, and mounting a ram disk for the database handles the
"entirely in ram" thing (no, there's no built in facility for in ram
operation and not likely to ever be one.)


Re: Embedded Database

From
dmartini@uni-hohenheim.de
Date:
Hi,

Citing Richard Connamacher <rich.n1@indieimage.com>:
> And, does anybody know if it's possible for PostgreSQL to run a database
> entirely in RAM
> without saving the file out to disk?

In principle yes:
On BSD platforms, there's the possibility to create memory based filesystems,
mount them (command is mount_mfs, don't remember about Linux, it's possible
there too, but it's been so long since I last used it) and use them like a real
hard disk based file system. Of course, everytime you reboot, your database
would be gone, so you would have to write a program/shell script to initialize
the database (initdb), start the database server with the proper config files
(you would want to modify the WAL behaviour, as the default behaviour is
probably mostly useless in this case (if you pull the power supply, the data
is gone anyways)) and populate the database.

If this is really sensible depends on your needs. Offline field measurement
data logging on machines without a hard drive would be a use which comes to
mind (but only if you require some features of postgresql which can not be
done using a simpler database engine (maybe a flatfile database).

Regards,
Daniel

Re: Embedded Database

From
Jeff Davis
Date:
On Mon, 2004-08-09 at 01:30, Richard Connamacher wrote:
> Does anybody know if it can be used as an embedded database engine within an application,
> so the application doesn't have to connect to an external server? (I have looked at SQLite, and
> I'd rather use PostgreSQL for my app, footprint be damned.)
>

There are no embedded database libraries for PostgreSQL data. Even a
well-designed embedded database library can leave your data corrupted
due to an applicaiton bug (because an embedded DB runs in the same
address space as the application, so it has no way to protect itself
from application bugs). Dangers like this, in addition to the
fundamental design differences, mean that one probably won't be
developed any time soon.

> And, does anybody know if it's possible for PostgreSQL to run a database entirely in RAM
> without saving the file out to disk?
>

Linux has the "tmpfs" filesystem. Just put all the DB files in a tmpfs
mount.

Hope this helps,
    Jeff Davis