Software⏱️ 2 min read📅 2026-05-31

How to Fix: Rails: FATAL - Peer authentication failed for user (PG::Error)

Postgres database user creation and permission setup for Ruby on Rails.

Quick Answer: Use pgAdmin or the command line to create a new user and grant database permissions in Postgres.

To resolve the 'Rails: FATAL - Peer authentication failed for user' error, you need to create a PostgreSQL user and grant it access to your database.

🚀 How to Create a PostgreSQL User

  • Open a terminal and type the following command: `sudo -u postgres createuser --superuser myprojectuser`

Granting Database Access

  1. Step 1: Create a new database using the following command: `sudo -u postgres createdb mydb_development`
  2. Granting Privileges to the User

    1. Step 1: Connect to your PostgreSQL database using the following command: `psql -U myprojectuser`
    2. Granting Privileges to the User (continued)

      1. Step 2: Run the following command to grant the user all privileges: `CREATE ROLE myprojectuser WITH PASSWORD 'myprojectpassword' IDENTIFIED BY 'myprojectpassword';`
      2. ✨ Wrapping Up

        After following these steps, you should be able to connect to your PostgreSQL database using the new user and grant it access to your application.

      Did this fix your problem?

      If not, try searching for specific error codes.

      🔍 Search Error Database

      ❓ Frequently Asked Questions