0

I would like to run a small logon script on my postgres server. If a user with a certain username connects, then I want to check the app name of the session, and if it contains a certain value I want to set idle_in_transaction_session_timeout for that session.

I fail to find where to put logon scripts/commands in postgres. Any ideas? TY!

1
  • 1
    From outside the other user's session, you can only configure default settings that will be applied next time they open a new session. You'd have to hijack their session in order to alter the settings that are already in place in their ongoing session. Logon/startup/init scripts are usually configurable on client end. Commented Feb 13, 2023 at 12:02

1 Answer 1

1

You can configure these settings on role level:

ALTER ROLE _your_user_name_ 
SET idle_in_transaction_session_timeout TO 3600000; -- one hour

Each time this user connects to your database, these settings will be applied. There is no need for an additional command after login. Other settings can be set on database level as well.

Sign up to request clarification or add additional context in comments.

5 Comments

yes thank you but i want different idle_in_transaction_session_timeout for the same role, depending on app name of the connection. we use the same role both manually and for the system. we want manual users to have a shorter timeout. ty
Advice: Use different roles
@Peter a) just don't do that, use different roles b) set the parameters in the connection settings of the application or user tool, not in the database
thank you @FrankHeikens and bergi - I agree that we should use different roles. But this seems very difficult to impossible with postgres as only the owner of objects can modify them. so the manual user will not be able to create and drop objects of the system user and vice versa. that is why we gave up having different users doing DDL to the same objects in postgres.
I have opened stackoverflow.com/questions/75445136/… to elaborate on this follow up problem with the different roles

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.