Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron Jobs 2

Status
Not open for further replies.

kizmar2

Programmer
May 25, 2004
164
US
I need to do the equivalent of the code below but with PostgreSQL. I haven't been able to find documentation on the pg_dump command that allows you to use a login. This is a script for a Cron Job by the way, on a web host.

Code:
mysqldump --user='username' --password='password' --extended-insert bd_name > /path/to/file/backup.sql

What I have with pgsql is this:

Code:
pg_dump -u --superuser='username' db_name > /home/macker/backup/db/macker2002.sql

I get permission denied. Which I'm assuming is because I don't have a password there.

KizMar
------------
 
I use:
pg_dump -U <user> -h <hostname> -F t <database> > file.tar

the -F does the format, t is the 'tar' format, p is plain, forget what the third is (on windows box at this second).

----
JBR
 
you can set the environment variables in the backup script (PGPASSWORD for example), see here
or you can use the .pgpass file for the user running the cron job
and you can tweek the pg_hba.conf file so it doesn't need password for the user running the cron job
 
I've tried setting the PGPASSWORD variable and it's not recognizing anything that I use... maybe I'm missing something. What's the syntax to set that in a script?

I don't have access to the .pgpass or pg_hba.conf files, I'm in a jailshell on my web host... so the variable may be my only hope of getting past the password verification...

KizMar
------------
 
the syntax depends on the script language used for the script (for bash it is
PGPASSWORD=mypass
)


by the way, despite being in a jail, I am quite sure that you can modify .pgpass, try finding where is your home directory and put it there
 
OK... creating the .pgpass file in my account's home directory worked!

I have another issue though... now when it goes to backup the DB, I get this:

pg_dump: attempt to lock table "colors" failed: ERROR: permission denied for relation colors

Keep in mind that we acquired this DB from someone else and there are a lot of triggers and constraints in there that I'm not familiar with.

That specific table is pretty basic so I'm not sure why it's not allowing the lock. Is there a command to stop pg_dump from trying to lock the tables?

KizMar
------------
 
FYI - I did the'ol "GRANT ALL PRIVILEGES ON <table> TO <user>;" to fix this...

I'm all set, thanks again!

KizMar
------------
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top