Git Product home page Git Product logo

otj-pg-embedded's Introduction

OpenTable Embedded PostgreSQL Component

Note: This library requires Java 11+. However, Flyway 10 requires Java 17. The last pure Java 11 release was 1.0.3

Allows embedding PostgreSQL into Java application code, using Docker containers. Excellent for allowing you to unit test with a "real" Postgres without requiring end users to install and set up a database cluster.

Recent Changes

The release of 1.0 brings major changes to the innards of this library. Previous pre 1.x versions used an embedded tarball. This was extremely fast (a major plus), but we switched to a docker based version for these reasons:

  • Advantages:
    • multi architecture support. This has become a huge issue for us with the introduction of the Mac M1 (and Windows ARM, Linux ARM)/
    • The same container works the same way on every OS - Mac, Windows, Linux.
    • You need a tarball for every linux distribution as PG 10+ no longer ship a "universal binary" for linux. This means a lot of support and maintenance work.
    • Easy to switch docker image tag to upgrade versions - no need for a whole new pg-embedded version.
    • More maintainable and secure (you can pull docker images you trust, instead of trusting our tarballs running in your security context)
    • Trivial to do a build oneself based on the official Postgres image adding extensions, setup scripts etc. - see https://github.com/docker-library/docs/blob/master/postgres/README.md for details.
  • Admittedly, a few disadvantages
    • Slower than running a tarball (2-5x slower).
    • A few API compatibility changes and options have probably disappeared. Feel free to submit PRs.
    • Docker in Docker can be dodgy to get running. (See below for one thing we discovered)

Before filing tickets.

  1. Before filing tickets, please test your docker environment etc. If using podman or lima instead of "true docker", state so, and realize that the docker socket api provided by these apps is not 100% compatible, as we've found to our sadness. We'll be revisiting testing these in the future. We've managed to get PodMan working, albeit not 100% reliably.
  2. No further PRs or tickets will be accepted for the pre 1.0.0 release, unless community support arises for the legacy branch. Please base any PRs for pre 1.x against the legacy branch.
  3. We primarily use Macs and Ubuntu Linux at OpenTable. We'll be happy to try to help out otherwise, but other platforms, such as Windows depend primarily on community support. We simply don't have the time or hardware. Happy to merge PRs though

See "Alternatives Considered" as well if this library doesn't appear to fit your needs.

Basic Usage

In your JUnit test just add (for JUnit 5 example see Using JUnit5 below):

@Rule
public SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance();

This simply has JUnit manage an instance of EmbeddedPostgres (start, stop). You can then use this to get a DataSource with: pg.getEmbeddedPostgres().getPostgresDatabase();

Additionally, you may use the EmbeddedPostgres class directly by manually starting and stopping the instance; see EmbeddedPostgresTest for an example.

Default username/password is: postgres/postgres and the default database is 'postgres'

The port exposed on the host is random and ephemeral so always use the getDatasource, getUrl methods

Sample of Embedded Postgres direct Usage

public void testDatabaseName() throws IOException,SQLException{
        EmbeddedPostgres db=EmbeddedPostgres.builder().start();
        Datasource dataSource = db.getPostgresDatabase();
        .... use the datasource then ...
        db.close();
        }

The builder includes options to set the image, the tag, the database name, and various configuration options.

Migrators (Flyway or Liquibase)

You can easily integrate Flyway or Liquibase database schema migration:

Flyway
@Rule 
public PreparedDbRule db =
    EmbeddedPostgresRules.preparedDatabase(
        FlywayPreparer.forClasspathLocation("db/my-db-schema"));
        
        
Please note: Recent versions of FLyway will probably hang if you have concurrent indexing. Use
the features described in the 1.0.3 changelog to disable the broken lock feature. See the FlywarePreparerTest
Liquibase
@Rule
public PreparedDbRule db = 
    EmbeddedPostgresRules.preparedDatabase(
            LiquibasePreparer.forClasspathLocation("liqui/master.xml"));

This will create an independent database for every test with the given schema loaded from the classpath. Database templates are used so the time cost is relatively small, given the superior isolation truly independent databases gives you.

Postgres version

The default is to use the docker hub registry and pull a tag, hardcoded in EmbeddedPostgres. Currently, this is "13-latest", as this fits the needs of OpenTable, however you can change this easily. This is super useful, both to use a newer version of Postgres, or to build your own DockerFile with additional extensions.

You may change this either by environmental variables or by explicit builder usage

Environmental Variables

  1. If PG_FULL_IMAGE is set, then this will be used and is assumed to include the full docker image name. So for example this might be set to docker.otenv.com/postgres:mytag
  2. Otherwise, if TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX is set, this is prefixed to "postgres" (adding a slash if it doesn't exist). So for example this might be set to "docker.otenv.com/"
  3. Otherwise, the default is used as defined above.

Explicit builder

It is possible to change postgres image and tag in the builder:

    EmbeddedPostgres.builder()
        .setTag("10")
        .start();

or use custom image:

    EmbeddedPostgres.builder()
        .setImage(DockerImageName.parse("docker.otenv.com/super-postgres"))
        .start();

There are also options to set the initDB configuration parameters, or other functional params, the bind mounts, and the network.

Using JUnit5

JUnit5 does not have @Rule. So below is an example for how to create tests using JUnit5 and embedded postgres, it creates a Spring context and uses JDBI:

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = DaoTestUsingJunit5.MockDBConfiguration.class)
class DaoTestUsingJunit5 {
    interface MyDao {}

    @Inject
    MyDao myDao;

    @Test
    void someTest() {
        // ....
    }

    @Import(DaoTestUsingJunit5.GlobalMockDBConfiguration.class)
    @Configuration
    static class MockDBConfiguration {
        @Bean
        public MyDao dao(Jdbi jdbi) {
            return jdbi.onDemand(MyDao.class);
        }
    }

    /**
     * This class is here as inner class for brevity,
     * but it's better to have only one for all tests.
     */
    @Configuration
    public static class GlobalMockDBConfiguration {
        @Bean("jdbiUser")
        @Primary
        Jdbi jdbi() throws SQLException {
            DatabasePreparer db = FlywayPreparer.forClasspathLocation("db/migration");

            Jdbi jdbi = Jdbi.create(PreparedDbProvider.forPreparer(db).createDataSource())
                    .installPlugin(new PostgresPlugin())
                    .installPlugin(new SqlObjectPlugin())
                    .setTransactionHandler(new SerializableTransactionRunner());

            return configureJdbi(jdbi);
        }

        static Jdbi configureJdbi(Jdbi jdbi) {
            // possible actions:
            // - register immutables
            // - set up mappers, etc
            return jdbi;
        }
    }
}

Yes, Junit4 is a compile time dependency

This is because TestContainers has a long outstanding bug to remove this -testcontainers/testcontainers-java#970 If you exclude Junit4, you get nasty NoClassDefFound errors.

If you only use Junit5 in your classpath, and bringing in Junit4 bothers you (it does us, sigh), then you can do the following:

  • add maven exclusions to the testcontainers modules you declare dependencies on to strip out junit:junit. This by itself would still lead to NoClassDefFound errors.
  • add a dependency on io.quarkus:quarkus-junit4-mock , which imports empty interfaces of the required classes. This is a hack and a cheat, but what can you do?

We initially excluded junit4 ourselves, which led to confusing breakages for junit5 users...

Some new options and some lost from Pre 1.0

  • You can't wire to a local postgres, since that concept doesn't make sense here. So that's gone.
  • You can add bind mounts and a Network (between two containers), since those are docker concepts, and can be very useful.
  • By the way, TestContainers does support ~/.docker/config.json for setting authenticated access to Docker, but we've not tested it.

Docker in Docker, authentication notes

We've been able to get this working in our CICD pipeline with the following

TESTCONTAINERS_HOST_OVERRIDE=localhost
TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=dockerhub.otenv.com/

The first parameter corrects for testcontainers getting confused whether to address the hosting container or the "container inside the container". The second parameter (which outside OpenTable would point to your private Docker Registry) avoids much of the Docker Rate Limiting issues.

See testcontainers/testcontainers-java#4596 for more information

Alternatives considered

We updated this library primarily for convenience of current users to allow them to make a reasonably smooth transition to a Docker based test approach.

  • Why not just use Testcontainers directly?

You can, and it should work well for you. The builders, the api compatibility, the wrapping around Flyway - that's the added value. But certainly there's no real reason you can't use TestContainers directly - they have their own Junit4 and Junit5 Rules/Extensions.

  • Why not use a maven plugin approach like fabric8-docker-maven?

Honestly I suspect this is a better approach in that it doesn't try to maintain its own version of the Docker API, and runs outside the tests, reducing issues like forking and threading conflicts. However, it would have been too major an overhaul for our users.

  • "I really prefer the old embedded postgres approach. It's faster."

    We recommend those who prefer the embedded tarball use https://github.com/zonkyio/embedded-postgres which was forked a couple of years ago from the embedded branch and is kept reasonably up to date.

    Another alternative is Flapdoodle's embedded postgres, but that is deprecated in favor of testcontainers too.

    Both libraries suffer from many of the cons that bedeviled upkeep of this library for years, but they are certainly viable options for many.


Copyright (C) 2017-2024 OpenTable, Inc

otj-pg-embedded's People

Contributors

arteam avatar benhardy avatar cannibalcow avatar cgc avatar danielcompton avatar dbunina avatar dependabot[bot] avatar dkaukov avatar elfrucool avatar epaul avatar flozano avatar gokceyucel avatar hgschmie avatar ilyapolikarpov avatar jond3k avatar jpierson-at-riis avatar jszczesnyoa avatar kevcodez avatar marekmalevic avatar meredrica avatar mikebell90 avatar motofix avatar msval avatar nedtwigg avatar pennello avatar poeschl avatar rushalias avatar stevenschlansker avatar tiagosimao avatar tomix26 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

otj-pg-embedded's Issues

Extension support

Is it possible to add extensions to the packaged postgres?
I was thinking about adding postgis.

Not able to create test database from .sql file

I am trying to create a test database from a .sql file . My code looks like below

public class EmbeddedPostgresTest {
    
    @Rule
    public PreparedDbRule db = EmbeddedPostgresRules.preparedDatabase(FlywayPreparer.forClasspathLocation("db"));


    @Test
    public void testTablesMade() throws Exception {
        try (Connection c = db.getTestDatabase().getConnection();
             Statement s = c.createStatement()) {
            ResultSet rs = s.executeQuery("SELECT * FROM permissions");
            rs.next();
            assertEquals("manage_permissions", rs.getString(1));
        }
    }
}

My test/resources/db/schema.sql looks like below

create table permissions (PermissionName varchar(64) NOT NULL,
                   Description varchar(256) NOT NULL,
                   CreatedBy text NOT NULL,
                   CreatedDate timestamp with time zone DEFAULT current_timestamp,
                   PRIMARY KEY(PermissionName));

insert into permissions values ('manage_permissions', 'Add/Remove/View/Modify roles and permissions', 'System');
insert into permissions values ('manage_users', 'Add/Remove/View/Modify users, reset passwords, assign roles', 'System');
insert into permissions values ('manage_data_sources', 'Add/Remove/View data sources', 'System');
insert into permissions values ('manage_tenants', 'Add/Remove/View tenants', 'System');

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test.embedded</groupId>
    <artifactId>psql</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.opentable.components/otj-pg-embedded -->
        <dependency>
            <groupId>com.opentable.components</groupId>
            <artifactId>otj-pg-embedded</artifactId>
            <version>0.9.0</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>5.0.5</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>(whatever version is current)</version>
                <configuration>
                    <!-- or whatever version you use -->
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

The directory looks like below

screen shot 2018-01-08 at 5 42 50 pm

Can someone let me know what is going wrong?

Errors with pg output processing

I am using this under Win10 x64, and my logs are looking like this:

[main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - 24a80e05-6dd1-4e9b-8e9e-a48a5934e0cd initdb completed in 00:00:07.492
[main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - 24a80e05-6dd1-4e9b-8e9e-a48a5934e0cd postmaster started as java.lang.ProcessImpl@3cd1f1c8 on port 50439. Waiting up to PT10S for server startup to finish.
[output redirector for java.lang.ProcessImpl@3cd1f1c8] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - �������� ������� �������....2018-02-21 20:34:47.672 +07 [14260] ���������: ��� ����� ����������� �� ������ IPv6 "::1" ������ ���� 50439
[output redirector for java.lang.ProcessImpl@3cd1f1c8] ERROR com.opentable.db.postgres.embedded.EmbeddedPostgres - while reading output
java.io.IOException: Stream closed
at java.io.BufferedReader.ensureOpen(BufferedReader.java:122)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at com.opentable.db.postgres.embedded.ProcessOutputLogger.run(ProcessOutputLogger.java:48)
at java.lang.Thread.run(Thread.java:748)

is it expected behavior ? I see 2 issues with this:

  1. encoding (those � should by Cyrillic, I believe)
  2. ERROR (Stream closed exception)

Further along, it seems to work, but this is sort of frustrating...

Setting PostgreSQL version

This example in README.md doesn't work anymore, since the constructor signature for ClassPathResource has changed:

class ClasspathBinaryResolver implements PgBinaryResolver {
    public InputStream getPgBinary(String system, String machineHardware) throws IOException {
        ClassPathResource resource = new ClassPathResource(format("postgresql-%s-%s.txz", system, machineHardware));
        return resource.getInputStream();
    }
}

Consider creating a Maven plugin

This library is by far the most flexible, reliable, fastest, and simply best one overall I've seen for embedded pgsql. Thank you!

Would you consider creating a maven plugin out of it? My use case is creating JOOQ code at generate-sources phase (so, running Flyway and then JOOQ against a live DB). Somehow this seems to be harder to do with a local, embedded pgsql than expected...

Explicitly setting locale for the database

Some database locale settings (i.e. LC_COLLATE, LC_CTYPE) can be set only when creating database. If not set explicitly, those settings are propagated from system locale settings. It results in undetermined behavior in tests which involve database sorting, when the same test is run in various environments with various system locale settings (i.e. Windows, Linux, Mac OS X). It would be nice to have a possibility to pass collation settings to initdb command somehow (as soon as EmbeddedPostgres class is designed not to be extended), or maybe use 'C' value as default? Thank you for your consideration.

Expose verifyReady() method

To help know when the Postgres instance is ready for use, exposing the verifyReady() method or a similar method as public would be extremely useful.

EmbeddedPostgreSQLRule missing

Your README.md refers to the classes EmbeddedPostgreSQLRule, EmbeddedPostgreSQL which are missing from .jar file (I tried versions 0.8.0 and 0.7.1). I don't see these in your source files as well.
I have imported only otj-pg-embedded jar in my pom.
Am I missing some other dependency?

Unable to delete file ... epg-lock (windows)

Working on windows 10, when starting embedded postgres below exception gets spammed 2 - 6 times.
The app continues to run afterward with DB up and running but the spam is annoying.

Version: 0.7.1

java.io.IOException: Unable to delete file: C:\Users\user_m\AppData\Local\Temp\embedded-pg\fd1546b8-53e2-4038-beb1-e47f50f36a37\epg-lock
	at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:2381)
	at org.apache.commons.io.FileUtils.cleanDirectory(FileUtils.java:1679)
	at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1575)
	at com.opentable.db.postgres.embedded.EmbeddedPostgres.cleanOldDataDirectories(EmbeddedPostgres.java:344)
	at com.opentable.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:110)
	at com.opentable.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:421)
	at com.opentable.db.postgres.embedded.EmbeddedPostgres.start(EmbeddedPostgres.java:363)
	at lt.funguide.fun.db.InMemoryDatabaseConfig.embeddedPostgres(InMemoryDatabaseConfig.java:49)

Server frozen

Hello there,

I'm unable to get the server working on my Mac Book Pro x86_64 running macOS Sierra 10.12.21. After debugging, the process is frozen at this line EmbeddedPostgres:431 (version 0.7.1)

Preconditions.checkState(0 == process.waitFor(), "Process %s failed\n%s", Arrays.asList(command), IOUtils.toString(process.getErrorStream()));

when running

system(pgBin("initdb"), "-A", "trust", "-U", PG_SUPERUSER, "-D", dataDirectory.getPath(), "-E", "UTF-8");

Any idea how to fix that issue ?

Thanks.

FATAL log messages to STDOUT cause issues with Jenkins

When running JUnit tests with Jenkins and using a Jenkins stdout/stderr parser, tests with otj-pg can fail because of the way Postgres logs to stdout. Postgres prints several FATAL:... messages at startup and shutdown, which can cause Jenkins to flag the test as failing.

Would be helpful to have a handle to stdout/stderr from the Postgres process which can be redirected to the test's logging subsystem or supressed.

Using a template database rather than Flyway.

I'm using this code right now:

DatabasePreparer prep = FlywayPreparer.forClasspathLocation("db/migration");
PreparedDbProvider provider = PreparedDbProvider.forPreparer(prep);

Rather than running FlywayPreparer, I'm hoping I can just open an existing database, and use it as a template that gets copied into all the prepared copies:

EmbeddedPostgres postgres = EmbeddedPostgres.builder()
					.setDataDirectory(existingDbDataDir)
					.start();

Try as I might, I am completely baffled as to how to implement DatabasePreparer. Any hints? Am I going about this all wrong? Thanks!

[QUESTION] Using the pg-embedded in an IOT

Hi,

I been searching for DBs that I can use in an IOT env (RPI 2/3). Although the main purpose of the project is for tests, can i use it as embedded DB such as H2 or HyperSQL?

THKS.

Failed to load Spring ApplicationContext when creating datasource

Hello guys and thank you for the awesome work.
I have an issue when I launch my unit tests (locally but more when I launch them on jenkins). It seems like it fails to load the application context because the following command fails :

/tmp/embedded-pg/PG-11dcc08f73460f51bbcf948559611bae/bin/initdb, -A, trust, -U, postgres, -D, /tmp/embedded-pg/5247740b-705f-4717-a1b5-8dfd2fdbbd55, -E, UTF-8

When I launch the unit tests on my computer it runs well but when I run it on jenkins it fails. I tried to clean the /tmp/embedded-pg before each build.

When i execute the command directly with the jenkins user, everything is fine.
I use spring boot so every tests creates a new database, maybe that's the problem ?

Any guesses please ?

I attached the stacked trace in a file. Thank you in advance.

stacktrace.txt

EmbeddedPostgres - if dataDirectory is deep, it cannot be created

Basically, this: https://github.com/opentable/otj-pg-embedded/blob/master/src/main/java/com/opentable/db/postgres/embedded/EmbeddedPostgres.java#L125

should be dataDirectory.mkdirs() instead. I'm using the library to write an embedded-postgres Maven plugin, and there the dataDirectory sometimes does not exist, and its parent directory does not, either. E.g. if the dataDirectory is target/pgdata, but mvn clean removed the target directory, it needs to be created.

Currently I'm doing this manually in my plugin, but the library should honestly just take care of that.

IllegalStateException when running process initDB on Linux within Docker

Environment: Ubuntu 16.04, Maven 3.5.4, otj-pg-embedded 0.12.1

We are seeing a problem running the module from maven on a Linux box within a Docker container.

04:08:13.751 [main] INFO c.o.d.p.embedded.EmbeddedPostgres - Detected a Linux x86_64 system 04:08:13.949 [main] INFO c.o.d.p.embedded.EmbeddedPostgres - Extracting Postgres... 04:08:16.257 [main] INFO c.o.d.p.embedded.EmbeddedPostgres - Postgres binaries at /tmp/embedded-pg/PG-2194babe356599ede43b2da5db755202 [ERROR] Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 2.783 s <<< FAILURE! - in ParameterDetailsDAOImplIT [ERROR] getCurrentParameterDetailsByParameterAndBranchReturnsNullWhenNotFound(ParameterDetailsDAOImplIT) Time elapsed: 2.556 s <<< ERROR! java.lang.IllegalStateException: Process [/tmp/embedded-pg/PG-2194babe356599ede43b2da5db755202/bin/initdb, -A, trust, -U, postgres, -D, /tmp/epg4882221037890953290, -E, UTF-8] failed

This is the only information provided, even if maven is ran with the -e switch.

It works fine when ran locally on MacOS but falls over on Linux in Docker. What could be wrong?

getting Stream Closed exception

i tried running the sample test given at 👍 https://github.com/opentable/otj-pg-embedded/blob/master/src/test/java/com/opentable/db/postgres/embedded/EmbeddedPostgresTest.java

using the following dependency:

<dependency>
			<groupId>com.opentable.components</groupId>
			<artifactId>otj-pg-embedded</artifactId>
			<version>0.11.0</version>
			<scope>test</scope>
		</dependency

and get the following output:

22:34:44.655 [main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - Detected a Windows x86_64 system
22:34:44.766 [main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - Postgres binaries at C:\Users\VIKESH~1\AppData\Local\Temp\embedded-pg\PG-20610842f7206a9abbecdcf12709c0f8
22:34:50.059 [main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - 375b9973-cb6f-4851-ba5a-b9b2690ee619 initdb completed in 00:00:05.289
22:34:50.180 [main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - 375b9973-cb6f-4851-ba5a-b9b2690ee619 postmaster started as java.lang.ProcessImpl@26be92ad on port 53255.  Waiting up to PT10S for server startup to finish.
22:34:50.400 [output redirector for java.lang.ProcessImpl@26be92ad] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - waiting for server to start....2018-02-08 22:34:50.401 IST [9468] LOG:  listening on IPv6 address "::1", port 53255
22:34:50.402 [output redirector for java.lang.ProcessImpl@26be92ad] ERROR com.opentable.db.postgres.embedded.EmbeddedPostgres - while reading output
java.io.IOException: Stream closed
	at java.io.BufferedReader.ensureOpen(BufferedReader.java:122)
	at java.io.BufferedReader.readLine(BufferedReader.java:317)
	at java.io.BufferedReader.readLine(BufferedReader.java:389)
	at com.opentable.db.postgres.embedded.ProcessOutputLogger.run(ProcessOutputLogger.java:48)
	at java.lang.Thread.run(Thread.java:748)
22:34:50.931 [main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - 375b9973-cb6f-4851-ba5a-b9b2690ee619 postmaster startup finished in 00:00:00.846
22:34:51.605 [main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - 375b9973-cb6f-4851-ba5a-b9b2690ee619 shut down postmaster in 00:00:00.586

Though looking at the logs it seems the server did start and stop gracefully but why do i see this exception ?

Precaching extracted binary postgres distribution

It would be nice (for performance reasons) to allow to precache extracted binary postgres distribution.
Seems like at the moment created database (data dir) can be left untouched and not cleaned up (for diagnosing and performance purpose), but postgres binary archive is extracted each time EmbeddedPostgres is started. Having it to omit to delete the directory with extracted postgres on exit would speed up subsequent runs - especially handy would be on CI server

Maven central appears to be missing binary artifacts.

Hi all,
I'm attempting to use this project, but whilst mvn central has entries for the latest version

        <dependency>
            <groupId>com.opentable.components</groupId>
            <artifactId>otj-pg-embedded</artifactId>
            <version>0.11.1</version>
        </dependency>

it appears to be missing any jar content since version 0.4.0, and consequently (for me at least) doesn't work.

is this intentional? am I missing something?
seems strange nobody else has noticed.

thanks.

Build for Java 7

Thanks for getting this updated! We're not quite ready to update to Java 8. Any chance of building this for Java 7? If not, no big deal, I can fork it.

ProcessOutputLogger does not work after server is started

When I start postgres the following log is redirected by ProcessOutputLogger
LOG: listening on IPv6 address "::1", port 59561 LOG: listening on IPv4 address "127.0.0.1", port 59561 LOG: database system was shut down at 2018-05-14 18:55:20 MSK LOG: database system is ready to accept connections ������

But futher logs from server are not printed.

E.g. we run the following command
select 1 from not_existing_table
Postgres generates the following error
ERROR: relation "not_existing_table" does not exist at character 15
But this error is not redirected by ProcessOutputLogger.

I suppose this condition teminates ProcessOutputLogger thread too early
while (process.isAlive())

Error message is not always given out when stopping the EmbeddedPostgress process fails

Hi,

We are having a somewhat random issue with stopping the EmbeddedPostgres instance upon the shutdown hooks being run with v0.12.0.

The error looks as follows:

-2019-01-11 10:42:05.953 -ERROR �[35m24261�[0;39m --- [36607f15-closer] [MDC: ] �[36mc.o.d.p.embedded.EmbeddedPostgres       �[0;39m : Could not stop postmaster 49614da6-fe92-4eb3-8f8a-510836607f15
-java.lang.IllegalStateException: Process [/tmp/embedded-pg-jenkins/PG-6e6cb600c5af6f0b241f84df1594a9c6/bin/pg_ctl, -D, /tmp/embedded-pg-jenkins/data/MEszVDSZVyoxehlM, stop, -m, fast, -t, 5, -w] failed

    at com.opentable.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:585)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres.pgCtl(EmbeddedPostgres.java:411)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres.close(EmbeddedPostgres.java:384)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres$1.run(EmbeddedPostgres.java:364)
    at java.lang.Thread.run(Thread.java:748)

It seems that for whatever reason, the pg_ctl stop command did not execute correctly. However, there is no output as to why that could be (stdout seems to be empty!).

I debugged the problem a bit and found that in EmbeddedPostgres#system:585 (link to v0.12.0) an IllegalStateException is thrown where the error stream should also be output IOUtils.toString(process.getErrorStream()).

However, upon forcing an error (by killing the postgres process manually before process.start() is invoked), I saw the following behaviour:

  1. IOUtils.toString(process.getErrorStream()) is empty.

  2. IOUtils.toString(process.getInputStream()) contains:

     pg_ctl: PID file "/tmp/embedded-pg-jenkins/data/CFEPcYcPWgvwnfqu/postmaster.pid" does not exist
     Is server running?
    

Which is the same behaviour that we saw in our CI logs. We do not redirect stderr to stdout during the build. Obviously, there could be any number of reasons why pg_ctl stop could fail (and none of the ones I have though seem to have been the case at the time, e.g. insufficient space, OS issue that would appear in dmesg/syslog, etc.).

It would be really nice if all the values of the pg_ctl stop command execution were output in the exception instead of only the (weirdly empty) stderr, for better debugging of odd cases like this since it does seem to be an OS-level issue and not an application issue. Additionally, IMO, it may be useful for the EmbeddedPostgres instance to have a reference to the actual Process of the postgres instance, but this might be out of scope for this issue.

If you'd like, I would be more than happy to create a PR for this change. Please let me know if anything in the above analysis is incorrect, too.

overriding locale settings not working

Hi,

I am using this lib in a project which is operated across different geographies. The locale settings picked up by the lib is OS default. Few of my team members sit in Poland and they have set the OS locale to "Polish" language. We have our tests written where we assert the error messages coming from postgres. The assertions are written in english like:

assertThat(ex.errorMessage(), containsString("Unique constraint violation"));

this assertion fails on their machine because the error message in polish language. I have tried overriding the default OS locale settings from this lib like:

            EmbeddedPostgres.builder()
                    .setLocaleConfig("LANGUAGE", "en_US.UTF-8")
                    .setLocaleConfig("LC_ALL", "en_US.UTF-8")
                    .start();

but it fails to start without giving any explicit exception. Can you please confirm if i am using it in correct way?

Thanks
Vikesh

Get "This ResultSet is closed" on connection.getTransactionIsolation()

I use embedded postgres under MacOS High Sierra

<dependency> <groupId>com.opentable.components</groupId> <artifactId>otj-pg-embedded</artifactId> <version>0.11.0</version> <scope>test</scope> </dependency>

Everything works OK until I want to get getTransactionIsolation then I receive such exception:
`
org.postgresql.util.PSQLException: This ResultSet is closed.

at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(AbstractJdbc2ResultSet.java:2654)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.setFetchSize(AbstractJdbc2ResultSet.java:1771)
at org.postgresql.jdbc4.Jdbc4Statement.createResultSet(Jdbc4Statement.java:39)
at org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler.handleResultRows(AbstractJdbc2Statement.java:211)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1773)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
at org.postgresql.jdbc2.AbstractJdbc2Connection.execSQLUpdate(AbstractJdbc2Connection.java:263)
at org.postgresql.jdbc2.AbstractJdbc2Connection.getTransactionIsolation(AbstractJdbc2Connection.java:775)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
at com.sun.proxy.$Proxy86.getTransactionIsolation(Unknown Source)
at com.elanceodesk.workplace.oauthplugins.oauthclients.db.GoogleTokenDAOITItem.testAAA(GoogleTokenDAOITItem.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

`

Tiny version of otj-pg-embedded

I think it could be useful having a "tiny artifact" that contains just the classes, leaving out the PG binaries.
What do you think?

Trying to connect before DB is ready

Hi there:

Would there be a way to delay the attempt to connect to the DB? I debugged a bit, and it looks like the connection is just being attempted too fast. Thanks!

Whenever I try to connect, I get something like the following:
May 23, 2018 3:10:45 PM org.postgresql.Driver connect
SEVERE: Connection error:
org.postgresql.util.PSQLException: Connection to localhost:61589 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:265)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:431)
at org.postgresql.Driver.connect(Driver.java:247)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:79)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:64)

Illegal State issue from initdb

Hi, I'm attempting to use otj-pg-embedded-0.11.0 (as downloaded from the maven repository) on a windows 10 system and I am getting the following when I attempt a simple junit test:

java.lang.IllegalStateException: Process [C:\Users\john\AppData\Local\Temp\embedded-pg\PG-20610842f7206a9abbecdcf12709c0f8\bin\initdb.exe, -A, trust, -U, postgres, -D, C:\Users\john\AppData\Local\Temp\epg3467157523703904606, -E, UTF-8] failed

at com.opentable.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:558)
at com.opentable.db.postgres.embedded.EmbeddedPostgres.initdb(EmbeddedPostgres.java:223)
at com.opentable.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:141)
at com.opentable.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:545)
at com.opentable.db.postgres.embedded.EmbeddedPostgres.start(EmbeddedPostgres.java:445)
at com.opentable.db.postgres.junit.SingleInstancePostgresRule.before(SingleInstancePostgresRule.java:35)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:41)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

The unit test is copied from from your test:

package com.billerica.manager.database;

import com.opentable.db.postgres.junit.EmbeddedPostgresRules;
import com.opentable.db.postgres.junit.SingleInstancePostgresRule;
import org.junit.Rule;
import org.junit.Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import static org.junit.Assert.*;

public class testSingleInstanceEmbeddedPg {

@Rule
public SingleInstancePostgresRule epg = EmbeddedPostgresRules.singleInstance();

@Test
public void testSingleInstance() throws Exception {
    try (Connection c = epg.getEmbeddedPostgres().getPostgresDatabase().getConnection()) {
        assertNotNull(epg);
        Statement s = c.createStatement();
        ResultSet rs = s.executeQuery("SELECT 1");
        assertTrue(rs.next());
        assertEquals(1, rs.getInt(1));
        assertFalse(rs.next());
    }
}

}

I see that the temp folder epg3467157523703904606 is empty, if that says anything. I haven't found any log files in the temporary folders.

Other tests give similar results. Sorry if I have missed something obvious; I haven't done any other configuration or setup.

Thanks for any help you can provide.

How to hide log messages?

Hi,

I have a logback.xml as well as a log4j.properties with logging set to OFF, but I still have messages such as these:

Success. You can now start the database server using:

    /tmp/embedded-pg/PG-11dcc08f73460f51bbcf948559611bae/bin/pg_ctl -D /tmp/embedded-pg/6de10060-d1c7-496a-9cce-aa868015ed4f -l logfile start

server starting
LOG:  database system was shut down at 2017-07-07 17:03:46 CEST
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

How to hide them?

Thanks!

Could not find artifact org.springframework.boot:spring-boot-dependencies:pom:2.0.0.M7

Version 0.11.2 seems to have an unresolvable dependency. Using this in my pom.xml

    <dependency>
        <groupId>com.opentable.components</groupId>
        <artifactId>otj-pg-embedded</artifactId>
        <version>0.11.2</version>
        <scope>test</scope>
    </dependency>

fails with

Could not resolve dependencies for project de.lhorn:playground:jar:1.0-SNAPSHOT: Failed to collect dependencies at com.opentable.components:otj-pg-embedded:jar:0.11.2: Failed to read artifact descriptor for com.opentable.components:otj-pg-embedded:jar:0.11.2: Could not find artifact org.springframework.boot:spring-boot-dependencies:pom:2.0.0.M7 in central (https://repo.maven.apache.org/maven2)

I don't see any explicit dependency on spring boot, especially not a milestone M7.

Could the dependencies please be made resolvable?

What are the default access ?

Hello and first of all thank you for this great library. It seems it will avoid me a lot of pain !

However I have a question regarding the creditentials. I would like to connect to this db from my test with JPA.
So I would need:
host = "localhost"
username = "postgres"
password = ""
port = 9999

EmbeddedPostgres.builder().setPort(POSTGRES_PORT).start()

I guess it should work like that right ?

Failed to run on Windows 2012

When trying to start EmbeddedPostgres on TeamCity agent with Windows 2012, I receive :

com.google.common.base.VerifyException: Process [Z:\buildAgent\temp\buildTmp\embedded-pg\PG-01856e144a4b170a72702240e1e507fe\bin\initdb.exe, -A, trust, -U, postgres, -D, Z:\buildAgent\temp\buildTmp\embedded-pg\5bbbd7d5-cacb-41fc-baed-5561fa0dce06, -E, UTF-8] failed

    at com.google.common.base.Verify.verify(Verify.java:123)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:509)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres.initdb(EmbeddedPostgres.java:208)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:130)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:493)

Log entries before exception

[:test] initdb: could not change permissions of directory "Z:/buildAgent/temp/buildTmp/embedded-pg/e290f582-e4af-406e-a757-d0d8d6153c0c": Permission denied
[21:28:23][:test] The database cluster will be initialized with locale "English_United States.1252".
[21:28:23][:test] The default text search configuration will be set to "english".
[21:28:23][:test] Data page checksums are disabled.
[21:28:23][:test] fixing permissions on existing directory Z:/buildAgent/temp/buildTmp/embedded-pg/e290f582-e4af-406e-a757-d0d8d6153c0c ... 

Problem with not closing/killing postgreSQL instances

Hello,

I have problem using Embedded PostgreSQL in my application.
I am using your library to integration tests. During the execution I have error in logs that old instance/temp folder from previous run is unable to delete.
This is usually when I create DataSource bean from embedded Postgres Data
I am using Win10, Java 8

	@Bean
	public DataSource embeddedDataSource()  {
		final DataSource dataSource;
		try {
			dataSource = EmbeddedPostgres
					.builder()
					.setPgBinaryResolver(new ClasspathBinaryResolver())
					.setPort(port)
					.start().getTemplateDatabase();
			return dataSource;
		} catch (IOException e) {
			LOGGER.error("Unable to setup embedded Postgresql server {}", e.getMessage());
			throw new RuntimeException("Failed to setup Embedded Postgresql server");
		}
	}

This caused an entry in the logs like :

07-11-2017 11:05:33.424 [localhost-startStop-1] INFO  c.o.d.p.embedded.EmbeddedPostgres.cleanOldDataDirectories - Found stale data directory C:\Users\KTelka\AppData\Local\Temp\embedded-pg\ba0c377f-3a7e-431d-88a5-44bf88494c88
07-11-2017 11:05:36.541 [localhost-startStop-1] WARN  c.o.d.p.embedded.EmbeddedPostgres.cleanOldDataDirectories - While cleaning old data directories
java.io.IOException: Unable to delete file: C:\Users\KTelka\AppData\Local\Temp\embedded-pg\ba0c377f-3a7e-431d-88a5-44bf88494c88\epg-lock
	at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:2381)
	at org.apache.commons.io.FileUtils.cleanDirectory(FileUtils.java:1679)
	at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1575)
	at com.opentable.db.postgres.embedded.EmbeddedPostgres.cleanOldDataDirectories(EmbeddedPostgres.java:344)
	at com.opentable.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:110)
	at com.opentable.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:421)
	at com.harman.ndscompiler.restserver.it.config.IntegrationTestConfiguration.embeddedDataSource(IntegrationTestConfiguration.java:48)

Also sometimes it displays me an error that orphaned instance found and then library tires to kill that process.

Do you have any ideas how to avoid this ?

Unable to run on Windows

When starting up the server receive

java.lang.RuntimeException: java.io.IOException: Cannot run program "uname": CreateProcess error=2, The system cannot find the file specified at com.google.common.base.Throwables.propagate(Throwables.java:160) at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL.system(EmbeddedPostgreSQL.java:433) at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL.prepareBinaries(EmbeddedPostgreSQL.java:453) at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL.<init>(EmbeddedPostgreSQL.java:97) at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL$Builder.start(EmbeddedPostgreSQL.java:418) at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL$Builder$start$2.call(Unknown Source)

This is because "uname" does not exist on Windows. When I run it under MinGW it is unable to delete the temp files:

Caused by: java.lang.IllegalStateException: could not delete C:\Users\<user>\AppData\Local\Temp\pgpg5803195040675452262pgpg at com.google.common.base.Preconditions.checkState(Preconditions.java:197) at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL.prepareBinaries(EmbeddedPostgreSQL.java:510) at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL.<init>(EmbeddedPostgreSQL.java:97) at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL$Builder.start(EmbeddedPostgreSQL.java:418)

Where to get pull 31?

I was hoping to be able to make use of the improvement in #31, but I couldn't find a release in maven with that fix in it. Can someone point me to the right place? Thanks!

getting postgres statemetn logging

I'm not sure what I am doing wrong, but I'm trying to log SQL statements to stderr so I can see them during testing. However, nothing seems to work.

This is what I have:

            pg = EmbeddedPostgres
                    .builder()
                    .setServerConfig( "log-connections", "true" )
                    .setServerConfig( "log-statement", "all" )
                    .setServerConfig( "log_min_duration_statement", "0" )
                    .setServerConfig( "log_destination", "stderr" )
                    .setServerConfig( "logging_collector", "on" )
                    .start()

Failed with Java 32bit...

Seems that also failed with 32bit Java...
I get:
Caused by: java.lang.IllegalStateException: No Postgres binary found for Windows / x86.
Possible add support for 32bit Java? Thanks.

Failure running in Docker dind

I wrote a GitLab pipeline to run Maven JUnit test using Embedded Postgres.
On my host no problems, it works like a charm.
In the pipeline instead the following error is thrown:

The DIND image is the official one and uses Alpine.
My host is an Ubunut 17.10 distribution.


T E S T S

Running it.cdp.galileo.galgar.jpa.GaranziaJpaTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 0.971 sec <<< FAILURE! - in it.cdp.galileo.galgar.jpa.GaranziaJpaTest
testOperazioneUpdate(it.cdp.galileo.galgar.jpa.GaranziaJpaTest) Time elapsed: 0.326 sec <<< ERROR!
com.google.common.base.VerifyException:
Process [/tmp/embedded-pg/PG-924739a3db254612413e7be5f025c166/bin/initdb, -A, trust, -U, >postgres, -D, /tmp/embedded-pg/5c1238a4-e398-43f1-a34e-2b71b9874be2, -E, UTF-8] failed

Unable to run with 32-bit JDK

Trying to start instantiate on a 32 bit JDK produces the following error (on Windows 10):

14:26:19.068 [main] INFO com.opentable.db.postgres.embedded.EmbeddedPostgres - Detected a Windows x86 system
java.lang.NullPointerException
    at java.security.DigestInputStream.read(DigestInputStream.java:161)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1792)
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1769)
    at org.apache.commons.io.IOUtils.copy(IOUtils.java:1744)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres.prepareBinaries(EmbeddedPostgres.java:548)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:106)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:421)
    at com.opentable.db.postgres.embedded.EmbeddedPostgres.start(EmbeddedPostgres.java:363)
    at com.opentable.db.postgres.junit.SingleInstancePostgresRule.before(SingleInstancePostgresRule.java:37)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
    Suppressed: java.lang.NullPointerException
        at java.io.FilterInputStream.close(FilterInputStream.java:181)
        at com.opentable.db.postgres.embedded.EmbeddedPostgres.prepareBinaries(EmbeddedPostgres.java:586)
        ... 17 more

It's because it tries to find a file called postgresql-Windows-x86.txz, which doesn't exist. I'd like to see a more explicit message about 32-bit not being supported, if that's the intention.

Downgrade to 1.7

No reason to use 1.8, project successfully compiles with 1.7. Can you downgrade required version in pom.xml for next release?

Extracting tar doesn't work on ubuntu 14.04

tar: Ignoring unknown extended header keyword 'SCHILY.ino'
tar: Ignoring unknown extended header keyword 'SCHILY.nlink'
tar: Ignoring unknown extended header keyword 'SCHILY.dev'
tar: Ignoring unknown extended header keyword 'SCHILY.ino'
tar: Ignoring unknown extended header keyword 'SCHILY.nlink'
tar: Ignoring unknown extended header keyword 'SCHILY.dev'
tar: Ignoring unknown extended header keyword 'SCHILY.ino'
tar: 
    at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL.system(EmbeddedPostgreSQL.java:418)
    at com.opentable.db.postgres.embedded.EmbeddedPostgreSQL.<clinit>(EmbeddedPostgreSQL.java:470)

suppose that this is because of
http://lifeonubuntu.com/tar-errors-ignoring-unknown-extended-header-keyword/

Using version 0.4.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.