Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pg_restore asking for password for database when there isn't one

I'm setting up a Rails app on a fresh Ubuntu installation and created the Postgres databases using rake db:create:all. In databases.yml, the password field for all databases is left blank. I'm trying to do a pg_restore of a dump I captured from the app's production deployment, but I keep being prompted for a password. I have a feeling this is something to do with the settings in the pg_hba.conf file, but I can't remember how I had them set in my previous Ubuntu installation. How do I get Postgres to trust pg_restore for local connections? Or is there something different causing this issue?

like image 851
Richard Stokes Avatar asked Jul 23 '13 19:07

Richard Stokes


People also ask

Does Pg_restore overwrite existing database?

When restoring a PostgreSQL dump using pg_restore , you usually add the --clean flag to remove any existing data from tables. Note that this only removes data from tables that are part of the dump and will not remove any extra tables. You need to do that yourself.

What is the default postgres password?

Type the current password for the specified user type in the Current password field. If you upgraded from version 5.2. 1, the default Postgres database password is postgres .

How do I log into postgres without password?

Edit the pg_dba. conf file and change all local connections from md5 to trust. By doing this, you can log in to the PostgreSQL database server without using a password.

Where is PostgreSQL password stored?

PostgreSQL database passwords are separate from operating system user passwords. The password for each database user is stored in the pg_authid system catalog. Passwords can be managed with the SQL commands CREATE ROLE and ALTER ROLE, e.g., CREATE ROLE foo WITH LOGIN PASSWORD 'secret' , or the psql command \password .


1 Answers

Set trust (or peer if you want to match postgresql user names to unix user names) for local connections in pg_hba.conf. You pretty much answered it in your question.

If you're specifying -h localhost explicitly then you're using TCP/IP, so you'll need to either omit -h localhost, use -h /tmp or wherever your unix_socket_directory is configured to live, or set trust for host connections from 127.0.0.1/32 in pg_hba.conf as well.

See pg_hba.conf and client authentication.

like image 199
Craig Ringer Avatar answered Nov 15 '22 07:11

Craig Ringer