How can I log queries for each (or specific) user in a separate file in PostgreSQL?
The answer will completely depend on the platform you are using. You need a type of environment in which each request is executed and / or communicated along with the connection context.
For example, in NodeJS, if you are using node-postgres , you have access to an object client
along with every request made, and that object has all the connection details, including the username.
You will need to solve this problem for a specific database + development environment + database. Without these 3 variables, it is known that there can be no answer.
The only alternative is when the database is fully accessible through functions that add functionality to log every request detail against the current username. But for starters, this is not a very good architecture.
source to share