Try breaking your data insertion into smaller batches or you can optimise the import operation either by adjusting the batch size or by using bulk loading( functionality (COPY INTO command) which is highly optimized for large volumes of data)