简体   繁体   中英

PostgreSQL 14.5 pg_read_binary_file could not open file for reading: Invalid argument

Yesterday I installed PostgreSQL 14.5 on a Windows 10 laptop. I then ran an old script to load images into a table. The script uses the pg_read_binary_file function. Some of the images are.jpg files and some are.png files. Of the 34 files, only 5 were successfully processed (1.jpg and 4.png). The other 29 failed with the following error:

[Exception, Error code 0, SQLState XX000] ERROR: could not open file " file absolute path " for reading: Invalid argument

For instance, the following statement executes without errors

select pg_read_binary_file('C:\Users\Jorge\OneDrive\Documents\000\020-logos\adalid.png') as adalid_png;

... and the following statement fails

select pg_read_binary_file('C:\Users\Jorge\OneDrive\Documents\000\020-logos\oper.png') as oper_png;

... with the following error message

[Exception, Error code 0, SQLState XX000] ERROR: could not open file "C:/Users/Jorge/OneDrive/Documents/000/020-logos/oper.png" for reading: Invalid argument

So far, I have not been able to identify any difference in the files that could be the cause of the error. Also, I'm pretty sure the script works on earlier releases of version 14. Unfortunately I have not been able to find a website to download any of those earlier releases to test it again.

Has anyone else found this problem, and its solution?

I found the cause; the command fails when the filename is not lowercase. So I solved the problem by renaming all the image files.

For example, it fails with a filename JRCG1.JPG but succeeds if the file is renamed jrcg1.jpg.

Isn't technology wonderful?

Please ignore my previous answer . As you can see in it, there was no explanation for the failure of the last command (update pais).

Now I think the issue is somehow caused by OneDrive . This laptop is new. When I logged in with my Microsoft account, the OneDrive directory was automatically created and updated. Apparently this operation only updates the directory entries, leaving the contents of the files in the cloud until they are opened (or renamed). When I zipped the directory that contains all my images, a message from OneDrive appeared saying that it in that moment it will restore some files. After that, all the commands in my scripts work. I even renamed (back to their original names) those files with hyphenated or uppercase names, and everything worked just fine. My theory is that pg_read_binary_file gets the file entry from the directory, and so it doesn't give the "No such file or directory" message, but then it fails reading the contents; giving the "Invalid argument" message instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM