dbTalk Databases Forums  

In-memory PostgreSQL database

comp.databases.postgresql comp.databases.postgresql


Discuss In-memory PostgreSQL database in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ben Finney
 
Posts: n/a

Default In-memory PostgreSQL database - 05-14-2008 , 01:05 AM






Howdy all,

I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?

--
\ “Leave nothing to chance. Overlook nothing. Combine |
`\ contradictory observations. Allow yourself enough time.” |
_o__) —Hippocrates |
Ben Finney

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:32 AM






Ben Finney <ben (AT) benfinney (DOT) id.au> wrote:
Quote:
I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
There is no "embedded database" in PostgreSQL.

I am very surprised that you even consider running unit tests with
anything else than the database you want to use in production. Doesn't
that take away much of the benefits of unit testing?

If it is the overhead of establishing server connections that worries
you, why don't you write your unit tests so that the connection is kept
open?

If you are worried about concurrent unit tests thrashing each other's data,
you could have one database per developer in one PostgreSQL cluster
on a central server.

You can also install testing databases locally on the developers' machines,
but that will mean that you have to have a database server process running
on each machine.

Yours,
Laurenz Albe


Reply With Quote
  #3  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:32 AM



Ben Finney <ben (AT) benfinney (DOT) id.au> wrote:
Quote:
I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
There is no "embedded database" in PostgreSQL.

I am very surprised that you even consider running unit tests with
anything else than the database you want to use in production. Doesn't
that take away much of the benefits of unit testing?

If it is the overhead of establishing server connections that worries
you, why don't you write your unit tests so that the connection is kept
open?

If you are worried about concurrent unit tests thrashing each other's data,
you could have one database per developer in one PostgreSQL cluster
on a central server.

You can also install testing databases locally on the developers' machines,
but that will mean that you have to have a database server process running
on each machine.

Yours,
Laurenz Albe


Reply With Quote
  #4  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:32 AM



Ben Finney <ben (AT) benfinney (DOT) id.au> wrote:
Quote:
I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
There is no "embedded database" in PostgreSQL.

I am very surprised that you even consider running unit tests with
anything else than the database you want to use in production. Doesn't
that take away much of the benefits of unit testing?

If it is the overhead of establishing server connections that worries
you, why don't you write your unit tests so that the connection is kept
open?

If you are worried about concurrent unit tests thrashing each other's data,
you could have one database per developer in one PostgreSQL cluster
on a central server.

You can also install testing databases locally on the developers' machines,
but that will mean that you have to have a database server process running
on each machine.

Yours,
Laurenz Albe


Reply With Quote
  #5  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:32 AM



Ben Finney <ben (AT) benfinney (DOT) id.au> wrote:
Quote:
I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
There is no "embedded database" in PostgreSQL.

I am very surprised that you even consider running unit tests with
anything else than the database you want to use in production. Doesn't
that take away much of the benefits of unit testing?

If it is the overhead of establishing server connections that worries
you, why don't you write your unit tests so that the connection is kept
open?

If you are worried about concurrent unit tests thrashing each other's data,
you could have one database per developer in one PostgreSQL cluster
on a central server.

You can also install testing databases locally on the developers' machines,
but that will mean that you have to have a database server process running
on each machine.

Yours,
Laurenz Albe


Reply With Quote
  #6  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:32 AM



Ben Finney <ben (AT) benfinney (DOT) id.au> wrote:
Quote:
I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
There is no "embedded database" in PostgreSQL.

I am very surprised that you even consider running unit tests with
anything else than the database you want to use in production. Doesn't
that take away much of the benefits of unit testing?

If it is the overhead of establishing server connections that worries
you, why don't you write your unit tests so that the connection is kept
open?

If you are worried about concurrent unit tests thrashing each other's data,
you could have one database per developer in one PostgreSQL cluster
on a central server.

You can also install testing databases locally on the developers' machines,
but that will mean that you have to have a database server process running
on each machine.

Yours,
Laurenz Albe


Reply With Quote
  #7  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:32 AM



Ben Finney <ben (AT) benfinney (DOT) id.au> wrote:
Quote:
I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
There is no "embedded database" in PostgreSQL.

I am very surprised that you even consider running unit tests with
anything else than the database you want to use in production. Doesn't
that take away much of the benefits of unit testing?

If it is the overhead of establishing server connections that worries
you, why don't you write your unit tests so that the connection is kept
open?

If you are worried about concurrent unit tests thrashing each other's data,
you could have one database per developer in one PostgreSQL cluster
on a central server.

You can also install testing databases locally on the developers' machines,
but that will mean that you have to have a database server process running
on each machine.

Yours,
Laurenz Albe


Reply With Quote
  #8  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:32 AM



Ben Finney <ben (AT) benfinney (DOT) id.au> wrote:
Quote:
I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
There is no "embedded database" in PostgreSQL.

I am very surprised that you even consider running unit tests with
anything else than the database you want to use in production. Doesn't
that take away much of the benefits of unit testing?

If it is the overhead of establishing server connections that worries
you, why don't you write your unit tests so that the connection is kept
open?

If you are worried about concurrent unit tests thrashing each other's data,
you could have one database per developer in one PostgreSQL cluster
on a central server.

You can also install testing databases locally on the developers' machines,
but that will mean that you have to have a database server process running
on each machine.

Yours,
Laurenz Albe


Reply With Quote
  #9  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:32 AM



Ben Finney <ben (AT) benfinney (DOT) id.au> wrote:
Quote:
I'm using PostgreSQL as the server for several of my applications, but
unit testing the application by setting up and SQLite in-memory
database during the test case. This is workable, and certainly better
than the unacceptable overhead of connecting to a PostgreSQL server
when running the unit tests.

This has limitations, though: there are many PostgreSQL features that
aren't supported in SQLite, so the unit test fixtures have to fake a
lot of it for the sake of the PostgreSQL-specific application code.

What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
There is no "embedded database" in PostgreSQL.

I am very surprised that you even consider running unit tests with
anything else than the database you want to use in production. Doesn't
that take away much of the benefits of unit testing?

If it is the overhead of establishing server connections that worries
you, why don't you write your unit tests so that the connection is kept
open?

If you are worried about concurrent unit tests thrashing each other's data,
you could have one database per developer in one PostgreSQL cluster
on a central server.

You can also install testing databases locally on the developers' machines,
but that will mean that you have to have a database server process running
on each machine.

Yours,
Laurenz Albe


Reply With Quote
  #10  
Old   
Marco Mariani
 
Posts: n/a

Default Re: In-memory PostgreSQL database - 05-14-2008 , 04:41 AM



Ben Finney wrote:

Quote:
What options are there for creating and connnecting to a PostgreSQL
database that exists only in memory, similar to the same thing in
SQLite (and, I believe, MySQL)?
I don't think you would gain anything by keeping the DB in RAM with
postgres, because it's CPU-bound if there is little data.

If the test DB fits in RAM, this means Postgres already leverages the
memory as cache (if configured properly)

In my current application, I truncate and refill all the tables after
each of the 500 test.

I tried creating a tablespace in ramdisk, and had no performance
improvement at all.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.