Why are you using a direct assignment to CurrentMemoryContext instead of using the MemoryContextSwitchTo function in the SafeCopying() routine?
"CurrentMemoryContext = cxt" is the same as "MemoryContextSwitchTo(cxt)", you can see it in the implementation of MemoryContextSwitchTo(). Also correct this.
When you initialize the cstate->sfcstate structure, you create a cstate->sfcstate->safe_cxt memory context that inherits from oldcontext. Was it intended to use cstate->copycontext as the parent context here?
Good remark, correct this.
Thanks Nikita Malakhov for advice to create file with errors. But I decided to to log errors in the system logfile and don't print them to the terminal. The error's output in logfile is rather simple - only error context logs (maybe it's better to log all error information?).
There are 2 points why logging errors in logfile is better than logging errors in another file (e.g. PGDATA/copy_ignore_errors.txt). The user is used to looking for errors in logfile. Creating another file entails problems like: 'what file name to create?', 'do we need to make file rotation?', 'where does this file create?' (we can't create it in PGDATA cause of memory constraints)