Configure Multiple PostgreSQL DB in Django

HI everybody!
I can’t find anything understandable about this particular option. I’m keep studying Django since it’s only 2 years i’m working on it and i’m stuck.
I have a pc with my project django and postgresql db. By external application the db collects data (industrial field), with python / django i show this data via user interface. (This cannot change because i must keep the possibility to access locally to the pc with his db.)

Now the requests:

In some cases there are 2 or more PCs in doing the job. So i need a third pc (or a virtual machine) capable to connect to every pc in the same time e show the data (data pc 1, data pc 2, data pc 3… ecc ecc.). All in a local area network and with the same user interface i projected for the single pc.

  • How can i do that?
  • Is it possibile to have this without copy or replicate every data from dislocated db into my third db ?
  • How to handle the authentication ? I mean, of course i have login in my pc1, but how can i access with the same credentials to pc2, or to pc3 (and see every pc)

That would be a huge step for me and for resolve this implementation problem.
Not the last, because than i must face up to the “cloud problem”, but anyway… i’m really stuck and confuse.
Thanks a lot to everyone!

When you reference the “user interface”, are you talking about web pages here?

If you’re talking about a Django application, are you looking at building an internal web site for multiple people?

Why do you think a database must be on a local PC?

Have you ever deployed a web site before?

Yes, when i reference the “user interface” i’m talking about web pages.
Yes again, i’m talking about a Django application and i’m looking to build an internal web site for multiple people with different permissions (but this feature is already deployed, not canonically but it works).

The database must be on a local pc beacuse of the structure. This industrial pc is mounted on a industrial line, taking productions data. So the pc will be always online (24h) and my application must be a windows service (already done that with IIS).

I’ve never deployed a web site using django (online, like publish it via “Digital Ocean” or something like that, but my entire project is already working, except if i have 2 or more PCs, i must open as many web session as PCs and connect to them indipendentelly), also i still not can’t deployed to external resources beacuse of the data: different rules in different clients, diferrent security policy, different management of the network. The system must be alwasy “up”, but always available on lan though internet isn’t available (in fact: i’ve all resources locally in “static” nothing on CDN or external)

First, the obligatory docs link: How to deploy Django | Django documentation | Django

Cool. I would suggest then that when you’re talking about this application, keep in mind that it’s the browsers that connect to the web server, not the reverse. The web server does not “connect to the various PCs to show data”. The various PCs request data from the web server.

All connections to the web server are initiated by the client browser.

Again I think there’s possibly a terminology issue here.
Yes, I understand this is an internal application with internal-only access.
However, there is no technical requirement for the database to reside on the same PC as the web server. (In fact, it’s very common for the database to be on a separate server.)

Deploying a web site does not necessarily refer to making it generally available to the internet. I have now deployed more than two dozen Django sites so far. (Counting replications, the total is probably closer to 40.) Only two of them are accessible outside our office. All the others are internal-use only.

The point is that how a site is accessed doesn’t affect how you do the deployment. The requirements are effectively the same. (There are some exceptions. I’ve got a couple of sites that the deployment methodology would make some people cringe - but they’re appropriate for those specific environments.)

(Side note: I also work in the “embedded system” / “industrial engineering” field. A lot of my work is with traffic signal control systems.)

Thanks for the reminder it usefull. Must remember that and i’ll check the docs linked.

ok i understand the point. In fact, i already tried by virtual machines on my pc to put the database in one machine and the web server in other: it works, i adjusted the property db parameters in
The problem i cant’ figured out is: i know i have the possibility to set multiple db in, but how it works the correct reference to data in the db? How can i tell the software if i click on “PC2” it must shows the data in PC2’s db. Also… is it possible to compare data between dbs? Or this kind of connection manteins separate ambients?

See Manually selecting a database.

The parameter in the using clause doesn’t need to be a literal. It could be a variable.

Sure - how effective it’s going to be will depend upon how much data you’re talking about. (I’m not sure I’d want to try to do it with millions of rows of data - at least not in a view. I might consider doing something like that in a custom management command.) But nothing prevents you from retrieving data from DB-1, then retrieving the data from DB-2 and comparing it.

Thanks a lot, i’m starting to see in what way i must go.
Just few minutes ago, talking with collegues , comes another feature that flip me of the chair…
They don’t want to public any port of db outside the pc. I don’t understand very well, but i think they want some sort of call to web server inside the pc and pass data through the web… like some sort of api or… whatever, i don’t know… First thing first: i’ll try with one web server → to many dbs .
Then… any suggestions in case the specific is i can’t use the first method?

Can it be done? Sure. Should it be done? Not in my opinion. As far as I’m concerned, that idea provides no value at all, especially since you’re already talking about an internal environment that is isolated from the outside world.

Databases are designed around providing access to multiple remote (not same pc) connections and is going to be a lot more secure than any sort of user-written api.

1 Like