Home > Back-end >  PostgreSQL get windows user during insert
PostgreSQL get windows user during insert

Time:12-06

I have windows based application that communicates with PostgreSQL (installed on another Windows Server). Currently I use connection string with username and password (user is configured on PostgreSQL DB). Is it possible to somehow change it so that in connection automatically logged to windows User is passed and somehow configured on Postgres so that he can have access to db?

I need to do it in order to add some audit: when record is added to table I would like to add information in separate column about which user inserted it (it would be great to do it on :) thanks!

CodePudding user response:

Answer depends on environment. If you work in domain and all your user do (careful on permissions), then it is possible on server side (see https://www.postgresql.org/docs/12/auth-methods.html) But if not, then the easiest approach is to include information in insert call, or call function which performs insert, but takes user info as an argument.

CodePudding user response:

If your server is on Windows too, the natural thing to do would be to use SSPI (Windows single-sign-on) authentication. For that, use sspi authentication in pg_hba.conf and add SSPI configuration parameters after that.

  • Related