简体   繁体   中英

How do you wipe a Postgresql database?

I'm sending queries through Django on a PaaS service, and I think I can't access any command line utilities. I would have just dropped the entire database and recreated it, but I don't have permissions for that.

I'm looking for a simple command that would return the database to a completely virgin state.

you could cascade drop the schema and then drop the db:

drop schema myschema CASCADE;
drop database mydb;

if you do not have the rights to do so, you will have to drop table by table.

EDIT: If you can only drop tables, this will give you the SQL statements to run:

select 'drop table '||schemaname||'.'||tablename||' CASCADE;' 
from pg_tables where schemaname = 'myschema' order by schemaname, tablename;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM