You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to start Postgres.app and PostgreSQL from a bash script? #832
This is a fairly banal question. I want to start Postgres.app und PostgreSQL from a bash script.
I can start the app easily via open /Applications/Postgres.app. But that does not start PostgreSQL. What is the scripting equivalent of selecting a PostgreSQL version and clicking the Start button in the user interface? What would be the equivalent of Stop?
Unfortunately Postgres.app doesn't have any scripting support to start and stop servers.
The easiest workaround would be to activate the "start on launch" checkbox in the server settings -- then Postgres.app would start the server automatically when you open the app.
Manually starting servers from the command line
It is possible to start the server from the command line directly, but then you will lose some features.
Most importantly, the permission dialog for trust authentication only works when you use Postgres.app to start the server. Therefore we recommend to disable trust authentication when you manually start the server (see Protecting PostgreSQL with a password).
Support for downloaded extensions (PG 18 or later) will also break if you manually start the server.
Postgres.app also does a few additional things before starting the server (eg. check that the port is available, check if the binaries have moved to a different location, check if there is a stale postmaster.pid file that needs to be deleted, etc.). But those are not strictly necessary.
The code that actually starts the server is in Server.swift in a method named startSync()
Postgres.app uses the pg_ctl program to start the server.
Here's an example what that command would look like:
Activity
jakob commentedon Nov 5, 2025
Unfortunately Postgres.app doesn't have any scripting support to start and stop servers.
The easiest workaround would be to activate the "start on launch" checkbox in the server settings -- then Postgres.app would start the server automatically when you open the app.
Manually starting servers from the command line
It is possible to start the server from the command line directly, but then you will lose some features.
Most importantly, the permission dialog for trust authentication only works when you use Postgres.app to start the server. Therefore we recommend to disable trust authentication when you manually start the server (see Protecting PostgreSQL with a password).
Support for downloaded extensions (PG 18 or later) will also break if you manually start the server.
Postgres.app also does a few additional things before starting the server (eg. check that the port is available, check if the binaries have moved to a different location, check if there is a stale postmaster.pid file that needs to be deleted, etc.). But those are not strictly necessary.
The code that actually starts the server is in Server.swift in a method named
startSync()Postgres.app uses the
pg_ctlprogram to start the server.Here's an example what that command would look like:
/Applications/Postgres.app/Contents/Versions/18/pg_ctl start \ -D "/Users/xxx/Library/Application Support/var-18" \ -w \ -l "/Users/xxx/Library/Application Support/var-18/postgresql.log" \ -o "-p 5432"-Dis the data directory-wtells pg_ctl waits until the server is started-lis the file name of the server log file5432is the port you configured the server to run on/Applications/Postgres.app/Contents/Versions/18according to your PostgreSQL version and location of Postgres.appTo stop the server you could use a command like:
/Applications/Postgres.app/Contents/Versions/18/pg_ctl stop \ -D "/Users/xxx/Library/Application Support/var-18" \ -wMW3000 commentedon Nov 5, 2025
Thank you, @jakob for the extensive explanation 🙏
For my use-case, the
Server Settings > Automatically start serveroption is enough ✅ I was not aware of that setting.Still it is interesting to learn about
pg_ctl.