From: | Lee Kindness <lkindness(at)csl(dot)co(dot)uk> |
---|---|
To: | "Evandro" <evandro(at)horizontenet(dot)com(dot)br> |
Cc: | <pgsql-general(at)postgresql(dot)org>, Lee Kindness <lkindness(at)csl(dot)co(dot)uk> |
Subject: | Drop all databases objects except the database |
Date: | 2002-03-15 16:36:25 |
Message-ID: | 15506.8969.230739.979973@kelvin.csl.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Probably the fastest way is to drop the database and then
recreate... But if this doesn't suit then consider the (horrid) script
fragment below:
psql -U sprint -A -q -t -c "SELECT relname FROM pg_class WHERE relname NOT LIKE 'pg_%' AND reltype != 0;" $1 | awk 'BEGIN {print "BEGIN;"} {print "GRANT ALL PRIVILEGES ON "$1" TO PUBLIC;"} END {print "COMMIT;"}' | psql -q $1
I use this in a script to GRANT PUBLIC access to all tables in a
database. You could use something similar to DROP objects. Obviously
you'd need to get all tables from pg_class and DROP TABLE then, then
get all triggers DROP TRIGGER, and so on... See the follow page for
info on the pg_class table:
http://www.us.postgresql.org/users-lounge/docs/7.2/postgres/catalog-pg-class.html
So in short... "dropdb db; createdb test"!!!
Regards, Lee Kindness.
Evandro writes:
> Does anyone know about a script or function to drop all databases
> objects except the database? ( to empty a database)
From | Date | Subject | |
---|---|---|---|
Next Message | Cornelia Boenigk | 2002-03-15 16:42:49 | How to catch notify messages with PHP |
Previous Message | Jean-Luc Lachance | 2002-03-15 16:19:47 | Re: R: [SQL] UPDATE and SELECT result difference |