Joao,
I strongly agree with Tim’s recommendation to create a schema for each “domain.” In addition to the reasons below, the prefix model would seem to condemn your programs and programmers to using dynamic SQL to construct your business logic in a manner that would work for any domain, as the table names for each SQL statement would vary based on the domain.
Schemas are a solid approach to multi-domain design, they should work well for you.
Cheers,
- Evan
Joao Ribeiro <joao.ribeiro@xxxxxxxxxxxxx> writes:Hello,
We are using Postgres and we are with a issue. We have splited our tables by domain and each domain has a separated database, but we are trying to change it to a single database model. We have two options, create the same database in a single schema and add a prefix on each database domain or create a schema for each database (we have about 15 different models). In this approach we still want to do some joins and other queries cross schema, but we don’t know what would be the best approach :) Could you help us to know what would be the best approach ?
* having just one database with one schema and all domain databases with a prefix * having a schema for each domain (15 domains) with the domain databases (+/ 20 tables) (knowing that we do cross schema queries)
_____
It is probably just a matter of taste to some extent. I personally wouldfavour separate schemas over tables in same schema with prefixes becauseI think that gives you more flexibility i.e. easier to select all thedata associated with a domain as it is all in one schema. I also thinkit is easier to define security roles on a per schema basis rather thancomplex roles in the same schema, especially if you add new objectsetc. Auditing is also less complex.There are no issues with cross-schema queries/joins etc apart fromhaving to include the schema name in the query. Some people don't likethis because you have to type more and have a longer search_path, but ifthe alternative is table prefixes, the amount of typing is similaranyway.Essentially, the schema gives you a predefined unit which manytools/commands understand. If everything is in the same schema, then youwill often need to replicate some level of this functionality yourselfand then ensure it is maintained. Extent to which this has an impactreally depends on your use case. Tim-- Tim Cross
|