Re: psql - better support pipe line

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql - better support pipe line
Date: 2015-08-24 11:02:10
Message-ID: CAFj8pRCOnOmrZra4bSnKWY9PAw612r=wkCfh1a=mNgvQKpGOEw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2015-08-24 12:49 GMT+02:00 Heikki Linnakangas <hlinnaka(at)iki(dot)fi>:

> On 08/24/2015 08:06 AM, Pavel Stehule wrote:
>
>> Hi
>>
>> I found so a set "psql" and "xargs" is pretty strong. But I miss a psql
>> option for simple returning current database and continuing in pipeline.
>>
>> What I am doing:
>>
>> psql postgres -At -c "select datname from pg_database" |
>> xargs -P 3 -I % psql % -At -c "select current_databe() from
>> pg_stat_all_tables
>> where relname = 'pg_attribute' and n_dead_tup > 100000" |
>> xargs -P 3 -I % sh -c "psql % -q -c 'analyze pg_attribute'; echo %" |
>> xargs -P 3 -I % psql % -At -c "select curren_database() from ..."
>>
>> it works perfectly - but the line
>>
>> xargs -P 3 -I % sh -c "psql % -q -c 'analyze pg_attribute'; echo %"
>>
>> is little bit ugly - with some psql option it can be cleaned to
>>
>> xargs -P3 -I % psql % -q --echo-db -c "analyze pg_attribute" | ...
>>
>> --echo-db requires -q option
>>
>> What are you thinking about this idea?
>>
>
> Seems like a one-tricky-pony to me. You're just as likely to need to print
> a relation name or something else, as the current database.
>

yes, you have true

> I don't actually understandu what you'd put in the "..." above. One you've
> analyze'd the table, what more do you want to do?
>

do other filtering and for example run VACUUM FULL when it can have a
significant effect

>
> Overall, once your pipeline gets that complicated, I'd rather write a
> little bash or perl script with for-loops and variables.

It is pipeline of trivial statements - so still it is pretty simple - and
with multiprocess suppport

Regards

Pavel

>
>
> - Heikki
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2015-08-24 11:38:19 Re: exposing pg_controldata and pg_config as functions
Previous Message Heikki Linnakangas 2015-08-24 10:49:41 Re: psql - better support pipe line