Am I supposed to let PG know in advance before I back up its datadir?
In order to create a usable online file system backup, you have to do one of the following:

Run pg_basebackup with -X stream (the default in later versions). That will do everything for you.

If you want to use this Robocopy, you have to use the low-level API:

enable WAL archiving by setting archive_mode and archive_command to archive WAL segments (you might use Robocopy there)

run SELECT pg_start_backup('label'); to get the database into backup mode

backup the data directory with Robocopy

end backup mode with SELECT pg_stop_backup();


To recover, you wilk have to use restore_command
Note that I showed you the comparatively simple deprecated &quot;exclusive backup&quot;, the &quot;non-exclusive backup&quot; is somewhat more complicated.


Consult the documentation for details.