Skip to content

Commit

Permalink
MDL-58651 logstore_database: Add ability to not send database options
Browse files Browse the repository at this point in the history
In the core dml:
PostgreSQL connections now use advanced options to reduce connection overhead.
These options are not compatible with some connection poolers. The
dbhandlesoptions parameter has been added to allow the database to configure
the required defaults.

This item adds a setting to the logstore_database plugin to let you set the
same flag for your destination database - without it you won't be able to ship
logs to a postgresql database with a pgbouncer frontend.
  • Loading branch information
aolley committed Jun 28, 2017
1 parent f4a2d69 commit 556ceb2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions admin/tool/log/store/database/classes/log/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected function init() {
$dboptions['dbport'] = $this->get_config('dbport', '');
$dboptions['dbschema'] = $this->get_config('dbschema', '');
$dboptions['dbcollation'] = $this->get_config('dbcollation', '');
$dboptions['dbhandlesoptions'] = $this->get_config('dbhandlesoptions', false);
try {
$db->connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'),
$this->get_config('dbname'), false, $dboptions);
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/log/store/database/lang/en/logstore_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
$string['databasepersist'] = 'Persistent database connections';
$string['databaseschema'] = 'Database schema';
$string['databasecollation'] = 'Database collation';
$string['databasehandlesoptions'] = 'Database handles options';
$string['databasehandlesoptions_help'] = 'Does the remote database handle its own options.';
$string['databasetable'] = 'Database table';
$string['databasetable_help'] = 'Name of the table where logs will be stored. This table should have a structure identical to the one used by logstore_standard (mdl_logstore_standard_log).';
$string['includeactions'] = 'Include actions of these types';
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/log/store/database/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
'logstore_database'), '', ''));
$settings->add(new admin_setting_configtext('logstore_database/dbcollation', get_string('databasecollation',
'logstore_database'), '', ''));
$settings->add(new admin_setting_configcheckbox('logstore_database/dbhandlesoptions', get_string('databasehandlesoptions',
'logstore_database'), get_string('databasehandlesoptions_help', 'logstore_database'), '0'));
$settings->add(new admin_setting_configtext('logstore_database/buffersize', get_string('buffersize',
'logstore_database'), get_string('buffersize_help', 'logstore_database'), 50));

Expand Down
5 changes: 5 additions & 0 deletions admin/tool/log/store/database/tests/store_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public function test_log_writing() {
} else {
set_config('dbcollation', '', 'logstore_database');
}
if (!empty($CFG->dboptions['dbhandlesoptions'])) {
set_config('dbhandlesoptions', $CFG->dboptions['dbhandlesoptions'], 'logstore_database');
} else {
set_config('dbhandlesoptions', false, 'logstore_database');
}

// Enable logging plugin.
set_config('enabled_stores', 'logstore_database', 'tool_log');
Expand Down
11 changes: 11 additions & 0 deletions admin/tool/log/store/database/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This files describes API changes in the logstore_database code.

=== 3.4 ===
* PostgreSQL connections now use advanced options to reduce connection overhead. These options are not compatible
with some connection poolers. The dbhandlesoptions parameter has been added to allow the database to configure the
required defaults. The parameters that are required in the database are;
ALTER DATABASE moodle SET client_encoding = UTF8;
ALTER DATABASE moodle SET standard_conforming_strings = on;
ALTER DATABASE moodle SET search_path = 'moodle,public'; -- Optional, if you wish to use a custom schema.
You can set these options against the database or the moodle user who connects.

2 changes: 1 addition & 1 deletion admin/tool/log/store/database/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2017051500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2017062600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2017050500; // Requires this Moodle version.
$plugin->component = 'logstore_database'; // Full name of the plugin (used for diagnostics).

0 comments on commit 556ceb2

Please sign in to comment.