Home > front end >  Save simple information for a database within postgress
Save simple information for a database within postgress

Time:09-27

I have a multi tennant application which will use the SILO Model to save data (each tennant will get an own database).

Because tennant names could be redundand my database are with GUIDs: MyApp_[GUID].

Now I want to save simple but neccesary information for each database like a tennant name and 3 to 5 more informations.

Is there a simple way to write and get these data?

The only way I can think of is to create a special table for this with only 1 row - but it seems a bot of wasting.

CodePudding user response:

If you're looking for a simpler solution than a table per database (and having to deal with the awkward constraint that it must have exactly one row), you could

  • use a custom configuration parameter. You can change them with ALTER DATABASE. The downside is that you can only store strings, and that the settings might be overridden per session.
  • use a COMMENT on the database. The downside is that you can only store a single string per databasebase; the advantage is that it is automatically shown in many lists of databases such as psql's \l command
  • add your own columns to the pg_database system table. You should not mess with that, so it's a spectacularly bad idea even if you knew what you were doing, but in a relational model it's the closest to what you were asking for so I'd mention it for completeness.

I don't really advocate any of these solutions, although they do what you were asking for there's probably a better solution to your actual problem. It might be as simple a table of databases, possibly with a foreign key to pg_database, in an extra database shared by all tenants.

  • Related