delete db postgres code example
Example 1: postgres delete database
CREATE DATABASE testdb1;
DROP DATABASE testdb1;
Example 2: postgres delete database
DROP DATABASE db_name;
Example 3: drop database postgres
DROP DATABASE base_de_datos;
ERROR: database "base_de_datos" is being accessed by other users
SQL state: 55006
Detail: There is 1 other session using the database.
SELECT *
FROM pg_stat_activity
WHERE datname = 'base_de_datos';
SELECT
pg_terminate_backend (pg_stat_activity.pid)
FROM
pg_stat_activity
WHERE
pg_stat_activity.datname = 'base_de_datos';
DROP DATABASE 'base_de_datos';
DROP DATABASE base_de_datos;
Example 4: postgres remove database
DROP DATABASE IF EXISTS database_name;
Example 5: delete db postgres
dropdb 'database name'
Example 6: drop database using terminal postgres
sql -U <user> -c "drop database protodb"