EnterpriseDB / mysql_fdw

PostgreSQL foreign data wrapper for MySQL
Other
530 stars 162 forks source link

Current git (17 March 2017) segfaults #132

Closed jefft closed 7 years ago

jefft commented 7 years ago

It appears mysql_fdw in git is segfaulting on all operations, at least in Postgres 9.5 on Ubuntu 16.04. Here I've installed it from git and ran a query on a previously established psql->mysql table:

root@jturner-desktop:~/src/github.com/EnterpriseDB/mysql_fdw# git log -1
commit 42d05b88ee6a8e6dda19d7b0f591be02b8219bf3
Merge: c14ee1d 13b95af
Author: Ibrar Ahmed <ibrar.ahmad@gmail.com>
Date:   Wed Feb 8 16:37:24 2017 +0500

    Merge pull request #127 from gabbasb/master

    Issue (#118) Add support for push down of WHERE clause with Param nodes.
jturner@jturner-desktop:~/src/github.com/EnterpriseDB/mysql_fdw$ sudo make USE_PGXS=1 install
/bin/mkdir -p '/usr/lib/postgresql/9.5/lib'
/bin/mkdir -p '/usr/share/postgresql/9.5/extension'
/bin/mkdir -p '/usr/share/postgresql/9.5/extension'
/usr/bin/install -c -m 755  mysql_fdw.so '/usr/lib/postgresql/9.5/lib/mysql_fdw.so'
/usr/bin/install -c -m 644 .//mysql_fdw.control '/usr/share/postgresql/9.5/extension/'
/usr/bin/install -c -m 644 .//mysql_fdw--1.0.sql  '/usr/share/postgresql/9.5/extension/'

jturner@jturner-desktop:~/src/github.com/EnterpriseDB/mysql_fdw$ psql mydatabase -tAqc "select count(*) from mysql.tickets"
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
connection to server was lost

The postgres log shows the segfault:

2017-03-17 13:42:13 AEDT [30845-1] jturner@mydatabase LOG:  statement: select count(*) from mysql.tickets
2017-03-17 13:42:13 AEDT [3032-50] LOG:  server process (PID 30845) was terminated by signal 11: Segmentation fault
2017-03-17 13:42:13 AEDT [3032-51] DETAIL:  Failed process was running: select count(*) from mysql.tickets
2017-03-17 13:42:13 AEDT [3032-52] LOG:  terminating any other active server processes

Reverting to the last official release gets it working again:

jturner@jturner-desktop:~/src/github.com/EnterpriseDB/mysql_fdw$ cd ../mysql_fdw-REL-2_2_0/
jturner@jturner-desktop:~/src/github.com/EnterpriseDB/mysql_fdw-REL-2_2_0$ sudo make USE_PGXS=1 install
/bin/mkdir -p '/usr/lib/postgresql/9.5/lib'
/bin/mkdir -p '/usr/share/postgresql/9.5/extension'
/bin/mkdir -p '/usr/share/postgresql/9.5/extension'
/usr/bin/install -c -m 755  mysql_fdw.so '/usr/lib/postgresql/9.5/lib/mysql_fdw.so'
/usr/bin/install -c -m 644 .//mysql_fdw.control '/usr/share/postgresql/9.5/extension/'
/usr/bin/install -c -m 644 .//mysql_fdw--1.0.sql  '/usr/share/postgresql/9.5/extension/'
jturner@jturner-desktop:~/src/github.com/EnterpriseDB/mysql_fdw-REL-2_2_0$ psql mydatabase -tAqc "select count(*) from mysql.tickets"
WARNING:  MySQL secure authentication is off
INFO:  Successfully connected to MySQL database rt3 at server 127.0.0.1 via TCP/IP with cipher <none> (server version: 5.5.5-10.0.29-MariaDB-0ubuntu0.16.04.1, protocol version: 10) 
80323
gabbasb commented 7 years ago

Hi, Thanks for the report, however I could not reproduce the seg fault. Please share your complete test case.

Also Can you please try this test case on your set up:

CREATE EXTENSION mysql_fdw;

CREATE SERVER mysql_server FOREIGN DATA WRAPPER mysql_fdw OPTIONS (host '127.0.0.1', port '3306');

CREATE USER MAPPING FOR abbasbutt SERVER mysql_server OPTIONS (username 'root', password 'what_ever');

CREATE FOREIGN TABLE foreign_test_tab(a int, b text) SERVER mysql_server OPTIONS (dbname 'msql_test_db', table_name 'test_tab');

select count(*) from foreign_test_tab;

prepare stmt(int) as select b from foreign_test_tab where a=$1;

execute stmt(1); execute stmt(2); execute stmt(3); execute stmt(4); execute stmt(5); execute stmt(6); execute stmt(7);

The test case works fine for me.

jefft commented 7 years ago

Thanks for checking! After further testing, I found the problem was due to a stale 'mysql_fdw.so' file. I was using make USE_PGXS=1 install to rebuild from git. I needed to use make USE_PGXS=1 clean install.

Because it would be a shame to let a test case go to waste, here is the full set of command for a clean Ubuntu system:

apt update
apt install -y postgresql-9.5 postgresql-server-dev-9.5 \
 mariadb-server-10.0 libmysqlclient-dev \
 make gcc
git clone https://github.com/EnterpriseDB/mysql_fdw.git
cd mysql_fdw
make USE_PGXS=1 clean install
cd ..
cat > mysql.sql <<EOF
create database msql_test_db;
use msql_test_db;
create table test_tab(a integer, b text);
insert into test_tab values (1, 'hello');
grant all on msql_test_db to 'root'@'localhost' identified by 'secret';
EOF
mysql < mysql.sql
sudo su - postgres
cat > postgres.sql <<EOF
CREATE DATABASE testdb;
\connect testdb;
CREATE EXTENSION mysql_fdw;
CREATE SERVER mysql_server FOREIGN DATA WRAPPER mysql_fdw OPTIONS (host '127.0.0.1', port '3306');
CREATE USER MAPPING FOR postgres SERVER mysql_server OPTIONS (username 'root', password 'secret');
CREATE FOREIGN TABLE foreign_test_tab(a int, b text) SERVER mysql_server OPTIONS (dbname 'msql_test_db', table_name 'test_tab');
EOF
psql < postgres.sql
psql testdb -tAc 'select * from foreign_test_tab;'