Skip to content

Instantly share code, notes, and snippets.

@arisnew
Created June 20, 2024 04:53
Show Gist options
  • Select an option

  • Save arisnew/0e464177ca574ea551b2a26dacc7a047 to your computer and use it in GitHub Desktop.

Select an option

Save arisnew/0e464177ca574ea551b2a26dacc7a047 to your computer and use it in GitHub Desktop.
Cara drop / delete database postgresql yg sedang ada koneksi aktif

example in postgresql old version:

-- login psql
-- makesure db exist
-- Disallow new connections
UPDATE pg_database SET datallowconn = false WHERE datname = "NAMA_DB";
-- ALTER DATABASE "NAMA_DB" CONNECTION LIMIT 1; -- (jika perlu)

-- teriminate existing connection
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = "NAMA_DB";

-- delete
DROP DATABASE "NAMA_DB";

Ref https://dba.stackexchange.com/questions/11893/force-drop-db-while-others-may-be-connected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment