Question

Currently, I have an application that uses Firebird in embedded mode to connect to a relatively simple database stored as a file on my hard drive. I want to switch to using PostgreSQL to do the same thing (Yes, I know it's overkill). I know that PostgreSQL cannot operate in embedded mode and that is fine - I can leave the server process running and that's OK with me.

I'm trying to figure out a connection string that will achieve this, but have been unsuccessful. I've tried variations on the following:

jdbc:postgresql:C:\myDB.fdb
jdbc:postgresql://C:\myDB.fdb
jdbc:postgresql://localhost:[port]/C:\myDB.fdb

but nothing seems to work. PostgreSQL's directions don't include an example for this case. Is this even possible?

Was it helpful?

Solution

Postgres databases are not a single file. There will be one file for each table and each index in the data directory, inside a directory for the database. All files will be named with the object ID (OID) of db / table / index.

The JDBC urls point to the database name, not any specific file: jdbc:postgresql:foodb (localhost is implied)

If by "disk that behaves like memory", you mean that the db only exists for the lifetime of your program, there's no reason why you can't create a db at program start and drop it at program exit. Note that this is just DDL to create the DB, not creating the data dir via the init-db program. You could connect to the default 'postgres' db, create your db then connect to it.

OTHER TIPS

You can trick it. If you are running PostGRESQL on a UNIXlike system, then you should be able to create a RAMDISK and use that for the database storage. Here's a pretty good step by step guide for RAMdisks on Linux.

In general though, I would suggest using SQLITE for an SQL db in RAM type of application.

Firebird 2.1 onwards supports global temporary tables, which only exist for the duration of the database connection.

Syntax goes something like CREATE GLOBAL TEMPORARY TABLE ... ON COMMIT PRESERVE ROWS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top