Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 970
Ram Rachum Avatar asked Nov 01 '11 17:11

Ram Rachum


People also ask

Can I remove default postgres database?

Unix. The default directory for PostgreSQL is /usr/local/pgsql. To uninstall PostgreSQL, manually delete the PostgreSQL folder from the default directory. To delete the database files, manually delete the Data folder from the default directory.

How do you clear a database on PgAdmin?

But there is another way in pgAdmin4: Close connections to the databases you would like to delete by right-clicking on it and selecting "Disconnect database..." Left-click on "Databases" (One up in the hierarchy: The folder that contains all your databases) Select tab "Properties" on the right hand side.

How do I delete all tables in PostgreSQL?

By using fetching all table names from pg_tables table. PostgreSQL stores all the tables on its record table named pg_table . SELECT 'DROP TABLE IF EXISTS "' || tablename || '" CASCADE;' from pg_tables WHERE schemaname = 'public'; As you can see, By the use of subquery, We can remove the entire tables from the schema.

What is purge in PostgreSQL?

Using memory purge configuration parameters, Postgres Pro Standard can automatically replace data with zero bytes before it is deleted. This section describes how different types of data are handled. By default, all the memory purge parameters are switched on.


1 Answers

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;
like image 90
Martin Samson Avatar answered Sep 17 '22 14:09

Martin Samson