Files
fedora-infra_ansible/roles/copr/frontend/tasks/psql_setup.yml
Michal Konecny 2ec055db6f Use first uppercase letter for all handlers
This will unify all the handlers to use first uppercase letter for
ansible-lint to stop complaining.

I went through all `notify:` occurrences and fixed them by running
```
set TEXT "text_to_replace"; set REPLACEMENT "replacement_text"; git grep
-rlz "$TEXT" . | xargs -0 sed -i "s/$TEXT/$REPLACEMENT/g"
```

Then I went through all the changes and removed the ones that wasn't
expected to be changed.

Fixes https://pagure.io/fedora-infrastructure/issue/12391

Signed-off-by: Michal Konecny <mkonecny@redhat.com>
2025-02-10 20:31:49 +00:00

153 lines
4.1 KiB
YAML

---
- name: Install postresql
ansible.builtin.package: state=present pkg={{ item }}
with_items:
- "postgresql-server"
- "postgresql-contrib"
- "pspg"
- name: See if PostgreSQL is initialized
stat: path=/var/lib/pgsql/data/PG_VERSION
register: postgres_initialized
- name: Init postgresql
ansible.builtin.shell: "postgresql-setup initdb"
when: not postgres_initialized.stat.exists
- name: Copy pg_hba.conf
ansible.builtin.copy: src="pg/pg_hba.conf" dest=/var/lib/pgsql/data/pg_hba.conf owner=postgres group=postgres mode=0600
notify:
- Restart postgresql
tags:
- config
- name: Ensure postgres has a place to backup to
ansible.builtin.file: dest=/backups state=directory owner=postgres
tags:
- config
# TODO: I think we missing user creation, check it we do it somewhere else ...
- name: Copy over backup scriplet
ansible.builtin.copy: src="{{ files }}/../roles/postgresql_server/files/backup-database" dest=/usr/local/bin/backup-database mode=0755
tags:
- config
- name: Set up some cronjobs to backup databases as configured
ansible.builtin.template: >
src="{{ files }}/../roles/postgresql_server/templates/cron-backup-database"
dest="/etc/cron.d/cron-backup-database-{{ item }}"
with_items:
- "{{ dbs_to_backup }}"
when: dbs_to_backup != []
tags:
- config
- name: Enable Pg service
service: state=started enabled=yes name=postgresql
- name: Create db
postgresql_db: name="coprdb" encoding='UTF-8'
become: yes
become_user: postgres
- name: Create db user
postgresql_user: db="coprdb" name="copr-fe" password="{{ copr_database_password }}" role_attr_flags=SUPERUSER,NOCREATEDB,NOCREATEROLE
become: yes
become_user: postgres
- name: Set shared_buffers for PostgreSQL
lineinfile:
path: /var/lib/pgsql/data/postgresql.conf
regexp: '^shared_buffers ='
line: 'shared_buffers = 8096MB'
notify: Restart postgresql
tags:
- config
- name: Set effective_cache_size for PostgreSQL
lineinfile:
path: /var/lib/pgsql/data/postgresql.conf
regexp: '^effective_cache_size ='
line: 'effective_cache_size = 2048MB'
notify: Restart postgresql
tags:
- config
- name: Set work_mem for PostgreSQL
lineinfile:
path: /var/lib/pgsql/data/postgresql.conf
regexp: '^work_mem ='
line: 'work_mem = 4MB'
notify: Restart postgresql
tags:
- config
- name: Set maintenance_work_mem for PostgreSQL
lineinfile:
path: /var/lib/pgsql/data/postgresql.conf
regexp: '^maintenance_work_mem ='
line: 'maintenance_work_mem = 500MB'
notify: Restart postgresql
tags:
- config
- name: Set checkpoint_completion_target for PostgreSQL
lineinfile:
path: /var/lib/pgsql/data/postgresql.conf
regexp: '^checkpoint_completion_target ='
line: 'checkpoint_completion_target = 0.9'
notify: Restart postgresql
tags:
- config
- name: Set log_min_duration_statement for PostgreSQL
lineinfile:
path: /var/lib/pgsql/data/postgresql.conf
regexp: '^log_min_duration_statement ='
line: 'log_min_duration_statement = 500'
notify: Restart postgresql
tags:
- config
- name: Set max_connections for PostgreSQL
lineinfile:
path: /var/lib/pgsql/data/postgresql.conf
regexp: '^max_connections ='
line: 'max_connections = 200'
notify: Restart postgresql
tags:
- config
- name: Install psqlrc file
ansible.builtin.copy:
content: |
\pset linestyle unicode
\pset border 2
-- Switch pagers with :x and :xx commands
\set x '\\setenv PAGER less'
\set xx '\\setenv PAGER \'pspg -bX --no-mouse\''
:xx
dest: "{{ copr_fe_homedir }}/.psqlrc"
owner: copr-fe
group: copr-fe
mode: "0600"
- name: Install pgpass file
ansible.builtin.copy:
content: |
localhost:*:coprdb:copr-fe:{{ copr_database_password }}
dest: "{{ copr_fe_homedir }}/.pgpass"
owner: copr-fe
group: copr-fe
mode: "0400"
- stat: path="{{ copr_fe_homedir }}/.psql_history"
register: history_file
- name: Install pghistory file
ansible.builtin.file: path="{{ copr_fe_homedir }}/.psql_history" state=touch
owner=copr-fe group=copr-fe mode=0600
when: not history_file.stat.exists