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:

1
2
3
4
5
6
## Enable Password Login on Local PostgreSQL

1. Open the `pg_hba.conf` file for editing using a text editor. You can use `vim` as you mentioned or any other text editor of your choice. Replace `/usr/local/var/postgres/pg_hba.conf` with the correct path to your `pg_hba.conf` file if it's located elsewhere.

   ```shell
   vim /usr/local/var/postgres/pg_hba.conf
  1. 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
  2. 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.

  3. Save the pg_hba.conf file and exit the text editor.

  4. 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.
0%