[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-22。"],[[["\u003cp\u003ePassword policies in AlloyDB Omni enhance security by enforcing strong passwords for users authenticating with the built-in, password-based method.\u003c/p\u003e\n"],["\u003cp\u003eTo enable password policies, the \u003ccode\u003ealloydb_password_validation\u003c/code\u003e library must be preloaded in the \u003ccode\u003epostgresql.conf\u003c/code\u003e file, where policies are defined using Grand Unified Configuration (GUC) parameters.\u003c/p\u003e\n"],["\u003cp\u003ePassword complexity requirements can be set to require a minimum length and specific character types (uppercase, lowercase, numeric, non-alphanumeric) using relevant flags in the \u003ccode\u003epostgresql.conf\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003ePassword expiration can be enforced by setting the \u003ccode\u003epassword.enforce_expiration\u003c/code\u003e flag to \u003ccode\u003eON\u003c/code\u003e, defining the expiration period with \u003ccode\u003epassword.expiration_in_days\u003c/code\u003e, and setting the notification period with \u003ccode\u003epassword.notify_expiration_in_days\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can prevent passwords from containing usernames by enabling the \u003ccode\u003epassword.enforce_password_does_not_contain_username\u003c/code\u003e flag in your \u003ccode\u003epostgresql.conf\u003c/code\u003e file.\u003c/p\u003e\n"]]],[],null,["# Manage built-in authentication using password policies\n\nSelect a documentation version: 15.7.0keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/manage-password-policy)\n- [16.8.0](/alloydb/omni/16.8.0/docs/manage-password-policy)\n- [16.3.0](/alloydb/omni/16.3.0/docs/manage-password-policy)\n- [15.12.0](/alloydb/omni/15.12.0/docs/manage-password-policy)\n- [15.7.1](/alloydb/omni/15.7.1/docs/manage-password-policy)\n- [15.7.0](/alloydb/omni/15.7.0/docs/manage-password-policy)\n- [15.5.5](/alloydb/omni/15.5.5/docs/manage-password-policy)\n\n\u003cbr /\u003e\n\nThis page describes how you can set and manage password policies for AlloyDB Omni.\n\n\u003cbr /\u003e\n\nAbout password policies\n-----------------------\n\nIf your application's database users authenticate with\nAlloyDB Omni using the built-in, password-based method,\nthen you can make authentication more secure by enforcing strong passwords. You\ncan define and enable password enforcement by\n[setting an AlloyDB Omni password policy](#set-password-policy).\n\n### Limitations of password policies\n\nAlloyDB Omni password policies have the following limitations:\n\n- Password policies apply to passwords created only after you set the policies.\n Existing user passwords aren't affected by a change in password policy.\n\n- Password policies apply to passwords entered only as plain text. Password\n policies don't apply to passwords entered as encrypted strings.\n\nSet an AlloyDB Omni password policy\n-----------------------------------\n\nYou set a password policy by updating Grand Unified Configuration (GUC) password\nparameters in your `postgresql.conf` configuration file. To learn how to set a\nGUC parameter, see\n[Configure AlloyDB Omni database flags](/alloydb/omni/15.7.0/docs/configure-database-flags).\n\nA password policy for AlloyDB Omni can include the following\noptions:\n\n- **Disallow username**: prevent the username from being used in the password.\n\n- **Password complexity**: check if the password contains the allowed number of\n lowercase, uppercase, numeric, and non-alphanumeric characters. Also check if\n the password length is valid.\n\n- **Password expiry**: make sure that passwords are rotated periodically.\n\nFor a list of the password policy flags that AlloyDB Omni\nsupports, see\n[Password policy flags](/alloydb/omni/15.7.0/docs/reference/password-policy-flags).\n\n### Preload the password validation library\n\nFor password a policy to take effect in AlloyDB Omni, the\n`alloydb_password_validation` library must be loaded. To load this library,\ndo the following:\n\n1. Locate the `postgresql.conf` configuration file for your installation of\n AlloyDB Omni and open it in a text editor.\n\n2. Locate the `shared_preload_libraries` line and check if it includes\n `alloydb_password_validation`. If it doesn't, then you need to add it. When\n finished, your `shared_preload_libraries` line looks similar to the\n following:\n\n shared_preload_libraries='google_columnar_engine,google_job_scheduler,google_storage,alloydb_password_validation'\n\n### Enforce password complexity\n\nTo enforce a password-complexity policy, do the following:\n\n1. Verify the your `postgresql.conf` file\n [preloads password validation library](#preload-password-db-library).\n\n2. Set the\n [`password.enforce_complexity`](/alloydb/docs/reference/password-policy-flags#enforce-complexity)\n flag to `ON`.\n\n3. Use\n [password policy flags](/alloydb/omni/15.7.0/docs/reference/password-policy-flags) to\n define your password policy.\n\nFor example, to enforce a password policy that states a password must contain at\nleast one uppercase letter, one number, and be at least 10 characters long, you\nset the following in your `postgresql.conf` file:\n\n- `password.enforce_complexity = ON`\n- `password.min_uppercase_letters = 1`\n- `password.min_numerical_chars = 1`\n- `password.min_pass_length = 10`\n\nAfter these flags are set, an attempt to set a database user password that\ndoesn't comply with this password policy fails. For example, with this policy\nset, the following `psql` client command fails because the password `foo` is\nless than 10 characters and doesn't contain a number or an upper case character. \n\n CREATE USER \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eUSERNAME\u003c/span\u003e\u003c/var\u003e WITH PASSWORD foo;\n\n### Enforce password expiration\n\nTo enforce the password expiration policy, do the following:\n\n1. Verify the your `postgresql.conf` file\n [preloads password validation library](#preload-password-db-library).\n\n2. Set the\n `password.enforce_expiration`\n flag to `ON`.\n\n3. Set the\n `password.expiration_in_days`\n flag to the number of days after a password is set that it expires.\n\n4. Set the\n `password.notify_expiration_in_days`\n flag to the number of days before a password expires that a user starts\n receiving password expiration notifications.\n\nFor example, to enforce a password policy that states passwords expire after 30\ndays and that users are notified 15 days before their password expires, you must\nset the following in your `postgresql.conf` file:\n\n- `password.enforce_expiration = ON`\n- `password.expiration_in_days = 30`\n- `password.notify_expiration_in_days = 15`\n\nIf the password of a user expires, that user can't connect to\nAlloyDB Omni. To reset the password of a user, do the following:\n\n1. Connect to AlloyDB Omni using `psql`. For example, if you\n installed AlloyDB Omni using Docker, run the following\n command:\n\n docker exec -it \u003cvar translate=\"no\"\u003eCONTAINER-NAME\u003c/var\u003e psql -h localhost -U postgres\n\n2. At the `postgres=#` prompt, run the following command:\n\n ALTER USER \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e WITH '\u003cvar translate=\"no\"\u003eNEW-PASSWORD\u003c/var\u003e';\n\nFor more information about changing a user's password, see\n[`ALTER ROLE`](https://www.postgresql.org/docs/current/sql-alterrole.html) in\nPostgreSQL documentation.\n\n### Don't allow usernames in passwords\n\nTo enforce the policy that prevents a password from containing a username, do\nthe following:\n\n1. Verify the your `postgresql.conf` file\n [preloads password validation library](#preload-password-db-library).\n\n2. Set the\n `password.enforce_password_does_not_contain_username` to `ON`.\n\nFor example, to ensure that a password doesn't contain a username as a\nsubstring, you set the following in your `postgresql.conf` file:\n\n- `password.enforce_password_does_not_contain_username = ON`\n\nIf this flag is set, then the following operation fails because the password\n`alex-secret` contains the username `alex`: \n\n CREATE USER alex WITH PASSWORD 'alex-secret';\n\nWhat's next\n-----------\n\n- Learn how to [backup and restore AlloyDB AlloyDB Omni](/alloydb/omni/15.7.0/docs/backup-overview)\n- [Create a read-only replica](/alloydb/omni/15.7.0/docs/set-up-read-replica)"]]