Skip to content
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

Segmentation fault when running COPY statement #309

Closed
jkldv opened this issue Apr 16, 2019 · 7 comments
Closed

Segmentation fault when running COPY statement #309

jkldv opened this issue Apr 16, 2019 · 7 comments

Comments

@jkldv
Copy link

jkldv commented Apr 16, 2019

When I try to execute a COPY to a oracle_fdw foreign table, the thread crashes with segmentation fault. When I use postgres_fdw foreign table, this operation works fine and results in INSERT statements to the remote postgres database table.

[oracle_fdw]$ cat tmp | psql testdb_remote postgres -c 'copy garbage from stdin'
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.

Postgres log isn't terribly enlightening (and yes, my table is literally named 'garbage'):
2019-04-16 12:00:17.523 CDT [30505] LOG: server process (PID 26078) was terminated by signal 11: Segmentation fault
2019-04-16 12:00:17.523 CDT [30505] DETAIL: Failed process was running: copy garbage from stdin
2019-04-16 12:00:17.523 CDT [30505] LOG: terminating any other active server processes
2019-04-16 12:00:17.524 CDT [22378] WARNING: terminating connection because of crash of another server process

I'm pretty sure COPY should be allowed from experience with another FDW:
[postgres_fdw]$ cat tmp | psql testdb postgres -c 'copy rel_11.garbage from stdin'
COPY 1

@jkldv
Copy link
Author

jkldv commented Apr 16, 2019

Here's some more info I was able to grab.
/var/log/messages:
postmaster[26078]: segfault at 58 ip 00007fe7550984a8 sp 00007ffcc38d5af0 error 6 in oracle_fdw.so[7fe75508c000+21000]

core_backtrace:
[ { "address": 139774236566696
, "build_id": "b136ddb4c640a21dd8ec1432808b93e5b47bbfcf"
, "build_id_offset": 50344
, "function_name": "oracleExecForeignInsert"
, "file_name": "/usr/pgsql-11/lib/oracle_fdw.so"
}
, { "address": 5859560
, "build_id": "276dd96b90b1b030fe6113685407134a8f7148c3"
, "build_id_offset": 1665256
, "function_name": "CopyFrom"
, "file_name": "/usr/pgsql-11/bin/postgres"
}
, { "address": 5861445
, "build_id": "276dd96b90b1b030fe6113685407134a8f7148c3"
, "build_id_offset": 1667141
, "function_name": "DoCopy"
, "file_name": "/usr/pgsql-11/bin/postgres"
}

@jkldv
Copy link
Author

jkldv commented Apr 16, 2019

With debug3, I see this log
2019-04-16 15:25:06.049 CDT [30259] DEBUG: oracle_fdw: execute foreign table insert on 34084
2019-04-16 15:25:06.049 CDT [30259] CONTEXT: COPY garbage, line 1: "7 steel 88"
2019-04-16 15:25:06.285 CDT [30201] DEBUG: server process (PID 30259) was terminated by signal 11: Segmentation fault

@jkldv
Copy link
Author

jkldv commented Apr 16, 2019

Old school debugging with logs shows:
WARNING: oracle_fdw: fdw_state: 0

@laurenz laurenz added the bug label Apr 16, 2019
@jkldv
Copy link
Author

jkldv commented Apr 16, 2019

My suspicion is that this is caused by lack of implementation of BeginForeignInsert and EndForeignInsert. This is judging by the debug logs (almost none print for COPY vs INSERT)

@laurenz
Copy link
Owner

laurenz commented Apr 16, 2019

Yes, absolutely.
This function is not called for COPY.

I'll see if I can add support, otherwise I'll just forbid COPY.
Crashing is not an option.

laurenz added a commit that referenced this issue Apr 17, 2019
This capability was introduced to PostgreSQL in commit
3d956d9562aa4811b5eaaaf5314d361c61be2ae0 in v11.

Attempting COPY on a foreign table crashed PostgreSQL before this patch,
as reported by "jkldv" in #309.

This patch is still incomplete:
- too little testing
- crashes if there is an AFTER INSERT trigger
- no regression tests yet
@laurenz
Copy link
Owner

laurenz commented Apr 19, 2019

This was more work than I expected.
Could you test if it works for you now?

@jkldv
Copy link
Author

jkldv commented Apr 22, 2019

Worked perfectly! Thank you very much for your help.

Before:

$ cat tmp | psql testdb_remote postgres -c "copy garbage from stdin"
WARNING:  oracle_fdw: execute foreign table insert on 34084
WARNING:  oracle_fdw: fdw_state: 0
server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.

After:

$ cat tmp | psql testdb_remote postgres -c "copy garbage from stdin"
COPY 11

Repository owner locked as resolved and limited conversation to collaborators May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants