Rate This Document
Findability
Accuracy
Completeness
Readability

"conflicting types for copy_file_range" Displayed During PostgreSQL Compilation

Symptom

When PostgreSQL 10.1 or later is compiled on an Arm server, the message "copy_fetch.c:159:1: error: conflicting types for 'copy_file_range'" is displayed. The detailed information is as follows:

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I../../../src/interfaces/libpq -DFRONTEND -I../../../src/include -D_GNU_SOURCE -c -o copy_fetch.o copy_fetch.ccopy_fetch.c:159:1: error: conflicting types for 'copy_file_range'
copy_file_range(const char path, off_t begin, off_t end, bool trunc)^~~~~~~~~~~~~~~In file included from copy_fetch.c:15:0:/usr/include/unistd.h:1110:9: note: previous declaration of 'copy_file_range' was heressize_t copy_file_range (int infd, __off64_t *pinoff,^~~~~~~~~~~~~~~

Key Process and Cause Analysis

copy_file_range is a system call introduced in Linux 4.5 and is not supported in earlier Linux versions. Therefore, if the copy_file_range function is used for compilation in a Linux system of an earlier version, compilation problems occur. Using copy_file_chunk instead can avoid this problem. It is supported in earlier Linux systems.

Conclusion and Solution

  1. Locate the copy_fetch.c file.
    find / -name copy_fetch.c

    The copy_fetch.c file is in the src/bin/pg_rewind/ sub-path of postgresql-10.1 generated after the postgresql-10.1.tar.gz source package is decompressed.

  2. Go to the postgresql-10.1 directory and change all copy_file_range in copy_fetch.c to copy_file_chunk.
    sed -i "s/copy_file_range/copy_file_chunk/g" src/bin/pg_rewind/copy_fetch.c
  3. Run the following command to compile and install PostgreSQL:
    make && make install