pg_basebackup: error: could not initiate base backup: ERROR: could not stat file or directory

All we need is an easy explanation of the problem, so here it is.

I have postgres 14 running on Windows 2019 server and I am using pg_basebackup to take regular backups.

The same powershell script which was working last week suddenly started giving me below errors.
No changes happened in the system except a host reboot.

For testing purposes, I tried giving full access to everyone to the both data directory/backup directory and still the same error.

PS G:\FULL_Backup> Start-Process -FilePath "C:\Program Files\PostgreSQL\14\bin\pg_basebackup.exe" -ArgumentList "-D G:\FULL_Backup\PG_Basebackup_2022-05-16_085816", "-Ft", "-z", "-R", "-U postgres", "-w" -Wait -NoNewWindow
pg_basebackup: error: could not initiate base backup: ERROR:  could not stat file or directory "./base/18119/43980": Permission denied
pg_basebackup: removing contents of data directory "G:\FULL_Backup\PG_Basebackup_2022-05-16_085816"

Thanks,
Udhayan

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

The database server cannot read one of its own files, which should never happen. You have to fix that condition.

Probably causes for that are:

  • You are running a virus scanner on the data directory that locks the file. Don’t do that.

  • You changed ownership or permissions on that file. You should never modify anything in the data directory.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply