Skip to content

Support for Homebrew Postgres on MacOS #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

Support for Homebrew Postgres on MacOS #179

wants to merge 5 commits into from

Conversation

noelmcloughlin
Copy link
Contributor

This PR introduces support for the HomeBrew Postgresql package on MacOS, and some fixes/improvements for 'PostgresApp' package on MacOS.

The tested baseline included #176, #177, #178 so hopefully those commits are merged first.

** top_state **

base:
  '*':
    - postgres

** Pillars **

postgres:
{% if grains.os == 'MacOS' %}

  # Set to 'postgresapp' (default) or 'homebrew' for MacOS package
  use_upstream_repo: 'homebrew'

{% else %}
  # Set False to use distro packaged postgresql.
  # Set True to use upstream postgresql.org repo for YUM/APT/ZYPP
  use_upstream_repo: False

  # Upstream version
  version: '9.6'

  # Additional packages to install with PostgreSQL server,
  # this should be in a list format and correctly named.
  pkgs_extra:
  - postgresql-contrib
  - postgresql-plpython

  # PostgreSQL service name
  service: postgresql

  # These are Debian/Ubuntu specific package names
  pkg: 'postgresql-9.6'
  pkg_client: 'postgresql-client-9.6'

  #Debian alternatives priority incremental. 0 disables feature.
  linux:
    altpriority: 30
{% endif %}

.... rest identical to pillar.example ...

** State results ***

[ERROR   ] Service homebrew.mxcl.postgresql failed to start
local:
----------
          ID: postgresql-server
    Function: pkg.installed
      Result: True
     Comment: The following packages were installed/updated: postgresql
     Started: 13:13:12.225375
    Duration: 6148.853 ms
     Changes:   
              ----------
              postgresql:
                  ----------
                  new:
                      10.1
                  old:
----------
          ID: postgresql-server
    Function: file.managed
        Name: /Library/LaunchAgents/homebrew.mxcl.postgresql.plist
      Result: True
     Comment: File /Library/LaunchAgents/homebrew.mxcl.postgresql.plist updated
     Started: 13:13:13.378074
    Duration: 13.146 ms
     Changes:   
              ----------
              diff:
                  New file
              mode:
                  0644
----------
          ID: postgresql-cluster-prepared
    Function: cmd.run
        Name: initdb -D /Users/messi/Library/AppSupport/postgres_homebrew
      Result: True
     Comment: Command "initdb -D /Users/messi/Library/AppSupport/postgres_homebrew" run
     Started: 13:13:13.392806
    Duration: 801.939 ms
     Changes:   
              ----------
              pid:
                  30633
              retcode:
                  0
              stderr:
                  
                  WARNING: enabling "trust" authentication for local connections
                  You can change this by editing pg_hba.conf or using the option -A, or
                  --auth-local and --auth-host, the next time you run initdb.
              stdout:
                  The files belonging to this database system will be owned by user "messi".
                  This user must also own the server process.
                  
                  The database cluster will be initialized with locale "C".
                  The default database encoding has accordingly been set to "SQL_ASCII".
                  The default text search configuration will be set to "english".
                  
                  Data page checksums are disabled.
                  
                  creating directory /Users/messi/Library/AppSupport/postgres_homebrew ... ok
                  creating subdirectories ... ok
                  selecting default max_connections ... 100
                  selecting default shared_buffers ... 128MB
                  selecting dynamic shared memory implementation ... posix
                  creating configuration files ... ok
                  running bootstrap script ... ok
                  performing post-bootstrap initialization ... ok
                  syncing data to disk ... ok
                  
                  Success. You can now start the database server using:
                  
                      pg_ctl -D /Users/messi/Library/AppSupport/postgres_homebrew -l logfile start
----------
          ID: postgresql-config-dir
    Function: file.directory
        Name: /Users/messi/Library/AppSupport/postgres_homebrew
      Result: True
     Comment: Directory /Users/messi/Library/AppSupport/postgres_homebrew updated
     Started: 13:13:19.195268
    Duration: 219.31 ms
     Changes:   
              ----------
              mode:
                  0775
----------
          ID: postgresql-conf
    Function: file.blockreplace
        Name: /Users/messi/Library/AppSupport/postgres_homebrew/postgresql.conf
      Result: True
     Comment: Changes were made
     Started: 13:13:19.414895
    Duration: 4.529 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -656,3 +656,6 @@
                   #------------------------------------------------------------------------------
                   
                   # Add settings for extensions here
                  +# Managed by SaltStack: listen_addresses: please do not edit
                  +listen_addresses = '*'  # listen on all interfaces
                  +# Managed by SaltStack: end of salt managed zone --
----------
          ID: postgresql-pg_hba
    Function: file.managed
        Name: /Users/messi/Library/AppSupport/postgres_homebrew/pg_hba.conf
      Result: True
     Comment: File /Users/messi/Library/AppSupport/postgres_homebrew/pg_hba.conf updated
     Started: 13:13:19.419582
    Duration: 3792.969 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -1,93 +1,23 @@
                  +######################################################################
                  +# ATTENTION! Managed by SaltStack.                                   #
                  +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN! #
                  +######################################################################
                  +#
                   # PostgreSQL Client Authentication Configuration File
                   # ===================================================
                   #
                   # Refer to the "Client Authentication" section in the PostgreSQL
                  -# documentation for a complete description of this file.  A short
                  -# synopsis follows.
                  -#
                  -# This file controls: which hosts are allowed to connect, how clients
                  -# are authenticated, which PostgreSQL user names they can use, which
                  -# databases they can access.  Records take one of these forms:
                  -#
                  -# local      DATABASE  USER  METHOD  [OPTIONS]
                  -# host       DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
                  -# hostssl    DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
                  -# hostnossl  DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
                  -#
                  -# (The uppercase items must be replaced by actual values.)
                  -#
                  -# The first field is the connection type: "local" is a Unix-domain
                  -# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
                  -# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
                  -# plain TCP/IP socket.
                  -#
                  -# DATABASE can be "all", "sameuser", "samerole", "replication", a
                  -# database name, or a comma-separated list thereof. The "all"
                  -# keyword does not match "replication". Access to replication
                  -# must be enabled in a separate record (see example below).
                  -#
                  -# USER can be "all", a user name, a group name prefixed with "+", or a
                  -# comma-separated list thereof.  In both the DATABASE and USER fields
                  -# you can also write a file name prefixed with "@" to include names
                  -# from a separate file.
                  -#
                  -# ADDRESS specifies the set of hosts the record matches.  It can be a
                  -# host name, or it is made up of an IP address and a CIDR mask that is
                  -# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
                  -# specifies the number of significant bits in the mask.  A host name
                  -# that starts with a dot (.) matches a suffix of the actual host name.
                  -# Alternatively, you can write an IP address and netmask in separate
                  -# columns to specify the set of hosts.  Instead of a CIDR-address, you
                  -# can write "samehost" to match any of the server's own IP addresses,
                  -# or "samenet" to match any address in any subnet that the server is
                  -# directly connected to.
                  -#
                  -# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
                  -# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
                  -# Note that "password" sends passwords in clear text; "md5" or
                  -# "scram-sha-256" are preferred since they send encrypted passwords.
                  -#
                  -# OPTIONS are a set of options for the authentication in the format
                  -# NAME=VALUE.  The available options depend on the different
                  -# authentication methods -- refer to the "Client Authentication"
                  -# section in the documentation for a list of which options are
                  -# available for which authentication methods.
                  -#
                  -# Database and user names containing spaces, commas, quotes and other
                  -# special characters must be quoted.  Quoting one of the keywords
                  -# "all", "sameuser", "samerole" or "replication" makes the name lose
                  -# its special character, and just match a database or username with
                  -# that name.
                  -#
                  -# This file is read on server startup and when the server receives a
                  -# SIGHUP signal.  If you edit the file on a running system, you have to
                  -# SIGHUP the server for the changes to take effect, run "pg_ctl reload",
                  -# or execute "SELECT pg_reload_conf()".
                  -#
                  -# Put your actual configuration here
                  -# ----------------------------------
                  -#
                  -# If you want to allow non-local connections, you need to add more
                  -# "host" records.  In that case you will also need to make PostgreSQL
                  -# listen on a non-local interface via the listen_addresses
                  -# configuration parameter, or via the -i or -h command line switches.
                  +# documentation for a complete description of this file.
                   
                  -# CAUTION: Configuring the system for local "trust" authentication
                  -# allows any local user to connect as any PostgreSQL user, including
                  -# the database superuser.  If you do not trust all your local users,
                  -# use another authentication method.
                  +# DO NOT DISABLE!
                  +# If you change this first entry you will need to make sure that the
                  +# database superuser can access the database using some other method.
                  +# Noninteractive access to all databases is required during automatic
                  +# maintenance (custom daily cronjobs, replication, and similar tasks).
                   
                  +# Database administrative login by Unix domain socket
                  +local   all             postgres                                peer
                   
                   # TYPE  DATABASE        USER            ADDRESS                 METHOD
                  -
                  -# "local" is for Unix domain socket connections only
                  -local   all             all                                     trust
                  -# IPv4 local connections:
                  -host    all             all             127.0.0.1/32            trust
                  -# IPv6 local connections:
                  -host    all             all             ::1/128                 trust
                  -# Allow replication connections from localhost, by a user with the
                  -# replication privilege.
                  -local   replication     all                                     trust
                  -host    replication     all             127.0.0.1/32            trust
                  -host    replication     all             ::1/128                 trust
                  +local   db1             localUser                               md5
                  +host    db2             remoteUser      192.168.33.0/24         md5
----------
          ID: postgresql-tablespace-dir-my_space
    Function: file.directory
        Name: /srv/my_tablespace
      Result: True
     Comment: Directory /srv/my_tablespace is in the correct state
              Directory /srv/my_tablespace updated
     Started: 13:13:23.212795
    Duration: 47.959 ms
     Changes:   
----------
          ID: postgresql-running
    Function: service.running
        Name: homebrew.mxcl.postgresql
      Result: True
     Comment: Service started
     Started: 13:13:23.296112
    Duration: 17.441 ms
     Changes:   
              ----------
              homebrew.mxcl.postgresql:
                  True
----------
          ID: postgresql-client-libs
    Function: pkg.installed
      Result: True
     Comment: No packages to install provided
     Started: 13:13:23.313812
    Duration: 0.447 ms
     Changes:   
----------
          ID: postgres_maxfiles_limits_conf
    Function: file.managed
        Name: /Library/LaunchDaemons/limit.maxfiles.plist
      Result: True
     Comment: File /Library/LaunchDaemons/limit.maxfiles.plist is in the correct state
     Started: 13:13:23.314350
    Duration: 2.801 ms
     Changes:   

Summary for local
-------------
Succeeded: 10 (changed=7)
Failed:     0
-------------
Total states run:     10
Total run time:   11.049 s

@noelmcloughlin
Copy link
Contributor Author

Rebased as #191

@noelmcloughlin noelmcloughlin deleted the postgres_homebrew branch March 8, 2018 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant