Skip to content

fix(mysql_server_mariadb): Set production values as default #2300

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

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions roles/debian/mysql_server_mariadb/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
# @todo Configuration is for dev.

- name: Ensure mysql is installed.
ansible.builtin.apt:
pkg: "mariadb-server"
Expand All @@ -9,37 +7,12 @@

- name: Copy MySQL overriding configuration in place.
ansible.builtin.template:
src: mysql_dev.cnf.j2
dest: "/etc/mysql/conf.d/zz_dev.cnf"
src: zz_custom.cnf.j2
dest: "/etc/mysql/conf.d/zz_custom.cnf"
owner: root
group: root
mode: "0644"

# - name: Trigger overrides
# include_role:
# name: _overrides
# vars:
# _overrides: "{{ blackfire.overrides }}"
# when:
# - blackfire.overrides is defined
# - blackfire.overrides | length > 0

- name: Restart mysql.
ansible.builtin.service:
name: mysql
state: restarted
enabled: true

- name: Update MySQL root password.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need lines 33 to 41 for our ce-dev product that the database container. This might change in the future, but for now these lines should be left in. is_local: false is the default, so they will not have any effect on production systems.

ansible.builtin.shell: >
mysql -NBe 'GRANT ALL ON *.* TO "root"@"%" IDENTIFIED BY "root" WITH GRANT OPTION;'
when: is_local

- name: Update MySQL ce-dev password.
ansible.builtin.shell: >
mysql -NBe 'GRANT ALL ON *.* TO "ce-dev"@"%" IDENTIFIED BY "ce-dev" WITH GRANT OPTION;'
when: is_local

- name: Ensure mysql can write data.
ansible.builtin.file:
path: /var/lib/mysql
Expand All @@ -62,5 +35,5 @@
- name: Restart mysql.
ansible.builtin.service:
name: mysql
state: started
state: restarted
enabled: true
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
[mysqld]
bind-address = 0.0.0.0
character_set_server = utf8
collation_server = utf8_general_ci
bind-address = 127.0.0.1
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-query.log
slow_query_log_file = /var/log/mysql/mariadb-slow.log
log_slow_admin_statements = 1
general_log = 0
log_queries_not_using_indexes = 1
long_query_time = {{ mysql_server.long_query_time }}
skip-host-cache
skip-name-resolve
Expand All @@ -16,23 +13,31 @@ read_buffer_size = 8M
read_rnd_buffer_size= 4M
sort_buffer_size= 4M
bulk_insert_buffer_size = 16M
max_allowed_packet= 128M
# We need a large size for big tables during backups.
max_allowed_packet = 1G
thread_cache_size = 200
max_connections = 300
open_files_limit= 2000
tmp_table_size= 128M
max_heap_table_size = 128M
query_cache_size= 1G
query_cache_limit = 128M
query_cache_type= 1
tmp_table_size= 1G
max_heap_table_size = 1G
# Query cache is disabled for performance reasons for now.
query_cache_size= 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for these to be 0 by default, but they should be in defaults so people can change them if they would like to. The comment should move to defaults/main.yml against the variable too.

query_cache_type= 0
join_buffer_size = 512M
sql_mode = NO_ENGINE_SUBSTITUTION
innodb_buffer_pool_size= 512M
# Use a quarter of the total RAM for the buffer pool.
innodb_buffer_pool_size = {{ ansible_facts.memtotal_mb // 4 }}M
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, this should probably be a variable. You could have this in defaults/main.yml:

mysql_server:
  innodb_buffer_pool_size: "{{ ansible_facts.memtotal_mb // 4 }}M"

And then in this template:

innodb_buffer_pool_size = {{ mysql_server.innodb_buffer_pool_size }}

Gives people more flexibility.

innodb_read_io_threads = 8
innodb_write_io_threads= 8
innodb_flush_method= O_DIRECT
innodb_io_capacity = 400
innodb_file_per_table= 1
innodb_flush_log_at_trx_commit = 1
innodb_flush_log_at_trx_commit = 2
sync_binlog= 100
innodb_stats_on_metadata = 0

[mysqldump]
quick
quote-names
# We need a large size for big tables during backups.
max_allowed_packet = 1G
Loading