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.
📋 Table of Contents
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
- Step 1: Create a new database using the following command: `sudo -u postgres createdb mydb_development`
- Step 1: Connect to your PostgreSQL database using the following command: `psql -U myprojectuser`
- Step 2: Run the following command to grant the user all privileges: `CREATE ROLE myprojectuser WITH PASSWORD 'myprojectpassword' IDENTIFIED BY 'myprojectpassword';`
Granting Privileges to the User
Granting Privileges to the User (continued)
✨ 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.
❓ Frequently Asked Questions
Open a terminal and type the following command: `sudo -u postgres createuser --superuser myprojectuser`
Step 1: Create a new database using the following command: `sudo -u postgres createdb mydb_development`
Step 1: Connect to your PostgreSQL database using the following command: `psql -U myprojectuser`
Step 2: Run the following command to grant the user all privileges: `CREATE ROLE myprojectuser WITH PASSWORD 'myprojectpassword' IDENTIFIED BY 'myprojectpassword';`
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.
🛠️ Related Fixes
How to Fix: Pc crashes shortly after launching game (rainbow
Pc crashes shortly after launching game, possible cause: outdated grap
How to Fix: Installing an APK on a locked down phone
Installing an APK on a locked down phone: Try using a rooted device, e
How to Fix: FPS drops
FPS drops in games can be caused by high system resource usage, outdat