cli
cli copied to clipboard
Permission errors when restoring database backups in local development
Bug report
- [X] I confirm this is a bug with Supabase, not with my own application.
- [X] I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
When restoring a PostgreSQL database backup in a local Supabase development environment, I encounter persistent permission errors that prevent normal operation. This creates a difficult situation where database restores cannot be properly integrated into development workflows.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Steps to reproduce
supabase init- Restore the database using:
supabase db start --from-backup /path/to/backup.backup
superbase stopsupabase start- add a new migration (like CREATE TRIGGER... or
CREATE TABLE) - Try to run any Supabase operation that accesses or modifies the database structure (like running migrations)
Error:
failed to create migration table: ERROR: permission denied for database postgres (SQLSTATE 42501)
Current behavior
After restoring a database backup, I encounter the following error:
failed to create migration table: ERROR: permission denied for database postgres (SQLSTATE 42501)
Additionally, attempting to fix permissions via SQL commands fails with:
ERROR: permission denied for database postgres
Even direct container access using docker exec as the postgres user fails to provide the necessary permissions to modify the database structure.
Expected behavior
When restoring a database backup in a local development environment:
- The restore operation should maintain proper permissions for the Supabase service accounts
- Migration tables should be accessible/creatable after a restore
- No manual permission fixes should be required for standard operations
Related issues
The main problem is that restoring database backups results in permission errors that prevent further development
Attempted solutions
I've tried the following approaches, all without success:
- Connecting to the database via supabase sql and granting permissions
- Accessing the PostgreSQL container directly and attempting to grant permissions as the postgres user
- Various permission modification commands targeting the supabase_migrations schema
- Multiple connection methods to try to gain superuser privileges
Current workaround
Currently, the only functional but extremely inefficient workaround is:
- Export data only (not schema) from the restored database
- Start a fresh Supabase instance
- Run migrations to recreate the schema
- Import the data back
Impact
This issue significantly hampers development workflows that rely on database restores, making it difficult to:
- Share database states between team members
- Test migrations against production-like data
- Streamline local development setup
Additional context
There seems to be multiple interconnected permission issues:
- The postgres role doesn't retain expected superuser privileges after restore
- The Supabase service roles don't have permissions to access or create required structures
- Even direct container access doesn't provide sufficient permissions to fix the issue
Any guidance or fixes would be greatly appreciated as this currently blocks efficient development workflows.
Possible solution directions
Some potential approaches to investigate:
- Enhance the --from-backup functionality to properly restore role permissions
- Add an option to automatically grant necessary permissions after restore
- Provide clearer documentation on managing permissions in restored databases
- Create a dedicated workflow for restoring backups with proper permissions
System information
Supabase: 2.22.6
Node.js: 20.18.3
V8: 13.2.152.41-electron.0
OS: Darwin arm64 23.6.0