dbTalk Databases Forums  

Re: drop all tables in db - without dropdb ?!

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: drop all tables in db - without dropdb ?! in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Josh Berkus
 
Posts: n/a

Default Re: drop all tables in db - without dropdb ?! - 08-24-2004 , 02:54 PM






Tom tom,

Quote:
i would like to drop all tables in a database without
having to issue individual drop-statements for every
table.
is there a command that can do this?
If you're usng 7.4, you can drop the public schema, which will drop all
objects in it:

DROP SCHEMA public CASCADE;

However, you may not have permission to do that either. In that case, no,
you're stuck with one-by-one dropping. I suggest either getting greater
permissions, or writing a quick script in Perl.

--
Josh Berkus
Aglio Database Solutions
San Francisco

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #2  
Old   
Oliver Elphick
 
Posts: n/a

Default Re: drop all tables in db - without dropdb ?! - 08-24-2004 , 03:07 PM






On Thu, 2004-08-19 at 10:16, Tom Tom wrote:
Quote:
hi there,

i would like to drop all tables in a database without
having to issue individual drop-statements for every
table.
is there a command that can do this?

i can not use the dropdb since i do not have the
permissions
You could do:

DROP SCHEMA public CASCADE;

if you have permissions for that. (It would delete functions and so on
as well, not just tables.)


Or you could do it in shell script:

psql -t -d my_dbname -c "SELECT 'DROP TABLE ' || n.nspname || '.' ||
c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN
pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind =
'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND
pg_catalog.pg_table_is_visible(c.oid)" >/tmp/droptables

psql -d my_dbname -f /tmp/droptables
--
Oliver Elphick olly (AT) lfix (DOT) co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"I saw in the night visions, and, behold, one like the
Son of man came with the clouds of heaven, and came to
the Ancient of days, and they brought him near before
him. And there was given him dominion, and glory, and
a kingdom, that all people, nations, and languages,
should serve him; his dominion is an everlasting
dominion, which shall not pass away, and his kingdom
that which shall not be destroyed."
Daniel 7:13,14


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.