So far I've been using localhost to connect to my database, and I've developed a Java program for connecting to it, using localhost:5432. Now I need to run my program from my NAS so it can run 24/7 using very little power. The NAS has postgresql installed already, but since the NAS is using it, I can't just change the data directory.

My question now is how I can connect to my database in Java, when I can't use localhost:5432? It should be noted that the disk with the database is connected to the NAS via USB, so I can still read it locally, without the need for using global IPs.