PDA

View Full Version : cron jobs for postgresql


Montfort
04-02-02, 16:30
Hi tried to schedule a cron job(on solaris) to run a scripts(as postgres user) which in turn runs a query to the postgresql database and stores the results into a text file.But I get errors from the cron demon that there is no directory.When I tried to run the cron job as root.The error I get is psql not found.

the script I used is

psql -p 5432 -A -F ',' -c 'select * from test' -d test -t -o /cronjob/test.txt

Any suggestions?


Thanks
Montfort

eperich
04-03-02, 08:16
I had the same problem

the cron has only minor rights
also the path variable is one

start the psql with the absolute path and not relative

I think thats the problem

Montfort
04-03-02, 10:23
Hello eperich,
Thanks for the response.
Could You be more specific What you meant, about starting the psql with absolute path.
An example coould be very useful to me.

Thanks
Montfort.

eperich
04-03-02, 12:17
for EXAMPLE
/usr/local/pgsql/psql -p 5432 -A -F ',' -c 'select * from test' -d test -t -o /cronjob/test.txt


absolute path
cron does not have cause of security reason not the environment variable path

Montfort
04-03-02, 17:03
hello eperich,
I tried to the absolute path.The error I got was
/usr/local/pgsql/psql not found

any suggestions?

Thanks
Montfort

eperich
04-03-02, 17:12
this was an example

I don't know where the file is on your system

you must enter the path where your psql file
is located

Montfort
04-04-02, 12:39
hello eperich,
Thanks.
Running a cron job as a postgres user is possible?


Thanks
montfort

etones
04-04-02, 13:21
hi all, just read this, i arent and big postgre/php user, that my brother, but something i picked up...

inorder to access the postgre db during the cron, dont you need to be logged in as the postgre db user.

Try generating the cron whilst logged in as the postgre db user, may solve your problem

Regards

MaleMan
06-06-02, 21:20
i'd setup my linux box to backup and vacuum my postgreSQL dbase, the result is fine except for the name of the output file.

i put this lines to .bash_profile:
DATE1=`date +%b_%d_%y`
export DATE1

in crontab:
03 04 * * 0 ~/bin/pg_dump CDKEY /bin/gzip "$DATE1"_dbname1.dump.gz 2> "$DATE1"_CDKEY.error.log
06 04 * * 0 ~/bin/vacuumdb -a -f 2> "$DATE1"_vacuumdb.log

the output file is like this:
_dbname.dump.gz
_vacuumdb.log

but if i do this command:
#echo $DATE1
# Jun_07_02 --> output

pls help me guys...

eperich
06-09-02, 18:22
When starting the cron

be aware that almost no environment variables are active due to security reasons

always take the absolute PATH starting the postgresql commands

maybe this is the same thing that happened with the .bash_profile

make a shell script that executes the pg_dump and vacuumdb and generate the date there

MaleMan
06-09-02, 22:02
:)

now i konw... ill just make some adjustments and create some scripts for it.

THNX! :D

Genadijus
09-25-02, 04:08
add DATE variable to your crontab file

eg.

#!/bin/sh
DATE = `date +%b_%d_%y`

03 04 * * 0 ~/bin/pg_dump CDKEY /bin/gzip "$DATE1"_dbname1.dump.gz 2> "$DATE1"_CDKEY.error.log 06 04 * * 0 ~/bin/vacuumdb -a -f 2> "$DATE1"_vacuumdb.log

MaleMan
10-11-02, 01:20
thanx! that problem was already solved using bash/perl scripts, all your commands and sql queries are all in the script so once you do your cron job, you just create some line there to run your script and whala!!! your problem is solved.

:D