Terminate pgsql database sessions before dropping users/databases.

This commit is contained in:
Michael Hierweck 2014-08-28 19:27:49 +02:00
parent 278954bb97
commit c031f5004c
2 changed files with 2 additions and 0 deletions

View File

@ -45,6 +45,7 @@ public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
assert db.getInstance().equals("pgsql"); assert db.getInstance().equals("pgsql");
JDBCProcessor aJDBCP = createPostgreSqlAdminProcessor(); JDBCProcessor aJDBCP = createPostgreSqlAdminProcessor();
String aName = AbstractEntity.escapeString(db.getName()); String aName = AbstractEntity.escapeString(db.getName());
aJDBCP.addSQL("SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname='" + aName + "'");
aJDBCP.addSQL("DROP DATABASE " + aName); aJDBCP.addSQL("DROP DATABASE " + aName);
return aJDBCP; return aJDBCP;
} }

View File

@ -40,6 +40,7 @@ public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
assert dbu.getInstance().equals("pgsql"); assert dbu.getInstance().equals("pgsql");
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor(); JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
String aName = AbstractEntity.escapeString(dbu.getName()); String aName = AbstractEntity.escapeString(dbu.getName());
aJDBCP.addSQL("SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE usename='" + aName + "'");
aJDBCP.addSQL("DROP USER " + aName); aJDBCP.addSQL("DROP USER " + aName);
return aJDBCP; return aJDBCP;
} }