How to Safely Drop All Tables in PostgreSQL, Including a Key Change in v15
Developers resetting a PostgreSQL database can use DROP SCHEMA public CASCADE followed by CREATE SCHEMA public to remove all tables, views, sequences, and functions in one step. However, a PostgreSQL 15 change revokes the default CREATE privilege on the public schema from all roles, meaning permissions must be explicitly re-granted after recreation to avoid 'permission denied' errors. The same command also removes any installed extensions such as uuid-ossp, pgcrypto, and pgvector, which must be reinstalled manually afterward. An alternative approach using a PL/pgSQL loop drops only tables while preserving extensions and functions. For hosted platforms like Supabase, using the official CLI command 'supabase db reset' is recommended to avoid accidentally cascading into managed internal schemas.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in