Arbitrary logging can be inserted into WAL (Write-Ahead Log), PostgreSQL's update log, using a dedicated function. The logs are automatically extracted from the archive file to an external file by a daemon process running on a background worker.
These functions and daemon processes come in the form of PostgreSQL extensions (EXTENSION).
Logs inserted within the same transaction are extracted as sequential log sequences. If there are multiple log sequences, they are extracted in order of transaction completion.
Completion of a transaction is either COMMIT or ROLLBACK. Also, if an instance crashes while a transaction is in progress, it is considered to have ROLLBACK at the time of standby promotion or crash recovery on the primary alone, and is subject to userlog extraction.
If the instance crashes, the userlogs of COMMIT transactions will not be lost, but some current userlogs of ROLLBACK transactions and running transactions may be lost. This is because PostgreSQL does not synchronize WAL writes except for COMMIT.