Обсуждение: postgres on the comman line

Поиск
Список
Период
Сортировка

postgres on the comman line

От
"Michael Höller"
Дата:

Hello,

I like to automate a daily check and like to run select statement via
cron but this seems to be more tricky than I thought....

I tried the following:
su postgres -c "select count(*) from TABLE where xxxxxx;"

I have the probelm that I am allways asked for the password - I did not
find a way how to pass the password. 

Also I like to direct the result to a file, I assume I can do this via >
but not haveing passed the first problem I did not check this. 

I am happy for every hint

Thanks a lot 
Michael





Re: postgres on the comman line

От
Thomas Pundt
Дата:
Hi Michael,

On Thursday 22 September 2005 15:55, Michael Höller wrote:
| I like to automate a daily check and like to run select statement via
| cron but this seems to be more tricky than I thought....
|
| I tried the following:
| su postgres -c "select count(*) from TABLE where xxxxxx;"

you mean
 su - postgres -c "echo 'select count(*) from TABLE where xxxxxx;'|psql"

?

| I have the probelm that I am allways asked for the password - I did not
| find a way how to pass the password.

search the documentation for the .pgpass file. It should contain lines
with colon separated values consisting of host:port:database:user:password
and must not be world-readable.

| Also I like to direct the result to a file, I assume I can do this via >
| but not haveing passed the first problem I did not check this.

yes.

Ciao,
Thomas

--
Thomas Pundt <thomas.pundt@rp-online.de> ---- http://rp-online.de/ ----



Re: postgres on the comman line

От
"A. Kretschmer"
Дата:
am  22.09.2005, um 15:55:53 +0200 mailte "Michael Höller" folgendes:
> 
> 
> Hello,
> 
> I like to automate a daily check and like to run select statement via
> cron but this seems to be more tricky than I thought....
> 
> I tried the following:
> su postgres -c "select count(*) from TABLE where xxxxxx;"

- run the cron direcly as postgres
- echo "select foo from bar" | psql ...


or:

write your sql-query i a file and "psql -f file"

> 
> I have the probelm that I am allways asked for the password - I did not
> find a way how to pass the password. 

put it in the ~/.psqlrc


> 
> Also I like to direct the result to a file, I assume I can do this via >

yes, this is possible.


Regards, Andreas
-- 
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net===    Schollglas Unternehmensgruppe    === 


Re: postgres on the comman line

От
Achilleus Mantzios
Дата:
O "Michael Hφller" έγραψε στις Sep 22, 2005 :

> 
> 
> Hello,
> 
> I like to automate a daily check and like to run select statement via
> cron but this seems to be more tricky than I thought....
> 
> I tried the following:
> su postgres -c "select count(*) from TABLE where xxxxxx;"

Firstoff, 'select' is nor a unix command, neither
a postgresql program.
So you need something like:

su postgres -c "psql -c 'select count(*) from TABLE where xxxxxx'"

If you are the only one with an account on the machine
then you might try to tweak ~postgres/data/pg_hba.conf
and set method 'trust' for local access (no tcpip,psql without the -h 
option) .

Also you could set env variables PGPASSWORD, PGUSER.

> 
> I have the probelm that I am allways asked for the password - I did not
> find a way how to pass the password. 
> 
> Also I like to direct the result to a file, I assume I can do this via >
> but not haveing passed the first problem I did not check this. 
> 
> I am happy for every hint
> 
> Thanks a lot 
> Michael
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 

-- 
-Achilleus