Unable to remotely connect to postgres server on vps - database

I set up a postgres 14 db on my windows server 2016 vps. I configured the port to be 5432 and set listen_addresses = '*' inside postgresql.conf and added host all all 0.0.0.0/0 md5 and host all all ::0/0 md5 to pg_hba.conf. I checked that the service was indeed running when opening the windows Services application and I restarted the service after every change. I also added a new inbound rule on the firewall to allow port 5432. And I've tried restarting my entire vps.
Whenever I try to connect to the postgres server remotely (psql -h <my vps ip address>), I get met with Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections?. Am I somewhere missing a step?

Related

Getting: Could not connect to Server - Connectin refused with postgres

I have Postgres 13 and pgAdmin installed on my Windows machine. It worked for like ~six month, until I hat do restart my machine. After restarting the computer (which I had not done because there was an update), I am trying to connect to Postgres via pgAdmin as always and I get this
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
Some answeres on stackoverflow suggest, to edit the postgresql.conf file which I a) do not find in my postgres installation and b) I think is not the correct solution for me because it worked without any problem until I restarted my machine.
Why is that? It feels like postgres is not starting? Although this is a wild guess...

Unable to connect to SQL Server database from another machine

I need to access a SQL Server database which is installed on one machine and I want to access it from another machine. I have tried below options and nothing work
I have enabled TCP\IP with IPALL as 1433 in SQL Server Configuration manager
SQL Server and SQL Server Browser services are running, restarted after modified the configuration
Added SQL Server and TCP port to Windows firewall (allowed apps) as domain and public
Used
sqlcmd -S servername,portname -U username -P password -d database
What am I missing? On my local machine, it is working

Remote PostgreSQL connection from external client on Windows

i am trying to connect to a PostgreSQL DB which is hosted on Windows 10 machine.
I have changed the following settings on ini file:
listen_addresses = '*' is set in postgresql.conf
host all all 0.0.0.0/0 md5 is set pg_hba.conf
I have enabled the 5432 port for TCP/IP connections and I have checked that it is listening.
Results:
IT WORKS when I try to connect to the DB from a machine that is under the same network as the machine hosting the server using the private IP for connection
IT DOES NOT WORK when I try to connect to the DB from a machine outside the network of the machine hosting the server, using the public IP for connection
I have seen several topics about it, but the only suggestions are to modify init file and add a rule to open TCP/IP on 5432 port.
Could you please help?
thanks!

SQL server - Client Connection works in one network not on another

We cannot access from a client computer (Client) to a SQL Server computer (Server) on network A but successfully on another B. The Server computer has SQL Server 2019 installed, the Client computer has SQL Native Client 11.0 installed. We can connect from this client to the server in on network A either using sqlcmd, udl interface, or Telnet. But on a different network B, we cannot connect from the same Client to the same Server! What network configuration can avoid a SQL Server connection?
Server Parameters:
1. We defined firewall rules to allow inbound connection on ports 1433 for TCP and 1434 for UDP. We verified that that is the case on the Server by using "netstat -aon". We disabled the Norton Smart Firewall.
2. We have set this rule to apply to all profiles: Domain, Public, Private.
3. We ensured that all protocols for SQLEXPRESS are allowed and enabld in the SQL Server Configuration Manager, specifically TCP/IP.
4. We have enabled SQL Server Browser.
5. We have restarted all services multiple times after our configuration changes. We have even restarted the machine.
6. We made sure that the Server is accessible remotely and using SQL Server Authentication.
7. We reset both the modem and the router for both Networks before testing.
8. We confirmed both the Computer and the SQL Instance names in the SMSS logins and logs.
Tests we did on Network A:
1. We can ping the Client from the Server, the Server from the Client both with IP addresses and computer names (On Server: "ping -a ClientIP/ComputerName", On Client: "ping -a ServerIP/ComputerName". Both results with "Reply...").
2. We can access the database in the Server using SSMS both with Windows Authentication and SQL Server Authentication.
3. We cannot access to Server from the Client by Windows Authentication either by using "sqlcmd -S Server\sqlexpress -E".
4. We cannot access to Server from the Client by SQL Server Authentication by using "sqlcmd -U User -P Password -S Server\SQLExpress".
On the other hand, when these computers are in Network B, without changing anything we can connect to Server from the Client.
Here are the error messages we get:
sqlcmd -U User -P Password -S Server\SQLExpress
By default named instances use dynamic ports, which you're not allowing through the firewall.
The best solution is probably to simply configure the SQL Server instance to listen on the fixed port 1433, then you don't need to use an Instance Name or explicit port to connect.
To do this us SQL Server Configuration Manager to configure the instance to listen on port 1433 on all IPs. It should look like this:
With Dynamic Ports blank, and 1433 in the TCP IP port.
Then restart the SQL Server instance and in the SQL Server Logs you should see a message like
Server is listening on [ 'any' <ipv4> 1433].
Then try to connect like
sqlcmd -U User -P Password -S Server
And you can test with Powershell
PS C:\> test-netconnection Server -port 1433
If you do this you won't need the SQL Browser Service or the firewall rule for port 1434.

Use SQL Server Management Studio to connect remotely to an SQL Server Express instance hosted on an Azure Virtual Machine

Initial Attempt
I have an Azure VM with Windows Server 2012, on which I just installed SQL Server 2012 Express Database Engine component. Then, I followed the instructions here to connect remotely with SQL Server Management Studio.
Create a TCP endpoint for the virtual machine
Open TCP ports in the Windows firewall
Configure SQL Server to listen on the TCP protocol
Configure SQL Server for mixed mode authentication
Create SQL Server authentication logins
Determine the DNS name of the virtual machine
Connect to the Database Engine from another computer
After step seven I received the following error:
A network related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
(Microsoft SQL Server, Error: 53)
What else do I need to configure before connecting remotely?
Troubleshooting
I have been following the troubleshooting instructions here. Each blockquote below is a step described that that link.
Confirm the instance of the SQL Server Database Engine is installed
and running.
Done. We installed SQL Server Express, and it is running as a named instance called SQLEXPRESS.
If you are attempting to connect to a named instance, make sure the
SQL Server Browser service is running.
Done. We followed the steps here to turn on the SQL Server Browser service.
Get the IP Address of the computer.
Done. We will use these later for testing connectivity and maybe for setting up a static port for SQLEXPRESS.
10.241.62.155
fe80::45c:8c29:e19f:f78b%15
Get the TCP port number used by SQL Server.
Done. The SQL Server Management Studio server logs showed that the server was listening on port 49169.
Enable Protocols
Done. We had already enabled TCP/IP in the configuration manager, but we restarted the SQL Server Service just in case.
Testing TCP/IP Connectivity
Done. We used tcping.exe to test connectivity (cmd ping doesn't work quickly with Azure.) We were able to connect to port 80.
tcping.exe buddha.cloudapp.net > successful
tcping.exe buddha.cloudapp.net 80 > successful
Testing a Local Connection
Done. We used sqlcmd.exe from the command prompt and were able to connect locally via TCP with a username and password.
sqlcmd -S Buddha\SQLEXPRESS (success via shared memory protocol)
sqlcmd -S tcp:Buddha\SQLEXPRESS (success via TCP)
sqlcmd -S tcp:Buddha\SQLEXPRESS -U sa -P (success via TCP with username)
sqlcmd -S tcp:10.241.62.155\SQLEXPRESS -U sa -P (success with internal IP)
Opening a Port in the Firewall
We opened the port on which we SQLEXPRESS listens. The server logs (above) showed that SQLEXPRESS was listening on port 49169, but this is just one of many dynamic ports, and we wanted to set up the static port 1435.
Use WF.msc to create an inbound TCP rule for port 1435.
Use Azure Management Portal to create a TCP endpoint for port 1435.
The troubleshooting instructions also say:
If you are connecting to a named instance or a port other than TCP
port 1433, you must also open the UDP port 1434 for the SQL Server
Browser service.
Since we are connecting SQLEXPRESS (a named instance), we needed to open port 1434 for UDP.
Use WF.msc to create an inbound UCP rule for port 1434.
Use Azure Management Portal to create a UDP endpoint for port 1434
Further research about connecting to named instances revealed dynamic port issues. The reason why we are using port 1435 (static) instead of port 49169 (one of many effective options.)
Instances of SQL Server Express, SQL Server Compact, and named
instances of the Database Engine use dynamic ports. To configure these
instances to use a specific port, see Configure a Server to Listen on
a Specific TCP Port (SQL Server Configuration Manager). and
here.
Done. We went to SQL Configuration Manager > SQL Server Network Configuration > Protocols for SQLEXPRESS > TCP/IP, we did the following.
Protocol Tab > Listen All > NO.
IP Addresses Tab > for each listed address
Enabled > Yes
TCP Dynamic Ports > Blank (delete the zero)
TCP Port > 1435 (or your choice)
After restarting the SQLEXPRESS service, we again looked in the SQL Server Management Studio logs, and found that the Server is Listening on port 1435!!! Hooray!
Testing the Connection
Done. We opened SQL Server Management Studio on our local (non-Azure) computer and connected.
buddha.cloudapp.net,1435 OR buddha.cloudapp.net\SQLEXPRESS
sa
password
Success.
Here are the three web pages on which we found the answer. The most difficult part was setting up static ports for SQLEXPRESS.
Provisioning a SQL Server Virtual Machine on Windows Azure. These initial instructions provided 25% of the answer.
How to Troubleshoot Connecting to the SQL Server Database Engine. Reading this carefully provided another 50% of the answer.
How to configure SQL server to listen on different ports on different IP addresses?. This enabled setting up static ports for named instances (eg SQLEXPRESS.) It took us the final 25% of the way to the answer.
The fact that you're getting an error from the Names Pipes Provider tells us that you're not using the TCP/IP protocol when you're trying to establish the connection. Try adding the "tcp" prefix and specifying the port number:
tcp:name.cloudapp.net,1433
I too struggled with something similar. My guess is your actual problem is connecting to a SQL Express instance running on a different machine. The steps to do this can be summarized as follows:
Ensure SQL Express is configured for SQL Authentication as well as Windows Authentication (the default). You do this via SQL Server Management Studio (SSMS) Server Properties/Security
In SSMS create a new login called "sqlUser", say, with a suitable password, "sql", say. Ensure this new login is set for SQL Authentication, not Windows Authentication. SSMS Server Security/Logins/Properties/General. Also ensure "Enforce password policy" is unchecked
Under Properties/Server Roles ensure this new user has the "sysadmin" role
In SQL Server Configuration Manager SSCM (search for SQLServerManagerxx.msc file in Windows\SysWOW64 if you can't find SSCM) under SQL Server Network Configuration/Protocols for SQLExpress make sure TCP/IP is enabled. You can disable Named Pipes if you want
Right-click protocol TCP/IP and on the IPAddresses tab, ensure every one of the IP addresses is set to Enabled Yes, and TCP Port 1433 (this is the default port for SQL Server)
In Windows Firewall (WF.msc) create two new Inbound Rules - one for SQL Server and another for SQL Browser Service. For SQL Server you need to open TCP Port 1433 (if you are using the default port for SQL Server) and very importantly for the SQL Browser Service you need to open UDP Port 1434. Name these two rules suitably in your firewall
Stop and restart the SQL Server Service using either SSCM or the Services.msc snap-in
In the Services.msc snap-in make sure SQL Browser Service Startup Type is Automatic and then start this service
At this point you should be able to connect remotely, using SQL Authentication, user "sqlUser" password "sql" to the SQL Express instance configured as above. A final tip and easy way to check this out is to create an empty text file with the .UDL extension, say "Test.UDL" on your desktop. Double-clicking to edit this file invokes the Microsoft Data Link Properties dialog with which you can quickly test your remote SQL connection

Resources