{ "nodes": [{ "uri": "https:\/\/log.exos.ninja\/44", "content": "# Matar todas las conexiones a una base de datos Postgres para hacerle DROP\r\n\r\nNada, me pas\u00f3 que ten\u00eda que hacer un `drop database` en Postgres y me tir\u00f3 el siguiente error:\r\n\r\n ERROR: database \"****\" is being accessed by other users\r\n DETALLE: There is 1 other session using the database.\r\n SQL state: 55006\r\n Detail: There is 1 other session using the database.\r\n\r\nPor lo que tuve que buscar una forma de desconectar a los clientes conectados, por suerte en [stack overflow](https:\/\/stackoverflow.com\/questions\/5408156\/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it) encontr\u00e9 la respuesta.\r\n\r\nAs\u00ed que robando descaradamente:\r\n\r\n## PostgreSQL 9.2 and above:\r\n\r\n SELECT pg_terminate_backend(pg_stat_activity.pid)\r\n FROM pg_stat_activity\r\n WHERE pg_stat_activity.datname = 'TARGET_DB' -- \u2190 change this to your DB\r\n AND pid <> pg_backend_pid();\r\n\r\n## PostgreSQL 9.1 and below:\r\n\r\n SELECT pg_terminate_backend(pg_stat_activity.procpid)\r\n FROM pg_stat_activity\r\n WHERE pg_stat_activity.datname = 'TARGET_DB' -- \u2190 change this to your DB\r\n AND procpid <> pg_backend_pid();", "created": "2020-03-25 00:21:20"}] }