Suraj
Suraj

Reputation: 2563

pg_dump fails with error: `FATAL: role "username" does not exist`

I have a db named backupdb, I want to import this to my local rails app so I want to take a dump of it.

When I am running pg_dump backupdb, I am getting below error.

pg_dump: [archiver (db)] connection to database "backupdb" failed: FATAL: role "username" does not exist

what's wrong here. Please help.

I downloaded the db from my email and then trying to create a dump so I can import it to my local rails app

Upvotes: 28

Views: 38839

Answers (5)

Fuzzlightyear
Fuzzlightyear

Reputation: 19

I was having the same problem but after trying out different permutations of the command options while referencing the documentation, I was able to get it running with this order of options. The command I used is:

pg_dump.exe -h localhost -U postgres -t "shop*" -t "core*" -t "profiles*" -f "path/to/output/dir_or_file" mydbname

Where:

option prefix option params
-h host localhost
-U username postgres
-t Tables Any tables whose name starts with (shop, core, or profiles (NOTE: for django app tables in my case))
-f file out path where I want to save the dumped file
(End of cmd) database mydbname

Note: as I have multiple versions of postgresql on my computer, I had to call the newest pg_dump executable. (Just for reference)

Upvotes: 1

VijayGupta
VijayGupta

Reputation: 675

Try this way, it works!!

$ pg_dump -h localhost -U postgres -Fc mydb > db.dump

Upvotes: 26

SupaMario
SupaMario

Reputation: 1146

If someone has the same problem using intellij, here is what helped me: In my case the Problem was, that i right clicked the datasource, but you have to open it and right click the database itself. So in the image below don't click on localDB. Right click the database name and then do a dump.

Hope this will help someone to solve this confusing UX problem. :D

enter image description here

Upvotes: 0

Mani Deep
Mani Deep

Reputation: 1356

This command will take the backup of complete database

pg_dump -h localhost -U "dbuser" "dbname" -Fc > "pathfilename.backup"

**ex:** pg_dump -h localhost -U mani manidb - Fc > "thamesdb.backup"

for more pg_dump formats please refer to this answer

Upvotes: 3

xyious
xyious

Reputation: 1073

You're giving "username" as username, which does not exist. You need to pass a username that exists (postgres would probably do).
add parameters --username=postgres --password and it will ask you for the password for user postgres. (you might have security set to trust in your pg_hba.conf in which case leaving out --password would work.

Upvotes: 2

Related Questions