Accessing WSL postgresql server from Windows PGadmin - postgresql

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

Related

Postgres RDS access working on Mac, not Win 10

I have 2 computers (Win 10 and Mac) and need to access a RDS Postgres database. Connection is secure via a bastion host and ecs instance. When I configure TablePlus like this:
It works perfectly on the Mac but not on Windows. I checked a bit and recommendation is to create a tunnel via Putty to forward the port 5432 to a local one and then try to access the db with a local IP. But no success.
I would like to know if there is a specific setting in TablePlus or something I'm missing that will allow me to access the database on my Windows computer? I tried also with pgAdmin and same results.

Applying Entity Framework Core's Database Update to PostgreSQL server on a docker container with SSH

I'm a bit new to SQL and Docker. I've recently created a container for PostgreSQL on my Linux server that can be accessed by SSH. I am trying to manage it using the Entity Framework on .NET Core 2.2.
I'm trying to go by Npgsql's official documentation, but there isn't any provision for connection via SSH. The example they've provided for the connection string is:
optionsBuilder.UseNpgsql("Host=my_host;Database=my_db;Username=my_user;Password=my_pw")
Where:
my_host is set to the docker container's IP address.
my_db is the database name
my_user is the username on PostgreSQL
my_pw is the database password
I am also using this First EF Core Console Application as a tutorial. When I am attempting on the dotnet CLI:
dotnet ef database update
It keeps timing out, obviously because it can't connect to the server via SSH.
I've done my fair share of Googling with no luck. Can any of you please advise?
Edit FYI:
I am using a Windows 10 computer as a client
I am using Ubuntu Linux and connecting via OpenSSH
The Linux server has a Docker Container w/ PostgreSQL
I have successfully connected from my Windows 10 client using DBeaver
In principle, connecting to PostgreSQL isn't done over SSH - it's done directly via port 5432. You typically need to configure your container to expose that port (check the docker networking docs).
It is possible to use SSH tunneling to connect to PG (or any other service), but that's a pretty specialized mechanism to bypass firewalls and the like. You likely just need to expose port 5432 from your container.

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.

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.

Easiest way to access Postgress Database from Windows Machine?

I have a Postgres database on a linux server. I have root access which in turn can give me access to the database. In Windows you get PGAdminIII, which I would love to use to connect to the Linux server. I heard that tunneling might be necessary. I am not sure if that is true, or what it is really. Can anyone shed some light on the easiest way to get access to the database?
Tunneling is not strictly necessary. As long as you have port 5432 not firewalled, you should be able to connect to your Linux PostgreSQL server without much trouble.
You can check this from your Windows box by using this command from cmd console:
telnet linuxbox 5432
If you get black screen (not an error), then everything looks good and port 5432 should be open. Note that on Windows 7 you may need to enable telnet client (it is disabled by default) using this command:
pkgmgr /iu:"TelnetClient"
If your server is not located in your local network, or if you are concerned about security like somebody using network sniffer to watch your traffic, you should configure SSL/TLS on your PostgreSQL server - it is not very difficult to do, and completely free when using self-signed certificate.
Note that by default Postgres on Linux does not listen on network interfaces, you may need to enable it by editing postgresql.conf.