How to save large file effectively and quickly to postgreSql?

62 Views Asked by At

I have a problem saving a large file to the postgreSql. The file size is about 13 Mb. Now it takes about 9 second and i am using jdbcTemplate. I would like to get more good result. How could the process be improved? And is it possible? Code down below

CREATE TABLE IF NOT EXISTS attachment
(
    id         bigserial PRIMARY KEY,
    hash       text unique,
    attachment bytea not null,
    size       int,
    created    timestamptz DEFAULT CURRENT_TIMESTAMP
);

private static final String SQL_INSERT_ATTACHMENT = "INSERT INTO emails.attachment (hash, attachment, size) VALUES (?, ?, ?) ON CONFLICT (hash) DO NOTHING";

    public void saveAttachment(String hash, String attachment, Integer size) {
        jdbcTemplate.update(SQL_INSERT_ATTACHMENT, hash, attachment, size);
    }
0

There are 0 best solutions below