postgresql-embedded
postgresql-embedded copied to clipboard
Postgres does not start on OS X 10.11
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
Credentials{username='local', password='local'}
is in the log.
Did you specify username and password?
Connection db = DriverManager.getConnection(url, username, password);
@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 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);
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 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.
Can deamonProcess
be a property to change, instead of building whole process configuration by yourself ?
@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.
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 ?
Any update on this? I still have this problem and couldn't figure out what's wrong with it.
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.