py-mysql2pgsql icon indicating copy to clipboard operation
py-mysql2pgsql copied to clipboard

COPY from stdin failed: error in .read() call

Open ogirardot opened this issue 13 years ago • 14 comments

Hi, i'm trying to dump a big mysql database into a postgresql database, and i'm ending up with the following error

  >> py-mysql2pgsql -v -f mysql2pgsql.yml 
  >>>>>>>>>> STARTING <<<<<<<<<<

START CREATING TABLES
  START  - CREATING TABLE PING
  FINISH - CREATING TABLE PING
  START  - CREATING TABLE error
  FINISH - CREATING TABLE error
  START  - CREATING TABLE ping
  FINISH - CREATING TABLE ping
  START  - CREATING TABLE product
  FINISH - CREATING TABLE product
  START  - CREATING TABLE updateRequest
  FINISH - CREATING TABLE updateRequest
DONE CREATING TABLES
START WRITING TABLE DATA
  START  - WRITING DATA TO PING
  8438.17 rows/sec [1440000]    
  FINISH - WRITING DATA TO PING
  START  - WRITING DATA TO error

  FINISH - WRITING DATA TO error
  START  - WRITING DATA TO ping
Traceback (most recent call last):
  File "/usr/bin/py-mysql2pgsql", line 5, in <module>
    pkg_resources.run_script('py-mysql2pgsql==0.1.6', 'py-mysql2pgsql')
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 499, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 1239, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/lib/python2.7/site-packages/py_mysql2pgsql-0.1.6-py2.7.egg/EGG-INFO/scripts/py-mysql2pgsql", line 38, in <module>
    mysql2pgsql.Mysql2Pgsql(options).convert()
  File "/usr/lib/python2.7/site-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/mysql2pgsql.py", line 31, in convert
    Converter(reader, writer, self.file_options, self.run_options.verbose).convert()
  File "/usr/lib/python2.7/site-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/lib/converter.py", line 51, in convert
    self.writer.write_contents(table, self.reader)
  File "/usr/lib/python2.7/site-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/lib/__init__.py", line 86, in decorated_function
    ret = f(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/lib/postgres_db_writer.py", line 193, in write_contents
    self.copy_from(f, '"%s"' % table.name, ['"%s"' % c['name'] for c in table.columns])
  File "/usr/lib/python2.7/site-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/lib/postgres_db_writer.py", line 116, in copy_from
    columns=columns
psycopg2.extensions.QueryCanceledError: COPY from stdin failed: error in .read() call
CONTEXT:  COPY ping, line 693

No further information on the postgresql receiving side but :

ERROR:  COPY from stdin failed: error in .read() call
CONTEXT:  COPY ping, line 693
STATEMENT:  COPY "ping"("id","ccVersion","detectedOs","login","number","pingType","productVersion","receivedAt","uuid","version","product_id") FROM stdin WITH DELIMITER AS '      ' NULL AS '\\N'

Any idea ?

Regards,

Olivier.

ogirardot avatar Oct 18 '12 13:10 ogirardot

Is this where it fails consistently? I've had mystery failures before if the the query on the mysql side was cancelled for some reason either due to time outs or someone killing the pid.

philipsoutham avatar Oct 24 '12 23:10 philipsoutham

Hello

I'm having a similar issue:

[root@DBSlave ~]# py-mysql2pgsql -v -f /root/mysql2pgsql.yml

STARTING <<<<<<<<<<

START CREATING TABLES START - CREATING TABLE event FINISH - CREATING TABLE event DONE CREATING TABLES START WRITING TABLE DATA START - WRITING DATA TO event Traceback (most recent call last): File "/usr/bin/py-mysql2pgsql", line 38, in mysql2pgsql.Mysql2Pgsql(options).convert() File "/usr/lib/python2.6/site-packages/mysql2pgsql/mysql2pgsql.py", line 31, in convert Converter(reader, writer, self.file_options, self.run_options.verbose).convert() File "/usr/lib/python2.6/site-packages/mysql2pgsql/lib/converter.py", line 51, in convert self.writer.write_contents(table, self.reader) File "/usr/lib/python2.6/site-packages/mysql2pgsql/lib/init.py", line 86, in decorated_function ret = f(_args, *_kwargs) File "/usr/lib/python2.6/site-packages/mysql2pgsql/lib/postgres_db_writer.py", line 192, in write_contents self.copy_from(f, '"%s"' % table.name, ['"%s"' % c['name'] for c in table.columns]) File "/usr/lib/python2.6/site-packages/mysql2pgsql/lib/postgres_db_writer.py", line 115, in copy_from columns=columns psycopg2.extensions.QueryCanceledError: COPY from stdin failed: error in .read() call CONTEXT: COPY event, line 1

[root@DBSlave ~]#

Maybe this is related to encoding stuff on the original mysql database?

okossuth avatar Nov 20 '12 22:11 okossuth

Update:

I found this on postgres log:

WARNING: nonstandard use of \ in a string literal at character 309 HINT: Use the escape string syntax for backslashes, e.g., E''. ERROR: COPY from stdin failed: error in .read() call CONTEXT: COPY event, line 1 STATEMENT: COPY "event"("id","department_id","shift_id","start_date","end_date","num_users","deleted","comment","start_time","end_time","pub_date","answer_deadline","approval_type","owner_id","status","copy_of_id","resent_at","notification_sent_at","extended_at","last_change") FROM stdin WITH DELIMITER AS ' ' NULL AS '\N'

Any ideas of what is going on?

okossuth avatar Nov 21 '12 11:11 okossuth

Update 2:

I fixed the problem by uninstalling py-mysql2pgsql, upgrading my python installation from 2.6 to 2.7 and installing again py-mysql2pgsql. That did the trick

okossuth avatar Nov 21 '12 13:11 okossuth

ahh thx, strange...

2012/11/21 Oskar Kossuth [email protected]

Update 2:

I fixed the problem by uninstalling py-mysql2pgsql, upgrading my python installation from 2.6 to 2.7 and installing again py-mysql2pgsql. That did the trick

— Reply to this email directly or view it on GitHubhttps://github.com/philipsoutham/py-mysql2pgsql/issues/22#issuecomment-10597157.

ogirardot avatar Nov 21 '12 18:11 ogirardot

Olivier, it seems you are using py-mysql2pgsql version 0.1.6. I'm using version 0.1.5 ( py_mysql2pgsql-0.1.5-py2.7.egg-info). try that one, maybe it can fix your problem

okossuth avatar Nov 21 '12 18:11 okossuth

I'm having a similar issue

DONE CREATING TABLES START WRITING TABLE DATA START - WRITING DATA TO address_types Traceback (most recent call last): File "/usr/local/bin/py-mysql2pgsql", line 5, in pkg_resources.run_script('py-mysql2pgsql==0.1.6', 'py-mysql2pgsql') File "/usr/local/lib/python2.7/dist-packages/distribute-0.6.35-py2.7.egg/pkg_resources.py", line 505, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/local/lib/python2.7/dist-packages/distribute-0.6.35-py2.7.egg/pkg_resources.py", line 1245, in run_script execfile(script_filename, namespace, namespace) File "/usr/local/lib/python2.7/dist-packages/py_mysql2pgsql-0.1.6-py2.7.egg/EGG-INFO/scripts/py-mysql2pgsql", line 38, in mysql2pgsql.Mysql2Pgsql(options).convert() File "/usr/local/lib/python2.7/dist-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/mysql2pgsql.py", line 31, in convert Converter(reader, writer, self.file_options, self.run_options.verbose).convert() File "/usr/local/lib/python2.7/dist-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/lib/converter.py", line 51, in convert self.writer.write_contents(table, self.reader) File "/usr/local/lib/python2.7/dist-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/lib/init.py", line 86, in decorated_functi ret = f(_args, *kwargs) File "/usr/local/lib/python2.7/dist-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/lib/postgres_db_writer.py", line 193, in write self.copy_from(f, '"%s"' % table.name, ['"%s"' % c['name'] for c in table.columns]) File "/usr/local/lib/python2.7/dist-packages/py_mysql2pgsql-0.1.6-py2.7.egg/mysql2pgsql/lib/postgres_db_writer.py", line 116, in copy columns=columns psycopg2.extensions.QueryCanceledError: COPY from stdin failed: error in .read() call

lauborges avatar Mar 21 '13 03:03 lauborges

I'm running into this problem too. Is there any workaround?

grigy avatar Jun 29 '13 15:06 grigy

@grigy try what i did: I fixed the problem by uninstalling py-mysql2pgsql, upgrading my python installation from 2.6 to 2.7 and installing again py-mysql2pgsql. That did the trick

okossuth avatar Jun 30 '13 01:06 okossuth

KK, I'm in. ready to be hit with the logs.

  1. "WARNING: nonstandard use of \ in a string literal at character 309" is mostly a result of using psycopg2 and newer postgresql version that yells at regexps in regular strings. This is only a warning though.
  2. Most errors like "COPY from stdin failed" can be caused both by postgresql and mysql backends but only the last error is reported. In most cases postgresql says that the data wasn't received and mysql stays silent. Try checking MySQL logs for errors.

kworr avatar Sep 03 '13 22:09 kworr

I'm having this problem with all the mysql tables using auto_increment. I was also having it with longblog but hacked around that allowing migrate to test in pgsql which is what the application seems to want.

Still researching the auto_increment issue but though I'd post to see if anyone else has been able to resolve that.

jlmagee avatar Jan 02 '14 21:01 jlmagee

The issue is not with auto_increment at all. It is caused by the content of blob columns in mysql. Still researching.

jlmagee avatar Jan 03 '14 13:01 jlmagee

this is pure data content issue. nothing to do with the utility itself which works perfectly

jlmagee avatar Jan 04 '14 16:01 jlmagee

One thing that did the trick for me:

use the file copy option in your yaml config file.

if file is given, output goes to file, else postgres

file: /tmp/dbexport.pgsql postgres: hostname: localhost port: 5432 username: steeve password: 12345 database: marvelouscars

And then import data saved with pgsql:

psql -U steeve marvelouscars < /tmp/dbexport.pgsql

hope this help.

NB: I tryed all the tricks above without success, the problem seems to be when data are copied to postgresql, maybe a warning that the script cannot handle and turn in an error.

alkollo avatar Mar 02 '14 04:03 alkollo