The PostgreSQL Audit Extension (pgAudit) provides detailed session and/or object audit logging via the standard PostgreSQL logging.
The project is open source (https://github.com/pgaudit/pgaudit) with branches for each version of PostgreSQL:
PostgreSQL 13: https://github.com/pgaudit/pgaudit/tree/REL_13_STABLE
PostgreSQL 12: https://github.com/pgaudit/pgaudit/tree/REL_12_STABLE
There are many tutorials that discuss using Mingw or Cygwin to compile PostgreSQL and associated modules/plugins. These might work, but they seem to skip the part about linking.
Alright, let's begin. First, create a new project.
Next, make sure you are creating a dynamic link library.
Now, name the project and create it.
Remove all the auto-generated pre-compiled headers. Really, there are no need for headers here as PGAudit is just a single .c file.
Now paste in the correct pgaudit file.
Here they are if you're too lazy to get them for github.
pgaudit12.c
pgaudit13.c
Time to configure the project. Right click, and select properties. Now remove settings for pre-compiled headers.
Now link the PostgreSQL libs.
Then specify all the includes (make sure you specify the correct PostgreSQL version):
C:\Program Files\PostgreSQL\13\include;
C:\Program Files\PostgreSQL\13\include\server;
C:\Program Files\PostgreSQL\13\include\server\port\win32;
C:\Program Files\PostgreSQL\13\include\server\port\win32_msvc
Add _CRT_SECURE_NO_WARNINGS
Finally, compile the project.
Hopefully, you've made the DLL!
What next?
You can compile other PostgreSQL plugins this way.
But, if all you wanted was PGAudit for windows installations, here are the DLLs:
pgAudit12_win_x64.dll
pgAudit13_win_x64.dll