Bugzilla – Attachment 63940 Details for
Bug 11974
Enable non-default unix socket location for database connections.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11974 - Enable non-default unix socket location for database connections.
Bug-11974---Enable-non-default-unix-socket-locatio.patch (text/plain), 5.02 KB, created by
Olli-Antti Kivilahti
on 2017-06-02 14:44:14 UTC
(
hide
)
Description:
Bug 11974 - Enable non-default unix socket location for database connections.
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2017-06-02 14:44:14 UTC
Size:
5.02 KB
patch
obsolete
>From 20d9c3519db7e72ea6053a00104222916e526a67 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Fri, 2 Jun 2017 12:49:49 +0300 >Subject: [PATCH] Bug 11974 - Enable non-default unix socket location for > database connections. > >----------------- >- BUSINESS CASE - >----------------- >Currently Koha doesn't support using a non-default unix socket for database connections. >Using unix sockets is generally ~20-30% faster compared to using TCP packets. Because >Koha abuses the database a lot, this will make a difference. > >Using a non-default unix socket is useful if you want to run multiple databases >(eg. mysql and mariadb) in the same OS (eg. for testing purposes). >Also if one needs to move the unix socket, for example to share it between LXC containers >using a shared partition, this feature might be handy. > >Using unix sockets for connections are faster than TCP because there is no need for TCP >and IP layer packet generation. Instead applications can communicate directly without >extra overhead. >The benefit is marginal for a single query, around 0.5ms, but escalates linearly when >hundreds of queries are performed. > >------------ >- SOLUTION - >------------ >Mysql uses unix sockets for localhost connections only, but DBI::Mysql cannot automatically >find the non-default socket path, thus it needs to be explicitly given. > >This patch modifies the Koha::Database->_new_schema routine to check for the presence of >mysql_socket in koha-conf.xml and prioritize the socket connection. > >This patch works on MariaDB and Mysql and hopefully on PostgreSQL. > >------------- >- TEST PLAN - >------------- >DEFAULT: >1. edit koha-conf.xml >1.1. put your socket path to the <socket>-attribute > by default /var/run/mysqld/mysqld.sock > or create the xml-entry <socket>/var/run/mysqld/mysqld.sock</socket> >2. load any koha's web-page. Shouldn't get any errors. > >BAD SOCKET: >1. but a bad path as your mysql_socket, eg /var/run/mysqld/mysqld.sockBADBAD >2. load any koha's web-page. It should fail due to DB connection error. > >Thank you for testing! >--- > Koha/Database.pm | 22 +++++++++++++++++++++- > debian/templates/koha-conf-site.xml.in | 1 + > etc/koha-conf.xml | 1 + > 3 files changed, 23 insertions(+), 1 deletion(-) > >diff --git a/Koha/Database.pm b/Koha/Database.pm >index 7daf5f0..fb59eb3 100644 >--- a/Koha/Database.pm >+++ b/Koha/Database.pm >@@ -58,6 +58,7 @@ sub _new_schema { > my $db_port = $context->config("port") || ''; > my $db_user = $context->config("user"); > my $db_passwd = $context->config("pass"); >+ my $db_socket = $context->config("socket") || ''; > my $tls = $context->config("tls"); > my $tls_options; > if( $tls && $tls eq 'yes' ) { >@@ -80,9 +81,28 @@ sub _new_schema { > $encoding_query = "set client_encoding = 'UTF8';"; > $tz_query = qq(SET TIME ZONE = "$tz") if $tz; > } >+ >+ #Build the dsn, it is typically like >+ # dbi:mysql:database=koha;host=localhost;port=3306 >+ # dbi:mysql:database=koha;mysql_socket=/var/run/mysql/mysql.sock >+ # dbi:Pg:database=koha;host=/var/run/Pg >+ my $dsn = "dbi:$db_driver:database=$db_name;"; >+ #Figure out if we are using sockets and for which DBRMS? >+ if ($db_socket) { >+ if ($db_driver eq 'Pg') { >+ $dsn .= "host=$db_socket;port=$db_port"; #https://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-CONNECT-HOST >+ } >+ else { #default to mysql >+ $dsn .= "mysql_socket=$db_socket"; >+ } >+ } >+ else { >+ $dsn .= "host=$db_host;port=$db_port"; >+ } >+ > my $schema = Koha::Schema->connect( > { >- dsn => "dbi:$db_driver:database=$db_name;host=$db_host;port=$db_port".($tls_options? $tls_options : ""), >+ dsn => $dsn.($tls_options? $tls_options : ""), > user => $db_user, > password => $db_passwd, > %encoding_attr, >diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in >index e273bc8..9639148 100644 >--- a/debian/templates/koha-conf-site.xml.in >+++ b/debian/templates/koha-conf-site.xml.in >@@ -252,6 +252,7 @@ __END_SRU_PUBLICSERVER__ > <database>__DB_NAME__</database> > <hostname>__DB_HOST__</hostname> > <port>3306</port> >+ <socket>__DB_SOCKET__</socket> <!-- Set this for custom unix socket connection. In PostgreSQL this is the directory where the socket should be in, not the socket file, like with MariaDB/MySQL --> > <user>__DB_USER__</user> > <pass>__DB_PASS__</pass> > <biblioserver>biblios</biblioserver> >diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml >index 9003a6f..52777fd 100644 >--- a/etc/koha-conf.xml >+++ b/etc/koha-conf.xml >@@ -76,6 +76,7 @@ __PAZPAR2_TOGGLE_XML_POST__ > <database>__DB_NAME__</database> > <hostname>__DB_HOST__</hostname> > <port>__DB_PORT__</port> >+ <socket>__DB_SOCKET__</socket> <!-- Set this for custom unix socket connection. In PostgreSQL this is the directory where the socket should be in, not the socket file, like with MariaDB/MySQL --> > <user>__DB_USER__</user> > <pass>__DB_PASS__</pass> > <tls>__DB_USE_TLS__</tls> >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11974
:
26484
|
26485
|
26486
|
26487
|
26505
| 63940 |
63941
|
63942
|
63943
|
73131