Search code, repositories, users, issues, pull requests…

yandex eu
yandex eu

Maven Central Build status Windows build status

Embedded PostgreSQL server provides a platform neutral way for running postgres binaries in unittests. This library is based on Flapdoodle OSS’s embed process.

Sorry for any inconvinience, but this project needs active maintainers. If anyone is interested in becoming the maintainer – please let me (@smecsia) know.

Please be adviced that the main maintainer of this project has successfuly migrated to the use of Test Containers project. This is the best possible alternative nowadays.

  • It’s much easier than installing specific version manually
  • You can choose the version right from the code
  • You can start your development environment with the PostgreSQL embedded with the single command

Add the following dependency to your pom.xml:

Add a line to build.gradle:

Here is the example of how to launch and use the embedded PostgreSQL instance

Note that EmbeddedPostgres implements java.lang.AutoCloseable, which means that you can use it with a try-with-resources statement (in Java >= 7) to have it automatically stopped.

You can specify the cached artifact store to avoid archives downloading and extraction (in case if a directory remains on every run).

Just configure your own slf4j appenders. Here is the example of typical src/test/resources/log4j.properties file:

Pass the required IVersion interface implementation as a first argument of the EmbeddedPostgres object:

  • A lot of issues have been reported for this library under Windows. Please try to use the suggested way of start up and use the cached artifact storage (to avoid extraction of the archive as extraction is extremely slow under Windows):
  • PostgreSQL server is known to not start under the privileged user (which means you cannot start it under root/Administrator of your system):

initdb must be run as the user that will own the server process, because the server needs to have access to the files and directories that initdb creates. Since the server cannot be run as root, you must not run initdb as root either. (It will in fact refuse to do so.) (link).

However some users have launched it successfully on Windows under Administrator, so you can try anyway.

  • 11.2: on Mac OS X and Windows 64 bit
  • 10.7, 9.6.12, 9.5.16: on Linux, Windows, Mac OS X
  • any custom version