zoukankan      html  css  js  c++  java
  • odoo dbfilter,db_name 的配置,指定多个数据库

    个人偏向配置dbfilter,

    1. db_name指定多个数据库,可以使用逗号隔开,如db_name=db1,db2,但是db1,和db2,必须实际存在数据库中,不然启动报错,这就是我不喜欢使用的原因
    2. dbfilter使用正则表达式的方式可以指定多个数据库:dbfilter=db1|db2

    补充:

    dbfilter 有时候无法获取所有的数据库名:后来查到的原因是使用不同的数据库账号创建的数据库不能交叉使用,即使是superuser;
    获取所有数据库的代码,注意sql部分中有对datdba做筛选

    def list_dbs(force=False):
        if not odoo.tools.config['list_db'] and not force:
            raise odoo.exceptions.AccessDenied()
    
        if not odoo.tools.config['dbfilter'] and odoo.tools.config['db_name']:
            # In case --db-filter is not provided and --database is passed, Odoo will not
            # fetch the list of databases available on the postgres server and instead will
            # use the value of --database as comma seperated list of exposed databases.
            res = sorted(db.strip() for db in odoo.tools.config['db_name'].split(','))
            return res
    
        chosen_template = odoo.tools.config['db_template']
        templates_list = tuple(set(['postgres', chosen_template]))
        db = odoo.sql_db.db_connect('postgres')
        with closing(db.cursor()) as cr:
            try:
                cr.execute("select datname from pg_database where datdba=(select usesysid from pg_user where usename=current_user) and not datistemplate and datallowconn and datname not in %s order by datname", (templates_list,))
                res = [odoo.tools.ustr(name) for (name,) in cr.fetchall()]
            except Exception:
                _logger.exception('Listing databases failed:')
                res = []
        return res
    

    懂得,原来世界如此简单!

  • 相关阅读:
    1
    Dockerfile概述
    协议
    部署环境
    协议与数据2
    【笔记】刚到公司,初识dll
    C#Winform学习笔记
    VS2019添加VisionPro控件(此方法是大师分享的)
    VisionPro脚本
    Visionpro相机取像操作,.NET4.0
  • 原文地址:https://www.cnblogs.com/qianxunman/p/15118001.html
Copyright © 2011-2022 走看看