Change the Postgres Database Password
Security best practices require regular, periodic password changes. This section describes how to change the Postgres database password - while maintaining uninterrupted service connection to the database, with no downtime.
For simplicity this topic uses the Artifactory product and a database namedartifactory as examples. Perform this general procedure for Xray and other JFrog products and services that use a Postrgres database.
Complete the entire procedure with the same version of the JFrog product.
To update the password for the database user:
-
Log in to the Postgres server with the existing database user credentials (in our examples:
userandpwd_old). -
Create a temporary user with full privileges in the
artifactorydatabase:CREATE USER user_tmp in group artifactory PASSWORD 'pwd_tmp'; -
For each instance of the Artifactory service that uses this Postgres database, perform the following:
a. In the
database:section of the Artifactorysystem.yamlfile, change the username and password to the temporary credentials you created in the previous step (user_tmpandpwd_tmp).b. Restart the service.
The Artifactory service accesses the database with the temporary credentials.
-
Query the server for database activity that uses the original JFrog user:
SELECT count(1) FROM pg_stat_activity WHERE datname = 'artifactory' AND usename = 'user';If there is activity, wait for the connections to finish.
-
Change the password of the permanent user to its new value:
ALTER USER user WITH PASSWORD 'new_pwd'; -
For each instance of the Artifactory service that uses this database, perform the following:
a. In the
database:section of the Artifactorysystem.yamlfile:-
Change the username from
user_tmpback to the permanent valueuser. -
Change the password
pwd_tmpto thenew_pwdyou defined in the previous step.
b. Restart the service.
The Artifactory service uses the original user and the new password to access the database.
-
-
Query the server for database activity by the temporary user:
SELECT count(1) FROM pg_stat_activity WHERE datname = 'artifactory' AND usename = 'user_tmp';If there is any activity, wait for the connections to finish.
-
Remove the temporary artifactory user from the database.
DROP USER user_tmp;
Updated 1 day ago
