Ansible Role: PostgreSQL
An Ansible role for installing and managing PostgreSQL.
Requirements
This role has been tested on
Ubuntu 16.04
andUbuntu 16.10
only.
Variables
General
-
postgresql_version
: PostgreSQL version- Default:
9.6
- Default:
-
postgresql_listen_addresses
: address for PostgreSQL to bind to- Default:
localhost
- Default:
-
postgresql_port
: port for PostgreSQL to bind to- Default:
5432
- Default:
-
postgresql_data_directory
: postgreSQL data directory- Default:
/var/lib/postgresql/{{ postgresql_version }}/main
- Default:
-
postgresql_max_connections
: maximum number of connections- Default:
100
- Default:
-
postgresql_shared_buffers
: memory for shared buffers. tuning overrides this value.- Default:
128MB
- Default:
-
postgresql_work_mem
: memory for worker processes. tuning overrides this value.- Default:
4MB
- Default:
-
postgresql_log_autovacuum_min_duration
: minimum duration for logging long automatic vacuuming- Default:
-1
- Default:
-
postgresql_log_min_duration_statement
: minimum duration for logging long queries- Default:
-1
- Default:
-
postgresql_hba_mapping
: a mapping of PostgreSQL host-based authentication rules- Default:
[]
- Default:
-
postgresql_locale
: default locale to use- Default:
en_GB.UTF-8
- Default:
-
postgresql_additional_locales
: additional locales to install. Useful for adding separate databases with different locales.- Default:
['en_US.UTF-8']
- Default:
-
postgresql_timezone
: timezone to use for database and logs.- Default:
Africa/Accra
- Default:
-
postgresql_extensions
: additional list of PostgreSQL extensions to install.- Default:
['postgresql-plpython']
NOTE:
postgresql_version
is appended to the extension name. extension must be avaialable in apt. - Default:
Tuning
postgresql_tune_db
: should we run pgtune- Default:
yes
- Default:
postgresql_tune_db_type
: the workload type of the database- Default:
mixed
- Options:
web
: web applicationsoltp
: online transactions processing systemsdw
: data warehousesdesktop
: desktop applicationsmixed
: mixed type of applications
- Default:
postgresql_tune_total_memory
: total memory usable for PostgreSQL on server- Default:
{{ ansible_memtotal_mb }}MB
- Default:
postgresql_tune_total_memory_percentage
: percentage of total memory to allocate to PostgreSQL- Default:
100
- Default:
Replication
postgresql_wal_level
: wal level. if PgLogical is enabled,logical
is used.- Default:
minimal
- Default:
postgresql_max_worker_processes
: provider node requires one per database being replicated. Subscriber node requires one per provider node.- Default:
8
- Default:
postgresql_max_replication_slots
: provider node requires one per subscriber node.- Default:
0
- Default:
postgresql_max_wal_senders
: provider node requires one per subscriber node.- Default:
0
- Default:
PgLogical
postgresql_pglogical
: install and configure pglogical.- Default:
no
- Default:
Databases
postgresql_databases
: list of databases to manage- Default:
[]
- Example
postgresql_databases: - name: exampledb # required; the rest are optional lc_collate: # defaults to '{{ postgresql_locale }}' lc_ctype: # defaults to '{{ postgresql_locale }}' encoding: # defaults to 'UTF-8' template: # defaults to 'template0' login_host: # defaults to 'localhost' login_password: # defaults to not set login_user: # defaults to 'postgres' port: # defaults to not set state: # defaults to 'present'. can be 'absent'
- Default:
Users
postgresql_users
: list of databases to manage- Default:
[]
- Example
postgresql_users: - name: jdoe #required; the rest are optional password: # defaults to not set priv: # defaults to not set role_attr_flags: # defaults to not set db: # defaults to not set login_host: # defaults to 'localhost' login_password: # defaults to not set login_user: # defaults to 'postgres' port: # defaults to not set state: # defaults to 'present'. can be 'absent'
- Default:
Usage Example
- hosts: all
vars:
postgresql_listen_addresses: "*"
postgresql_hba_mapping:
- { type: "host", database: "all", user: "all", address: "0.0.0.0/0", method: "md5" }
- { type: "host", database: "all", user: "all", address: "10.0.2.0/24", method: "md5" }
postgresql_users:
- name: jdoe
state: present
postgresql_databases:
- name: test
state: present
postgresql_tune_total_memory_percentage: 50
roles:
- thedumbtechguy.postgresql
License
MIT / BSD
Author Information
This role was created by TheDumbTechGuy ( twitter | blog | galaxy )
Credits
This role was built upon the original work of: