How to Set Up Multiple Databases Filtered Based on Domain Odoo 15

How to Set Up Multiple Databases Filtered Based on Domain Odoo 15

3 minutes, 9 seconds Read

One of the main features of Odoo is a single system that can contain multiple databases. A logged-in user can select their required database. There are different users in Odoo, it may be a portal user may website, or a non-logged user. In such cases, there should be a way for Odoo to identify which database should be used to load web pages or perform other operations/functions. For that purpose, dbfilter option is used.
That is one of the purposes of dbfilter: The requested hostname(domain) should be selected which is specified by dbfilter. 
In this blog, let us discuss how to set up multiple databases filtered based on domain Odoo 15
You can start the server with the following parameters –db-filter as: ‘%d’ or ‘^%d’ or even ‘^%d$’.
This value is a regular expression, you can use %d for the hostname part of the domain or %h for the full domain name
Regular expressions(Regex)
Regex is a set of strings. Here, for the purpose of adding dbfilter some of them are used. 
The ‘^’ means that it’s the start of the line and the ‘$’ is the end of the line, so ‘^%d$’ only filters the database with the name.
The server is started with:
dbfilter=’^%d’
.(Dot)
The dot matches any character except the newline in the default mode.
^(Caret.)
Caret can be used to match characters at the very beginning of a string.
$
$ can be used to match characters that may occur at the very end of a string or right before the end, just before the newline of a string. Also, if in multiline mode, it can also be used to match right before a newline.
For example, too matches both too and ‘toomany’, while the regular expression too$ matches only ‘too’. More interestingly, searching for too.$ in ‘too1ntoo2n’ matches ‘too2’ normally, but ‘too1’ in multiline mode; searching for a single $ in ‘toon’ however will net you two (empty) matches: one just before the newline, and one at the very end of the string.
*
This causes the resulting RE to match 0 or possibly more repetitions of the preceding RE with as many repetitions as possible. ab* will match ‘a’, ‘ab’, or ‘a’ followed by any number of ‘b’s.
Examples of Configurations
One can set dbfilter on the basis of subdomain and host. 
dbfilter = ^%h$ // Based on the host. 
When the hostname is the dbfilter one should make sure that the name of the database should be the same as the complete hostname.
 For example, if the name of the host is cybrosys.test.com then the name of the database should also be the same. This way, only this database will be visible for this particular request.
dbfilter = ^%d$ // Based on the domain.
While setting the domain as dbfilter instead, the database should be named cybrosys instead, this way it will only be visible to the requests from cybrosys.test.com,www.cybrosys.cu.com, etc.
* We can set dbfilter if there is only a single database, like
dbfilter=.*
* There is a need to set a dbfilter based on a condition, for example below only shows the database name begins with ‘admin’ 
dbfilter = ^admin.*$
Here the first subdomain after www: matching databases will only show.
Some examples are the database “admin” will be shown in the incoming request sent to www.admin.com or admin.cu.in,  But if it is not sent to
www3.admin.com or home.admin.com.
And also you can use the ‘or’ option to specify the exact number of database
dbfilter = ^admin1$| ^admin2$
In conclusion, The main purpose of dbfilter is to avoid asking/redirecting the user to select a database. It is used to directly detect and select a database for the user.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *