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
    

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

  • 相关阅读:
    Azure WAF防火墙工作原理分析和配置向导
    多云时代,海外微软Azure云与国内阿里云专线打通性能测试
    【Hololens】微软Hololens虚拟现实视频集
    【Azure】Azure学习方法和学习资料
    LINUX ON AZURE 安全建议(全)
    编程行业之网络贩卖生存
    Bootstrap
    我谷首开博客
    Noip2018普及组初赛试题解题报告
    奇yin技巧
  • 原文地址:https://www.cnblogs.com/qianxunman/p/15118001.html
Copyright © 2011-2022 走看看