Skip to content

Instantly share code, notes, and snippets.

@tangoabcdelta
Last active January 20, 2021 21:12
Show Gist options
  • Save tangoabcdelta/4272d9c8ae328632645e1efd228b62ba to your computer and use it in GitHub Desktop.
Save tangoabcdelta/4272d9c8ae328632645e1efd228b62ba to your computer and use it in GitHub Desktop.
How to do this do, that etcetera
How to start / stop PostgreSQL from autostarting during start up - macOS
Disable/Enable PostgreSQL Autostart on Mac OS X Lion
  • save the following xml content in a com.edb.launchd.postgresql-9.1.plist
  • dump it in the correct directory
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
        <key>Label</key>
        <string>com.edb.launchd.postgresql-9.1</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Library/PostgreSQL/9.1/bin/postmaster</string>
                <string>-D/Library/PostgreSQL/9.1/data</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    <key>UserName</key>
    <string>postgres</string>
    <key>KeepAlive</key>
    <dict>
         <key>SuccessfulExit</key>
         <false/>
    </dict>
</dict>
</plist>
Stop PostgreSQL from auto starting in Mac OS X 10.7.x (Lion)

sudo launchctl unload -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.1.plist

Enable PostgreSQL to auto start in Mac OS X 10.7.x (Lion)

sudo launchctl load -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.1.plist

Manually Start PostgreSQL
# su as user "postgres" and run server: 
cd /Library/PostgreSQL/9.1/bin/

./pg_ctl -D /Library/PostgreSQL/9.1/data/ start

# Note:
# - Without "sudo" the commands seem to run successfully but don't take effect
# - Contents of com.edb.launchd.postgresql-9.1.plist in attached file (Permission MUST be: -rw-r--r--  1 root  wheel)
Manually Stop PostgreSQL
# su as user "postgres" and run server:

cd /Library/PostgreSQL/9.1/bin/
./pg_ctl -D /Library/PostgreSQL/9.1/data/ stop

# Note:
# - Without "sudo" the commands seem to run successfully but don't take effect
# - Contents of com.edb.launchd.postgresql-9.1.plist in attached file (Permission MUST be: -rw-r--r--  1 root  wheel)
How to stop PostgreSQL / postgres from autostarting during start up - Linux

(works on ubuntu 16.04 or later which use systemd)

  • start - sudo service postgresql start
  • stop - sudo service postgresql stop
  • restart - sudo service postgresql restart
  • auto launch - sudo systemctl enable postgresql
  • disable auto launch - sudo systemctl disable postgresql
Install PostgreSQL 10.4
sudo apt-get update
sudo apt-get install postgresql-10.4
# By default, the postgres user has no password and can hence only connect if ran by the postgres system user. The following command will assign it:
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo -u postgres psql -c "CREATE DATABASE testdb;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment