Thread: pg_dump backup problems with password authentication
Hi all, I am using PostgreSQL 7.0.2 in RedHat Linux 6.2 I have changed the default authentication, in the pg_hba.conf file, from trust to password. Unfortunately, this is giving me problems with pg_dump I am trying to do a copy of just one database (with all its tables, primary and foreign keys, check clauses, triggers, etc). So, I followed the instructions at: http://postgresql.rmplc.co.uk/users-lounge/docs/7.0/admin/manage-ag1655.htm and did a pg_dump dbname > dbname.pgdump (I replaced dbname by my database name, obviously) Because I have password authentication set, I get an error message: Connection to database 'dbname' failed. fe_sendauth: no password supplied So, I did a man pg_dump and found out that -u would prompt for username and password, and -v would give a verbose output. And so I did: pg_dump -u -v dbname > dbname.pgdump The problem is when I press the ENTER key on that command: it just sits there! Eventually, I have to hit CTRL+C to get out. Can any kind soul explain me what I am doing wrong? :( Thanks in advance, Ricardo Dias Marques ricmarques@spamcop.net
On Thu, Dec 07, 2000 at 01:07:17PM +0000, Ricardo Dias Marques wrote: > So, I did a man pg_dump and found out that -u would prompt > for username and password, and -v would give a verbose output. > And so I did: > pg_dump -u -v dbname > dbname.pgdump > > > The problem is when I press the ENTER key on that command: > it just sits there! Eventually, I have to hit CTRL+C to get out. > > > Can any kind soul explain me what I am doing wrong? :( Unfortunately, the prompts for your username and password come out on standard output, which you're redirecting to the file. So you don't see them. But pg_dump is listening; type in your username and password as if you *had* seen the prompts and it will all work. Alternatively, you can use "echo" to give them: echo -n -e "username\npassword\n" | pg_dump -u -v dbname > dbname.pgdump This is insecure, as your password is briefly visible in a full ps output, but it works non-interactively, so you can do it in scripts (e.g., from cron). Of course, that's potentially even more insecure... Richard
Hi again, I would like to thank Vasileiadis Spyros, Michael Ansley and Richard Poole who all pointed out the nature of the problem and the correct solution. SUMMARY The original situation was this: 1) I had changed authentication in pg_hba.conf from trust to password 2) This gave me a problem with pg_dump When I ran the command: pg_dump -D -u -v databasename > database.sql I didnt't get an Username prompt (the -u switch would do that) The explanation for this was that the Username prompt appears in stdout (STanDard OUTput), which *usually* is the screen, but because I was redirecting output to a file, the Username: prompt was being saved in the output file (database.sql) The solution was to write the pg_dump command above, press ENTER, and then write the username (the Username prompt doesn't appear, as explained above), press ENTER, write the password and press ENTER again. Using the -v switch, some lines appear which show the operations being done (e.g., "reading user-defined types", "finding Triggers for relation:", etc) To restore the data, I edited the database.sql with joe (I found out that my default configuration of pico was breaking the lines at wrap points). I removed the Username, and Password lines, and the \connect - postgres line. Then I wrote the password in the first line (I didn't need to write the Username, because I was logged in as user postgres) Then, I created the new database: createdb newdatabase And typed the restore command: psql newdatabase < database.sql Et voilá! :) Thanks for all the help, and I hope this summary will be useful to other people with the same problem (let me live in my illusion that I'm not the only one, OK? ;-) Best wishes, Ricardo Dias Marques ricmarques@spamcop.net