psql: FATAL: Peer authentication failed for user "dev"

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for psql: FATAL: Peer authentication failed for user "dev"

πŸ“ Easy Solutions to the "psql: FATAL: Peer authentication failed for user 'dev'" Error πŸš«πŸ”‘

So, you've encountered the frustrating "psql: FATAL: Peer authentication failed for user 'dev'" error while trying to log in to your PostgreSQL database as the user 'dev'. Don't worry, we’ve got your back! In this blog post, we'll address this common issue and provide easy solutions to help you get back on track. Let's dive in! πŸŠβ€β™‚οΈπŸ’»

Understanding the Problem πŸ€”

This error occurs when the authentication method set for your PostgreSQL database is set to "peer" authentication. In simpler terms, PostgreSQL is trying to match your operating system username (in this case, 'dev') with a database role, and failing to find a match.

Solution 1: Switch to Password Authentication πŸ”‘

One of the simplest ways to resolve this error is by changing the authentication method from "peer" to "password". Here's how you can do it:

  1. Open the pg_hba.conf file, which is usually located in the data directory of your PostgreSQL installation.

  2. Look for a line that specifies the authentication method for local connections. It should look something like this:

# "local" is for Unix domain socket connections only
local   all             all                                     peer
  1. Replace the "peer" method with "md5" to enable password authentication. The line should now look like this:

# "local" is for Unix domain socket connections only
local   all             all                                     md5
  1. Save the changes and restart your PostgreSQL server for the changes to take effect.

Solution 2: Configure pg_ident.conf for Peer Mapping πŸ—ΊοΈ

If you still want to use the "peer" authentication method but encounter this error, you can set up peer mapping using the pg_ident.conf file. Follow these steps:

  1. Open the pg_ident.conf file, also located in the data directory of your PostgreSQL installation.

  2. Add an entry that maps your operating system username to the desired PostgreSQL role. For example:

# MAPNAME       SYSTEM-USERNAME         PG-USERNAME
dev_map         dev                     dev

In this example, we're mapping the operating system username "dev" to the PostgreSQL role "dev". Feel free to change the names as per your setup.

  1. Save the changes and restart your PostgreSQL server.

Call-to-Action: Engage and Share! πŸ“£πŸ”„

We hope this guide has helped you resolve the "psql: FATAL: Peer authentication failed for user 'dev'" error effortlessly. If you found this post useful, be sure to share it with your fellow developers, so they can benefit too! And don't hesitate to leave a comment on our blog with your thoughts and any other PostgreSQL-related questions you may have. Happy coding! πŸ’ͺπŸš€

Disclaimer: The solutions provided are basic troubleshooting steps. If you encounter further issues, consider consulting the official PostgreSQL documentation or seeking help from the PostgreSQL community.

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

πŸ”₯ πŸ’» πŸ†’ Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! πŸš€ Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings πŸ’₯βœ‚οΈ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide πŸš€ So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? πŸ€” Well, my