How to utilize GUI tool of pgadmin using vagrant - postgresql

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.

Related

Troubles connecting PostgreSQL installed in WSL2 Ubuntu from the Windows 10 host

I'm having big troubles connecting to PostgreSQL, installed in WSL2 Ubuntu, from the Windows 10 host.
Here is what I have done so far.
Set password for postgres user.
Set the following in pg_hpa.conf
local all postgres md5
host all all 0.0.0.0/0 md5
Set the following in postgresql.conf
listen_addresses = '*'
Tested successfully that I can connect with psql -U postgres - so password should be set correctly.
When I try to connect using either pgAdmin or psql from the Windows 10 host, I get the following error.
error: could not connect to server: FATAL: password authentication failed for user "postgres"
Anything else I can change in pg_hpa.conf or other PostgreSQL configurations which might help?
I'm thinking that I could have something to do with that WSL2 has its own IP, even tough that connections from the hosts are made appear coming from localhost. The connection seems to be made, but authentication failed for some reason when it is not made from within Ubuntu.
I later tested with nc -l 5432 and for some reason, port 5432 didn't reach WSL2 on local host, but did on WSL-2 IP. If I use any other free port e.g. 5434 (free both on Windows and WSL-2) it works fine and I can connect to the PostgreSQL service on WSl-2 through localhost on windows.
I didn't change any options since the original posted question - only the port.
Update: It turns out that there indeed was a process from an old install of postgres on Windows which was listening on port 5432. This of cause explains it all. ..:/
As was pointed out by the original poster, ensure that you do not have a Windows service already running and listening on that port. In my case it was a PostgreSQL instance installed as a Windows service. Whatever the underlying networking support, it seems you can have a process/service listening on port 5432 in Windows as well as a separate Linux process listening on port 5432 from WSL2.
It was not enough to stop the Windows PostgreSQL service. Connecting from the Windows pgAdmin4 installation program failed. I also disabled the service from Microsoft Services console.
I needed to also stop and start the WSL2 postgresql. Only then was I successfully able to connect from my Windows pgAdmin4 installation program to the WSL2 postgreSQL

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

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.

Accessing WSL postgresql server from Windows PGadmin

I am running postgresql in WSL Ubuntu on windows. Everything is up to speed, my data is loaded and I wish to access the database through some graphical interface. I was thinking pgadmin4.
Is it possible to accomplish this through a windows install of pgadmin4? I installed pgadmin4 on windows and tried to connect the traditional way in the GUI through localhost but am not getting a connection. I figure there may be a special method here.
For everyone else stumbling across this: The best way to do this (that I know of) is to SSH into your local WSL and then configure the SSH in pgAdmin to that.
I have yet to figure out, how to use this remotely.
As long as postgres is running within your wsl2 instance (check with sudo service postgresql status) then within PgAdmin 4 (running in windows), all you need to do is click to "Register" a new server.
Then, while entering the Connection data, set host to localhost and port to 5432 (unless you specified unique port within your postgres instance when creating in wsl2.
See this answer for more detail
There is no special way needed, you should be able to get a connection. Just like your dev http ports are exposed to your browser on Windows, your db port should too.
I had to manually add localhost to pg admin though which is a bit weird.
Make sure your db service is up and running on Ubuntu, sometimes the db service is killed for no reason.
To see if your PostgresSQL service is up or not:
sudo service postgresql status
If it's not, start the service:
sudo service postgresql start

MongoDB Server Ubuntu 16.04

I've installed MongoDB on my Ubuntu 16.04 VPS and allowed connections through the firewall. When I run the server using the command (mongod), it starts without a problem and I can then connect to it (using RoboMongo as test application).
However, when I run the service automatically on startup (using systemctl), I cannot connect to it. I verified it was running, and could not run it myself as the address was already in use.
Does anyone have any experience with this, or any tips on how to solve the problem? The server will be running localhost only and I'm going to be using an SSH tunnel for testing purposes, so no authentication is necessary.
Anyone?
When you started mongod did you then provide a configuration file (using the --config or -f parameter)? If not then it defaults to listening on all interfaces.
The default configuration file which is used when starting the daemon with systemctl defaults to only listen on localhost preventing it from being available on the network. This is fine if you intend to connect to the server using a tunnel.

Allow incoming Postgresql connections to a Mac from a VM

I'm running Postgresql 9.4 on my mac on MacOS Sierra (host) and Ubuntu 16.04 in Virtualbox (guest) and I can't seem to figure out how to allow the guest to access the host without completely disabling the firewall. I want to just allow incoming connections on port 5432 for postgres and I have added the postgres executable and psql executable to the firewall options list and without turning the firewall completely off (which I don't want to do because I'll forget to turn it back on) I can't access postgres.
Does anyone know how to add a rule to allow connections in this version of the MacOS?
As a side note, I've already configured the pg_hba.conf files and everything else to allow connections on my private network and everything works with the MacOS firewall off, I'd just prefer to have it on with the rules in place.