Postgresql Server Password Change

3 views
Skip to first unread message

Suk Harian

unread,
Aug 5, 2024, 1:47:36 AM8/5/24
to sligidlifac
Thefirst variant of this command listed in the synopsis changes certain per-user privileges and authentication settings. (See below for details.) Database superusers can change any of these settings for any user. Ordinary users can only change their own password.

The second variant changes the name of the user. Only a database superuser can rename user accounts. The current session user cannot be renamed. (Connect as a different user if you need to do that.) Because MD5-encrypted passwords use the user name as cryptographic salt, renaming a user clears their MD5 password.


The third and the fourth variant change a user's session default for a specified configuration variable. Whenever the user subsequently starts a new session, the specified value becomes the session default, overriding whatever setting is present in postgresql.conf or has been received from the postmaster command line. Ordinary users can change their own session defaults. Superusers can change anyone's session defaults. Certain variables cannot be set this way, or can only be set by a superuser.


These clauses define a user's ability to create databases. If CREATEDB is specified, the user will be allowed to create his own databases. Using NOCREATEDB will deny a user the ability to create databases. (If the user is also a superuser, then this setting has no real effect.)


Set this user's session default for the specified configuration parameter to the given value. If value is DEFAULT or, equivalently, RESET is used, the user-specific variable setting is removed, so the user will inherit the system-wide default setting in new sessions. Use RESET ALL to clear all user-specific settings.


The VALID UNTIL clause defines an expiration time for a password only, not for the user account per se. In particular, the expiration time is not enforced when logging in using a non-password-based authentication method.


Caution must be exercised when specifying an unencrypted password withthis command. The password will be transmitted to the server incleartext, and it might also be logged in the client's command historyor the server log. psql contains a command \password that can be usedto change a role's password without exposing the cleartext password.


On many systems, a user's account often contains a period, or some sort of punctuation (user: john.smith, horise.johnson). In these cases, a modification will have to be made to the accepted answer above. The change requires the username to be double-quoted.


The password is always stored encrypted in the system catalogs. The ENCRYPTED keyword has no effect, but is accepted for backwards compatibility. The method of encryption is determined by the configuration parameter password_encryption. If the presented password string is already in MD5-encrypted or SCRAM-encrypted format, then it is stored as-is regardless of password_encryption (since the system cannot decrypt the specified encrypted password string, to encrypt it in a different format). This allows reloading of encrypted passwords during dump/restore.


In case the authentication method is 'peer', the client's operating system user name/password must match the database user name and password. In that case, set the password for Linux user 'postgres' and the DB user 'postgres' to be the same.


Most of the answers were mostly correct, but you need to look out for minor things. The problem I had was that I didn't ever set the password of "postgres", so I couldn't log into an SQL command line that allowed me to change passwords. These are the steps that I used successfully (note that most or all commands need sudo or root user):


Add the following line: host all all 127.0.0.1/32 trust. This allows for all users on all databases to connect to the database via IPv4 on the local machine unconditionally, without asking for a password.


This is a temporary fix and don't forget to remove this line again later on. Just to be sure, I commented out the host all all 127.0.0.1/32 md5 (md5 may be replaced by scram-sha-256), which is valid for the same login data, just requiring a password.


Connect with psql, and very importantly, force psql to not ask for a password. In my experience, it will ask you for a password even though the server doesn't care, and will still reject your login if your password was wrong. This can be accomplished with the -w flag.


The full command line looks something like this: sudo -u postgres psql -w -h 127.0.0.1 -p 5432. Here, postgres is your user and you may have changed that. 5432 is the port of the cluster-specific server and may be higher if you are running more than one cluster (I have 5434 for example).


Firstly, it is important to understand that for most Unix distributions, the default Postgres user neither requires nor uses a password for authentication. Instead, depending how Postgres was originally installed and what version you are using, the default authentication method will either be ident or peer.


The auth config file is a list of authentication rules. Scroll down the file until you locate the first line displaying the postgres user in the third column (if such a line exists). Uncomment the line if necessary (remove the semicolon), or otherwise if the line is missing entirely, add the following line to the top of the file and save your changes:


Note: Some older versions of Postgres prefer the default authentication method of ident, but most modern installations will utilize peer as specified above instead. You may need to test both if your results differ.


Now with your configuration file updated, repeat the steps in the Login and Connect as Default User section to try to connect to as the default postgres user. Once successful, proceed with changing the password.


PostgreSQL uses the pg_hba.conf configuration file stored in the database data directory (e.g., C:\Program Files\PostgreSQL\16\data on Windows) to control the client authentication. The hba in pg_hba.conf means host-based authentication.


Step 2. Edit the pg_dba.conf file and change all local connections from scram-sha-256 to trust. By doing this, you can log in to the PostgreSQL database server without using a password.


This is why: By default, the UNIX account "postgres" is locked, which means it cannot be logged in using a password. If you use "sudo passwd postgres", the account is immediately unlocked. Worse, if you set the password to something weak, like "postgres", then you are exposed to a great security danger. For example, there are a number of bots out there trying the username/password combo "postgres/postgres" to log into your UNIX system.


Of course things can change if you configure it differently from the default setting. For example, one could sync the PostgreSQL password with UNIX password and only allow local logins. That would be beyond the scope of this question.


This article shows you how to manage your Azure Database for PostgreSQL flexible server instance. Management tasks include compute and storage scaling, admin password reset, and viewing server details.


Azure Database for PostgreSQL - Single Server is on the retirement path. We strongly recommend that you upgrade to Azure Database for PostgreSQL - Flexible Server. For more information about migrating to Azure Database for PostgreSQL - Flexible Server, see What's happening to Azure Database for PostgreSQL Single Server?.


After server creation you can scale between the General Purpose and Memory Optimized tiers as your needs change. You can also scale compute and memory by increasing or decreasing vCores. Storage can be scaled up (however, you cannot scale storage down).


1. Security: Changing passwords regularly helps protect your database from unauthorized access. It is a good security practice to change passwords periodically or whenever there is a suspicion of compromise.


1. Use strong passwords: Choose passwords that are at least 12 characters long and include a mix of uppercase and lowercase letters, numbers, and special characters. Avoid using common words or easily guessable passwords.


3. Use a password manager: Consider using a password manager to securely store and manage your PostgreSQL user passwords. Password managers can generate strong passwords and help you keep track of them.


4. Implement multi-factor authentication (MFA): Enable MFA for your PostgreSQL database to add an extra layer of security. MFA requires users to provide additional verification, such as a temporary code from a mobile app, in addition to their password.


We have 13 node HA cluster, and recently we changed the password for Postgres DB(both postgres/apigee) user, since then even though Postgresql/postgres-server are both running fine and am able to see the analytics in UI, if I try to check the service health through curl API commands...its showing


Exception: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (FATAL: password authentication failed for user "apigee")


We have Postgres setup as Master/Standby. We changed only at master for both the users postgres/apigee and got the same changed to mgm-server/qpid-server/postgres-server properties file and started the services in the same sequence as suggested in docs.


In an OpenLDAP replication setup with OpenLDAP being on a node other than Management Server, ensure that you first change the password on both OpenLDAP nodes, then on both Management Server nodes.


In an OpenLDAP replication environment with multiple Management Servers, resetting the password on one Management Server updates the other Management Server automatically. However, you have to update all Edge UI nodes separately.


Use this section to enforce a desired level of password length and strength for your API management users. The settings use a series of preconfigured (and uniquely numbered) regular expressions to check password content (such as uppercase, lowercase, numbers, and special characters). Write these settings to /opt/apigee/customer/application/management-server.properties file. If that file does not exist, create it.

3a8082e126
Reply all
Reply to author
Forward
0 new messages