<p>If it's possible, I'm interested in being able to embed a PostgreSQL database, similar to <a href="http://www.sqlite.org/" rel="noreferrer">sqllite</a>.  I've read that it's <a href="http://bytes.com/forum/thread647637.html" rel="noreferrer">not possible</a>.  I'm no database expert though, so I want to hear from you.</p>

<p>Essentially I want PostgreSQL without all the configuration and installation.  If it's possible, tell me how.</p>

[{'answer_id': 60299, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 1, 'selected': False, 'text': "<p>PostgreSQL is intended to run as a stand-alone server; it's probably possible to embed it if you hack at it hard and long enough, but it would be much easier to just run it as intended in a separate process.</p>\n"}, {'answer_id': 60301, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 4, 'selected': False, 'text': '<p>You cannot embed it, nor should you try.  </p>\n\n<p>For embedding you should use <a href="http://www.sqlite.org/" rel="noreferrer">sqlite</a> as you mentioned or <a href="http://www.firebirdsql.org/" rel="noreferrer">firebird rdbms</a>.</p>\n'}, {'answer_id': 60358, 'author': 'Crag', 'author_id': 6238, 'author_profile': 'https://Stackoverflow.com/users/6238', 'pm_score': 5, 'selected': True, 'text': '<p>Unless you do a major rewrite of code, it is not possible to run Postgres "embedded". Either run it as a separate process or use something else. SQLite is an excellent choice. But there are others. MySQL has an embedded version. See it at <a href="http://mysql.com/oem/" rel="noreferrer">http://mysql.com/oem/</a>. Also several java choices, and Mac has Core Data you can write too. Hell, you can even use FoxPro. What OS you on and what services you need from the database?</p>\n'}, {'answer_id': 113326, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>You can\'t embed it as a in process type thing like sqlite etc, but you can easily embed it into your application setup using Inno setup at <a href="http://www.innosetup.org" rel="noreferrer">http://www.innosetup.org</a>.  Search their mailing list archive and you will find someone did most of the work for you and all you have to to is grab the zipped distro and you can easily have postgresql installed when the user installs your app.  You can then use the pg_hba.conf file to restrict the server to local host only.  Not a true embedded DB, but it would work.</p>\n'}, {'answer_id': 359652, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Anyone tried on Mac OS X:</p>\n\n<p><a href="http://pagesperso-orange.fr/bruno.gaufier/xhtml/prod_postgresql.xhtml" rel="nofollow noreferrer">http://pagesperso-orange.fr/bruno.gaufier/xhtml/prod_postgresql.xhtml</a></p>\n\n<p><a href="http://www.macosxguru.net/article.php?story=20041119135924825" rel="nofollow noreferrer">http://www.macosxguru.net/article.php?story=20041119135924825</a></p>\n\n<p>(Of course sqlite would be my embedded db of choice as well)</p>\n'}, {'answer_id': 4234810, 'author': 'brcha', 'author_id': 230939, 'author_profile': 'https://Stackoverflow.com/users/230939', 'pm_score': 4, 'selected': False, 'text': '<p>Run postgresql in a background process.</p>\n\n<p>Start a separate thread in your application that would start a postgresql server in local mode either by binding it to localhost with some random free port or by using sockets (does windows support sockets?). That should be fairly easy, something like:</p>\n\n<p>system("C:\\Program Files\\MyApplication\\pgsql\\postgres.exe -D C:\\Documents and Settings\\User\\Local Settings\\MyApplication\\database -h 127.0.0.1 -p 12345");</p>\n\n<p>and then just connect to 127.0.0.1:12345.</p>\n\n<p>When your application quits, you can always send a SIGTERM to your thread and then wait a few seconds for postgresql to quit (ie join the thread).</p>\n\n<p>PS: You can also use <a href="http://www.postgresql.org/docs/8.4/static/app-pg-ctl.html">pg_ctl</a> to control your "embedded" database, even without threads, just do a "pg_ctl start" (with appropriate options) when starting the application and "pg_ctl stop" when quitting it.</p>\n'}, {'answer_id': 8852027, 'author': 'Karel Vervaeke', 'author_id': 1147319, 'author_profile': 'https://Stackoverflow.com/users/1147319', 'pm_score': 1, 'selected': False, 'text': '<p>HSQLDB (http://hsqldb.org/) is another db which is easily embedded. Requires Java, but is an excellent and often-used choice for Java applications.</p>\n'}, {'answer_id': 69473393, 'author': 'elikesprogramming', 'author_id': 5141196, 'author_profile': 'https://Stackoverflow.com/users/5141196', 'pm_score': 0, 'selected': False, 'text': '<p>Well, I know this is a very very very old post, but if anyone has nowadays this question, I would refer to:</p>\n<ul>\n<li>You can use containers running Postgres. Here\'s a post that could be helpful, doing something along this line using <code>R</code>:\n<a href="https://rsangole.netlify.app/post/2021/08/07/docker-based-rstudio-postgres/?utm_source=pocket_mylist" rel="nofollow noreferrer">https://rsangole.netlify.app/post/2021/08/07/docker-based-rstudio-postgres/?utm_source=pocket_mylist</a></li>\n<li>Take a look at <code>duckdb</code> <a href="https://duckdb.org/docs/installation/" rel="nofollow noreferrer">https://duckdb.org/docs/installation/</a> It is relatively new and still needs to mature. But it works pretty much like an embedded database (&quot;In-process, serverless&quot;), with bindings for several languages (Python, R, Java, ...)</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/60285', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/525/']