While the SSH tunnel functionality in Navicat seems to work well if postgresql is running on a TCP port, it seems impossible for me to make it work when postgresql is accessible using a file socket?!
Is this true, or I am missing something?
Correct. There's no sensible way to connect to a unix socket over a ssh forward. You could possibly use socat to link a forwarded tcp/ip port to a unix socket, but I wouldn't bet on it working.
Just use TCP/IP.
Related
I have PostgreSQL 9.4 running on a Linux VPS, and I need to be able to connect to it over SSH from both Linux and Windows clients. (I will later need to connect to multiple servers, and so that all clients use the same port numbers, I'm forwarding to port 5551 for the first server, then I will use 5552, 5553, etc.)
From a Linux client I just run ssh -fNg -L 5551:localhost:5432 user#remote1.com and connect to localhost:5551 with PGAdmin3 or any other client app. Works great.
On Windows, I'm using PuTTY and Pageant. I got the connection to user#remote1.com via terminal working, then I went to the SSH Tunnels and added L5432 localhost:5551. Terminal connection still works, but when I try to connect with PGAdmin3 to localhost:5551 I get an error:
could not connect to server: Connection refused (0x0000274AD/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5551?
I resolved it. Like many things, this is obvious in hindsight. I had things backward in the SSH Tunnels setup in PuTTY. It needs to be L5551 remote1.com:5432
I just installed PostgreSQL on Snow Leopard and can't connect to the database server via pgAdmin 3.
I'm on my local machine, however I keep getting this error:
Could not connect to server: connection refused. Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5423?
I'm a bit of a noob when it comes to Postgres, so I'm not really sure what the problem is.
I can, however, log in through the command line, via psql -U postgres, and start and stop the server successfully.
Any help would be much appreciated.
The error message pointed out that you tried to connect to server on port 5423. However, postgres server listens on 5432 by default.
From your above comment (SHOW port; gives me "5432"), I think you need to change the port to 5432!
UPDATE: Tuan Dang spotted it. I'll leave this answer in place in case it helps someone else for whom the issue isn't quite the same.
Since you can connect via the command line, run:
SHOW port;
from psql. You'll probably see that the port is not 5432. You need to connect to the port PostgreSQL is actually running on from your application.
It's also possible that it just isn't listening on TCP/IP. Run:
SHOW listen_addresses;
to see what it's listening for.
The reason you can connect via the command line is likely to be because the command line psql you're using is connecting over a unix socket (since you didn't specify a host) and your app is connecting via tcp/ip.
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.
I like the pgAdmin III GUI software, but the GUI uses more bandwidth than SSH console.
psql is not interactive, without menus, tables list, etc.
Does exist some interactive text-mode tool to connect to PostgreSQL ?
There is no text-mode window-and-menu curses/ncurses style text mode interface for PostgreSQL; no ncurses equivalent to PgAdmin-III.
I strongly recommend learning psql and getting comfortable with it. You could use PgAdmin-III remotely as detailed below, but in the long run you'll be massively more productive if you learn psql.
Use PgAdmin-III via ssh tunnels or direct connection
You can always connect with PgAdmin-III via an ssh tunnel or remote TCP/IP connection. That way you aren't transmitting all the GUI data over the network, just the PostgreSQL protocol data.
For ssh, do something like:
ssh -L 15432:localhost:5432 remote_host
then while the ssh session is open, connect to localhost port 15432 to make a connection to the remote DB.
This will work even if the remote DB is only listening on 127.0.0.1. It'll also work if you ssh into a bastion host then connect to the DB server from there; just change localhost in the -L argument to the IP/hostname of the Pg server. For more information see the ssh manual, particularly LocalForward for IP forwarding, ProxyCommand for custom multilayer tunnels, and the -D option for dynamic SOCKS proxying.
It's even possible to use an ssh tunnel to connect to a server that's only listening for unix socket connections, by running socat to proxy between the unix socket and TCP.
None of this will work when you're connecting to a Windows host, but rdp2tcp can be used to tunnel TCP over RDP connections for similar effect. See this question.
Use psql
psql is pretty interactive. Though it isn't a GUI windowing interface, it's hardly just a scripting tool. It provides lots of visibility into the system with the \d commands, lots of info via \h, tab completion, paging, \e break-out command editing, and lots of other interactive features.
Use \? for psql help, and \h SQL_COMMAND for syntax of a particular SQL command, eg \h INSERT.
I have been using rockmongo as my client for mongodb on localhost for testing.
For prodction i DONT want a client online as this might reduce security.
Is there a client which will allow me to connect SSH? kind of like MySql Workbench?
or
Can rockmongo stay on my local computer and i connect to EC2 instance which has mongodb for production viewing?
or
Is there a better alternative to all of this?
My setup is a standard LAMP stack. willing to make any changes necessary.
MongoHub has the option to connect over ssh, but the app kind of sucks. It crashes a lot.
A more generic approach would be to just create your own ssh tunnel to your production server, and then connect over that through whatever client you want. The client won't care as long as it can make the connection.
On OSX/Linux, creating an ssh tunnel might look like this:
ssh -L 8080:127.0.0.1:27017 -f -C -q -N username#domain.com
This would open a local port 8080 which will forward the traffic to the localhost interface at the mongodb default port 27017 on the remote side. You would point your client at 127.0.0.1:8080 as if mongodb were running there locally.
Check some of these out - http://www.mongodb.org/display/DOCS/Admin+UIs
One workaround would be to set that file in a separate folder and make a .htaccess file that restricts access to only your ip address. Any requests not from your ip address would get denied access...