postgresql-embedded icon indicating copy to clipboard operation
postgresql-embedded copied to clipboard

Postgres does not start on OS X 10.11

Open tamasujj opened this issue 8 years ago • 10 comments

I'm using version 1.15 and I get the following error when I try to start embedded Postgres:

16/09/10 00:01:38 INFO Executable: start AbstractPostgresConfig{storage=Storage{dbDir=/var/folders/ds/qdbhlt795_s_ljp96lk0tr580000gp/T/postgresql-embed-609858de-b9f5-4992-918b-14fa031c77a7/db-content-a601dfa2-2edc-4cc6-b039-80dc4a5b5eee, dbName='teszt', isTmpDir=true}, network=Net{host='127.0.1.1', port=37700}, timeout=Timeout{startupTimeout=15000}, credentials=Credentials{username='local', password='local'}, args=[], additionalInitDbParams=[]}
Sep 10, 2016 12:01:59 AM ru.yandex.qatools.embed.postgresql.PostgresProcess onAfterProcessStart
SEVERE: Failed to read PID file (File '/var/folders/ds/qdbhlt795_s_ljp96lk0tr580000gp/T/postgresql-embed-609858de-b9f5-4992-918b-14fa031c77a7/db-content-a601dfa2-2edc-4cc6-b039-80dc4a5b5eee/postmaster.pid' does not exist)

I am able to start it from the terminal after I extract the binaries.

tamasujj avatar Sep 09 '16 22:09 tamasujj

@tamasujj Credentials{username='local', password='local'} is in the log.

Did you specify username and password? Connection db = DriverManager.getConnection(url, username, password);

guanzhou-zhao avatar Oct 15 '16 00:10 guanzhou-zhao

@guanzhou-zhao Yes I did, local/local is correct.

The error occurs at startup before I have the chance to connect to the database.

val runtime = PostgresStarter.getDefaultInstance
val config = new PostgresConfig(
    Version.V9_5_0,
    new Net("127.0.1.1", 37700),
    new Storage("teszt"),
    new Timeout(),
    new Credentials("local", "local")
)
val exec = runtime.prepare(config)
val process: PostgresProcess = exec.start()

tamasujj avatar Oct 17 '16 22:10 tamasujj

@tamasujj Your config looks far more advanced. For me I just used the example in README as below, and it works.

    String databaseName = "dbname";
    String userName = "username";
    String password = "password";

    // start Postgres service
    final PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getDefaultInstance();
    final PostgresConfig config = PostgresConfig.defaultWithDbName(databaseName, userName, password);
    PostgresExecutable exec = runtime.prepare(config);
    process = exec.start();

   // connecting to a running Postgres
    String url = String.format("jdbc:postgresql://%s:%s/%s",
            config.net().host(),
            config.net().port(),
            config.storage().dbName()
    );
    connection = getConnection(url, userName, password);

guanzhou-zhao avatar Oct 17 '16 22:10 guanzhou-zhao

I had similar issue. Eventually I understood that I did not call postgres.stop(). I needed to manually kill the hanging process occupied my port, added the stop() call to pre destroy callback and seems like it started to work.

However this is a question - what is done to make sure that the tool doesn't leave hanging processes in OS.

karayv avatar Oct 20 '17 19:10 karayv

@karayv if you're asking how we make sure that a process is killed once the Java process has exited, there is a shutdown hook, registered in embed-process library.

However, in the later versions it does not work by default (as we're running process not in "daemon mode" by default). You can turn this on by passing daemonProcess(true) to runtime config.

smecsia avatar Oct 24 '17 03:10 smecsia

Can deamonProcess be a property to change, instead of building whole process configuration by yourself ?

mnorkin avatar Dec 28 '17 11:12 mnorkin

@karayv makes a good point. You’ll want to make sure once your application has shut down your Postgres process has also stopped. I encountered the problem related to multiple Postgres processes running. That was partly because they weren’t stopped and partly—since I’m running in a Spring Boot context—because the Spring application was run twice and thus started Postgres twice.

So, I’m pretty confident this has something to do with colliding Postgres processes.

Zemke avatar Jan 28 '18 13:01 Zemke

Have same problem with macos sierra, I am able to start it from the terminal after I extract the binaries. How to check if there is hanging process, which port ? name ?

x-hovo-x avatar Feb 06 '18 20:02 x-hovo-x

Any update on this? I still have this problem and couldn't figure out what's wrong with it.

ngocketit avatar Nov 08 '18 15:11 ngocketit

Nvm. I figured it out. It's because localhost is missing in /etc/hosts. So I added: 127.0.0.1 localhost and it works.

ngocketit avatar Nov 08 '18 15:11 ngocketit