How can I connect to local database on a windows machine from a tomcat server on Ubuntu in a virtual machine - postgresql

I am trying to set up a server in a virtual machine using the Oracle VirtualBox. I use Ubuntu 18.04 LTS in the VirtualBox. I use PostgreSQL as my database.
In my Tomcat, I have a property file where I provide the database URL and password. I want the tomcat that is set up in the VirtualBox to be able to access a local database that is set up using PGAdmin in my Windows machine in which the VirtualBox is installed.
Is it possible to do that?

When connecting to a SQL server DB running on my host machine from a VM, I use the IP address to connect.
You can run ipconfig (or your OS's equivalent) to find the IP address of the machine serving the DB, then try to connect from your host machine via that IP address instead of the machine name.
There might be some VM-specific settings you need to tweak to allow network access between the VM and host, refer to this post for more info. Usually I have to set my VirtualBox network mode to bridged adapter.

Related

How can I connect to a Postgresql database (which is on my local machine) using dbeaver on my virtual machine?

I have created a postgresql database on my local machine and I want to connect to that database on my virtual linux(centos) machine. But I could not figure it out. What should I type in the host section ? (Link here)
You need to port forward the localhost to the virtual machine using something like this you need to enter your host and guest IPs and ports accordingly.

Access Postgres on Mac from Windows 10 on VMWare

I have postgres running on my Mac (OSX 10.13.1). Running Windows 10 in a virtual machine on VMWare Fusion (8.5.8). Requirement is to access a postgres database from an app running on the Windows VM, but I'm having trouble finding documentation and specific instructions about how to configure Postgres appropriately--appreciate any help.
The connection should be secure, and limited to local if possible--really don't want to expose a connection to the external internet.
I gather that there are some configuration settings that need to be made in postgresql.conf as well as in pg_hba.conf.
Tried adding listen_address = '*' to the postgresql.conf file, and added host all all xxx.xx.xxx.x/24 md5 (where x's indicate the IP address for the virtual machine) in the pg_hba.conf file.
On the setup screen for the postgres driver on Windows, I'm not sure how to set the driver up to find the database.
Also: I found an IP address for the VM on the Mac terminal, but does that change every time the machine restarts, or can it be set to a constant value? I.e. I don't want to have to reset the configuration every time the machine restarts.
Thanks in advance.

pgAdmin can't connect to database server

Database server os = Ubuntu 16.04
client machine= Windows os 8.
we are not able to connect database server from pagAdmin which I have installed on my laptop (while its prompting for password).
Have you configured "pg_hba.conf" file in the server for remote access? IF not, you need to add following in the file
# vi /var/lib/pgsql/data/pg_hba.conf
host all all 192.168.101.20/24 trust
192.168.101.20/24 is just an example, you need to write clients IP and port.

How to utilize GUI tool of pgadmin using vagrant

I have installed postgresql upon a vagrant ubuntu box and also companied control console with
sudo apt-get --assume-yes install pgadmin3
the tool is installed under /usr/bin
but I can not open pdadmin3 in the virtualbox due to the error
Error: Unable to initialize gtk, is DISPLAY set properly?
Could I possibly do this kind of thing in vagrant virtual box ? Or some work around
Run PgAdmin locally on your main desktop and connect to PostgreSQL on your Vagrant VM over TCP/IP.
The host can connect to guests if properly configured. You'll need to (a) ensure that Vagrant has suitable networking from host to guest, either using NAT and port forwards or using a virtual bridge; (b) ensure that PostgreSQL on the guest listens on all interfaces for TCP/IP connections using listen_addresses in postgresql.conf and (c) ensure that PostgreSQL on the guest is configured to allow connections from remote peers in pg_hba.conf.
Alternately, PgAdmin supports ssh tunnels. If you can ssh to the virtualbox you can configure PgAdmin to ssh to it too, then make a local PostgreSQL connection.
Personally I prefer to instead just use the psql command-line client for PostgreSQL directly on the VM. Way less hassle.

Can't connect to a remote DB2 using a virtual machine

I have a perl script running on a Debian virtual machine on VMWare. This script is supposed to connect to a DB2 database running on my Windows 7. When I try to connect with that string:
my $dbh = DBI->connect("dbi:DB2:DATABASE='nmap'; HOSTNAME='192.168.252.167'; PORT='50000'; PROTOCOL=TCPIP; UID='db2admin'; PASSWORD='password'";
The program returns an error and it says that db2 is not installed on Debian. How can I tell my script that the DB is running on a different machine? The virtual machine has a bridged connection with 192.168.252.178 as IP address.
You need the DBD::DB2 package installed on the client machine (your Debian VM in this case) if you want to connect to a DB2 database with DBI.