Search Postgresql Archives

Re: I need to take metadata from a shell script.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Guillaume Lelarge wrote:
And rather than checking the database name, I usually prefer to filter
with datallowconn.
It'll save template1 and postgres, but the script won't give me an error
on template0.

Template databases are labeled as such, so this excludes both template0 and template1 without having to hardcode their names:

query="select datname from pg_database where not datistemplate"


However, if you can't connect to them, you can't dump them either!  So you really need both those things:


query="select datname from pg_database where not datistemplate and datallowconn"
for line in `psql -At -c "$query" postgres`
do
 pg_dump -f /home/backups/`date +\%Y\%m\%d`/"$line".sql "$line"
done


It's also a good idea to use "-At" instead of just "-t" when writing scripts that parse the output from psql, as I modified the above. If you look carefully you'll see that without the "-A", there is a space before the name of each line output. Doesn't matter in this case, but using the default "aligned" mode can cause problems in more complicated scripts that output more than one field.

--
Greg Smith  2ndQuadrant US  Baltimore, MD
PostgreSQL Training, Services and Support
greg@xxxxxxxxxxxxxxx   www.2ndQuadrant.us


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux