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

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...

Related

Unable to remotely connect to postgres server on vps

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?

Connection refused to PostgreSQL server

I am currently setting up a postreSQL server on my Windows computer.
I want to create my first database, but couldn't create the createdb function due to a password authetification failed. Thus I found the following question on this website:
How to configure postgresql for the first time?
However, I think I forgot the ; at the end of :
ALTER USER postgres with encrypted password 'xxxxxxx';
And now, when I try to launch psql, I have the following errors:
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Active code page: 1252
psql: 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?
Press any key to continue . . .
Any idea of what I could do to solve the problem?
Do you think it is really the missing semi column that caused the problem?
Do you have any tutorial on how to setup a postgreSQL database on Windows? All the one I found until now were for Linux only.
The error you're getting appears to be from Postgres not currently running, rather than an authentication error as you're presumed. The PSQL client or whatever PG client you're using is attempting to establish a connection on the default port but nothing is there.
If Postgres isn't currently running, try finding it (Via CTRL-Alt-Delete). If it's running, try terminating it and starting it up again. Hopefully that fixes the problem... Otherwise your port 5432 might be blocked for some reason.
If all fails, I am still skeptical the parentheses could cause this error because it's not an authentication error. Try to reinstall Postgres with a clean install.

Create dump file using pg_dump tool

I'm trying to create a dump file using the pg_dump tool as specified here, but I keep getting this result:
$ PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser app_db > app_db.dump
Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?
I'm using OSX Lion for a rally sort time, and still don't know how can I open or close ports, so, If that's the issue, please tell me how can I open it, if the problem is other thing, please tell me what it is (and how to solve it)
Thanks
You need to have postgresql installed and running

Can't connect to SQL Server via Microsoft SQL Server 2012 JDBC Driver

This is weird. I'm on a Mac OS X 10.7.5 64-bit host running VirtualBox 4.2.6. I've got a Windows 7 SP1 guest (64-bit) with bridged networking running Microsoft SQL Server Express 2012. I configured SQL Server to use TCP/IP on port 1433, not dynamic ports (setting is blank, not 0). The Windows 7 guest has IPv4 address 192.168.99.132 and Windows Firewall is turned off.
I downloaded the Microsoft SQL Server 2012 JDBC driver along with Squirrel SQL client 3.4.0 for both Windows and Mac. When I run Squirrel on the Windows 7 guest OS itself, I can connect to SQL Server just fine via the Microsoft JDBC driver using the guest machine names of either "winny", "localhost", or "192.168.99.132" (JDBC URLs like jdbc:sqlserver://winny\SQLEXPRESS:1433;databaseName=vha). However, when I try to connect to SQL Server from Squirrel running on the Mac host, I get an exception (see stack trace below).
Here's the weird part. If, from the Mac host, I use the jTDS SQL Server driver (version 1.2.7 because I'm using JDK6, so can't use jTDS 1.3.0 -- that version is JDK7 only), I connect right away with the JDBC URL jdbc:jtds:sqlserver://192.168.99.132:1433/vha.
Any ideas why the Microsoft driver fails but jTDS succeeds from a remote host? The only piece of infomration missing from the jTDS URL that's in the Microsoft one is the instance name ("SQLEXPRESS"). And yes, I've tried the Microsoft URL with and without the instance name.
Java version on the Mac host is:
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)
Java version on the Windows 7 guest is:
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)
Stack trace when connecting from Mac host to Windows 7 guest:
java.util.concurrent.ExecutionException: java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:232)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.awaitConnection(OpenConnectionCommand.java:132)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$100(OpenConnectionCommand.java:45)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$2.run(OpenConnectionCommand.java:115)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:171)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$000(OpenConnectionCommand.java:45)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$1.run(OpenConnectionCommand.java:104)
... 6 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(SQLDriverManager.java:133)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:167)
... 8 more
In theory you also need the instance name in the jTDS connection string (e.g. appending ";instance=SQLEXPRESS") -- but I am not familair with jTDS and I might be wrong, but if you are not setting that and you are connecting then perhaps you are connecting to something else?
You showed your jTDS connection string above with the IP address and the Microsoft one with the server name "winny" (jdbc:sqlserver://winny\SQLEXPRESS:1433;databaseName=vha) -- have you tried the IP address? (jdbc:sqlserver://192.168.99.132\SQLEXPRESS:1433;databaseName=vha)
Things I usually try:
Verify the port -- can you telnet to localhost port 1433 on the host machine
Verify the network -- make sure the host responds to ping -- can you ping it by name from the client? By IP Address?
Verify port 1433 is open -- can you telnet from the client to the host on port 1433?
Because you can connect from the Mac client with jTDS you should be able to do all three of these already but it would be worth double checking.
You could also try hardcoding the port 1433 (change it from blank) on the server -- maybe another instance of SQL exists? See also http://support.microsoft.com/kb/287932
Here are some steps I usually go through, maybe this will help:
(Server) Open SSMS, right-click the SQL Server, Properties; verify that Allow Remote Connections is checked. If not, check and restart SQL Server.
(Server) Open SQL Server Configuration Manager (Start -> SQL Server -> Configuration Tools)
Verify that TCP/IP is Enabled
For default instance verify that static port 1433 is set (Note: a named instance will have a backslash, e.g. something like MYSQLSERVER\MYINSTANCE, whereas a default instance is identified with just the server name.)
For named instance choose another static port, e.g. 1434+, and set it as the static port. Only one per instance – do not re-use them on the same machine.
Restart SQL Server service
(Server) Verify that what you did worked so far; on SQL Server machine:
Open CMD prompt, "telnet localhost 1433" (change 1433 to other port number as appropriate)
If you get a blank screen that is "hung", it worked!
If you get an error, it did not work. Go back to square 1.
Try the same thing but using the machine name instead of localhost
(Server) Configure Windows Firewall to add an exception to TCP port 1433 (or whichever port you chose in step 2)
(Server) If using named instances, add another exception to UDP port 1433 as well (for the SQL Browser service, which uses UDP not TCP – also note SQL Browser Service ALWAYS uses port 1433 even if you chose a different TCP port for your instance in step 2)
(Client) Verify from another machine on the same network
Open CMD prompt, "ping " – if you get responses, the machines can see each other. Even if you do not get a response, try the next step – Windows 7 for example may default to NOT reply to echo requests (ping)
Open CMD prompt, "telnet 1433" (change 1433 to other port number as appropriate)
If you get a blank screen that is "hung", it worked!
If you get an error, it did not work. Go back to square 1.
(Client) Now try and connect to the SQL Server from another application like Excel
(Client) See also http://blogs.msdn.com/b/dataaccesstechnologies/archive/2010/01/29/testing-connection-to-sql-server-from-a-service-running-under-local-system-account.aspx for other errors
Step 1: Download jtds.jar from http://sourceforge.net/projects/jtds/files/
Step 2: Add the jar into eclipse or any IDE.
Step 3:
String driver="net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString="jdbc:jtds:sqlserver://127.0.0.1:1433/database_name;encrypt=false;user=sa;password=yourpassword;integratedSecurity=true;instance=SQLEXPRESS;";
String username="sa";
String password="yourpassword";
OR
String connString="jdbc:jtds:sqlserver://192.168.1.198:1433/database_name;encrypt=false;user=sa;password=yourpassword;";
String username="sa";
String password="yourpassword";

Remote connect to SQL Server Standard Edition from PHP/FreeBSD

Unable to connect to our company MSSQL server from one of our FreeBSD servers.
# telnet 192.168.1.51 1433
Trying 192.168.1.51...
telnet: connect to address 192.168.1.51: Connection refused
telnet: Unable to connect to remote host
No firewall running on the MSSQL server, and i have opened the default port on the BSD-FW
00210 allow tcp from any to any dst-port 1433 in
00215 allow tcp from any to any dst-port 1433 out
Any ideas on this?
The specifics of the MSSQL server running on a Windows Server 2003
Test whether you can connect from another non-local machine. If not TCP connections may not be enabled for SQL Server. Here are instructions for enabling TCP/IP Connections with SQL Server 2000
I updated it MSSQL to Service Pack 4, and i'm now able to telnet to the server on the specified port. And also connect to the server from PHP with pdo_dblib

Resources