'Add columns to a table that has more than 300K records

I am working on a SpringBoot application which connects to a Postgres database present on Azure platform.

I added a new SQL script which Flyway will try to execute during the application deployment. Then the CPU usage of azure database does not change much but the number active connections goes very high and I see a lot of errors "Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException"

The SQL script I am trying to run is on a child table which has around 320K records:

ALTER TABLE TABLENAME_1
    ADD COLUMN_5 VARCHAR(50),
    ADD COLUMN_6 BOOLEAN;

How can I make sure the script completes quick without causing so many new active connections. The script also seem to be taking more time to complete. I assumed 300K in a child table is not huge amount so the script will run very quick



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source