简体   繁体   English

DBMS 事务:它们存储在哪里?

[英]DBMS Transactions: where are they stored?

I'm using sequelize, and using transactions, but I have to make a lot of inserts every night, my fear is if these inserts/changes are stored in memory until transaction is commited and can crash the server and lost it all.我正在使用 sequelize,并使用事务,但我每晚都必须进行大量插入,我担心如果这些插入/更改存储在 memory 中直到事务被提交并且可能使服务器崩溃并丢失所有内容。 Or if these changes are stored and handled by the DBMS (in this case i'm using aurora/postgresql) and i don't have to worry about nothing或者,如果这些更改由 DBMS 存储和处理(在这种情况下,我使用的是 aurora/postgresql),那么我什么都不用担心

Help!帮助!

I'm usings express 4, sequelize 5 and this will run maybe on a cronJob This is an abstract example of my structure我正在使用 express 4,sequelize 5,这可能会在 cronJob 上运行这是我的结构的一个抽象示例

const db = require('../database/models')

class Controller {
    async test (req, res) {
        let transaction = await db.sequelize.transaction()
        try {
            await this.storeData(req.body, transaction)
            await transaction.commit()
            res.status(200)
        } catch (error) {
            if (transaction) await transaction.rollback()
            res.status(400)
        }
    }

    async storeDate (params, transaction = null) {
        // Calculation of the data to insert
        var records = []
        await Promise.all(records.map(async item => {
                await db.MyModel.create(item, { transaction })
            }
        ))
    }


A transaction feature in Sequelize is just a wrapper over a DB transaction and, of course, a transactional DBMS has a transaction log and stores all ongoing transaction operations there. Sequelize 中的事务功能只是对数据库事务的包装,当然,事务性 DBMS 具有事务日志并将所有正在进行的事务操作存储在那里。
One edge case would be if you really like to take too many objects and insert them all in one operation so I'd recommend to divide a huge amount of rows into smaller batches.一种极端情况是,如果您真的想获取太多对象并将它们全部插入一个操作中,那么我建议将大量行分成较小的批次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM