Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop DB on AWS RDS instance - Postgres

Trying to drop a db from AWS RDS (postgres) is blocked only for superuser (which is reserved to AWS only).

trying to run this command on my instance:

DROP DATABASE "dbname"

results in error:

psycopg2.InternalError: DROP DATABASE cannot run inside a transaction block

I saw this issue in AWS forums, which seems to have been active by a lot of people, but no AWS representative giving a valid solution.

How can I drop my db without taking down the whole instance and raising it again?

like image 763
NotSoShabby Avatar asked Sep 11 '25 22:09

NotSoShabby


1 Answers

Worked for me:

  1. Connect to postgres DB, disconnect from DB you want to DROP!
  2. select pg_terminate_backend(pid) from pg_stat_activity where datname='yourdb';
  3. drop database 'yourdb';

Step 2 and 3 execute fast in order to prevent user rdsadmin reconnect

like image 66
ADV-IT Avatar answered Sep 13 '25 12:09

ADV-IT