Skip to content

How to start Postgres.app and PostgreSQL from a bash script? #832

Closed

Description

@MW3000

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?

Activity

  1. jakob commented on Nov 5, 2025

    @jakob
    Member

    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:

    /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"
    • -D is the data directory
    • -w tells pg_ctl waits until the server is started
    • -l is the file name of the server log file
    • 5432 is the port you configured the server to run on
    • adjust the path /Applications/Postgres.app/Contents/Versions/18 according to your PostgreSQL version and location of Postgres.app

    To 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" \
        -w
  2. MW3000 commented on Nov 5, 2025

    @MW3000
    Author

    Thank you, @jakob for the extensive explanation 🙏

    For my use-case, the Server Settings > Automatically start server option is enough ✅ I was not aware of that setting.

    Still it is interesting to learn about pg_ctl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions