Postgres Enable Password Login on Local
To enable password login on a local PostgreSQL database, you need to modify the pg_hba.conf
file and then restart the PostgreSQL service. Here are the steps in markdown format:
|
|
-
In the
pg_hba.conf
file, locate the line that corresponds to the local connection method. It typically looks like this:1 2
# "local" is for Unix domain socket connections only local all all trust
-
Change the authentication method from “trust” to “md5.” Your modified line should look like this:
1 2
# "local" is for Unix domain socket connections only local all all md5
This change ensures that local connections require a password.
-
Save the
pg_hba.conf
file and exit the text editor. -
After modifying the configuration file, you need to restart the PostgreSQL service for the changes to take effect. You can use
brew services
to do this:1
brew services restart postgres
Now, local connections to your PostgreSQL database will require a password for authentication.
Make sure to replace `/usr/local/var/postgres/pg_hba.conf` with the actual path to your `pg_hba.conf` file, which may vary depending on your PostgreSQL installation and operating system.