Terminate MySQL connections on shared host? - sql

I'm using MediaTemple's Grid Server (shared/grid hosting) to run some MySQL/PHP sites I'm writing and noticed that I wasn't closing one of my MySQL connections, which caused my site to error out:
"Too Many Connections"
I can't log in anywhere to close the connections manually.
Is that any way to close open connections using a script or other type of command?.
Should I just wait?

If you can't log into MySQL at all, you will probably have to contact your hosting provider to kill the connections.
If you can use the MySQL shell, you can use the show processlist command to view connections, then use the kill command to remove the connections.
It's been my experience that hung SQL connections tend to stay that way, unfortunately.

blindly going in an terminating connections is not the way to solve this problem. first you need to understand why you are running out of connections. is your max_connections setting selected to correctly match the number of max/anticipated users? are you using persistent connections when you really don't need them? etc.

Make sure that you're closing the connections with your PHP code. Also, you could increase the maximum connections allowed in /etc/my.cnf.
max_connections=500
Finally, you can login to a mysql prompt and type show status or show processlist to view various statistics with your server.
If all else fails, restarting the server daemon should clear the persistent connections.

Well, if you cannot ever sneak in with a connection, I dunno', but if you can occasionally sneak in, in Ruby it would be close to:
require 'mysql'
mysql = Mysql.new(ip, user, pass)
processlist = mysql.query("show full processlist")
killed = 0
processlist.each { | process |
mysql.query("KILL #{process[0].to_i}")
}
puts "#{Time.new} -- killed: #{killed} connections"

If you can access the command line with enough privileges, restart the MySQL server or the Apache (assuming that you use Apache) server - because probably it is keeping the connections open. After you successfully closed the connections, make sure that you are not using persistent connections from PHP (the general opinion seems to be that it doesn't create any significant performance gain, but it has all kinds of problems - like you've experienced - and in some cases - like using it PostgreSQL - it can even significantly slow down your site!).

Related

Rundeck project and job sync between 2 instances with backend as mysql cluster

I have set up 2 rundecks in 2 VMs and mysql cluster so Rundeck #1 on VM#1 connects to Mysql DB#1 and similarly Rundeck #2 on VM#2 connects to Mysql DB#2.
The problem now I have is whenever I am creating a project / job in rundeck #1 that I am not able to see it in rundeck #2. What should I do?
Any help will be appreciated
I would first try to switch the databases, i.e. Rundeck#2 connects to MySql DB#1 to see if the jobs are visible.
If this is the case, then you have a sync issue.
If jobs are still not visible, then i assume that there are some identification problems of the Rundeck instances.
Just my 2 cents.
The issue can be fixed by maintaining the default engine in my.cnf.
So in my case I just modified the /etc/my.cnf
Introduced the following option below the header [mysqld]:
default-storage-engine=NDBCLUSTER
And did a mysql restart and the tables sync started to happen.
delete the rundeck db before proceeding with any modifications.
Thanks and hope this helps everyone facing such issues.

How can I start go server permanently?

I've got problem with my Go server.
When I'm connected to my NAS via SSH and do ./gogs web, the server is starting. But when I close the SSH connection, the server is stopped.
How I can start my Go server permanently?
You have scripts in gogs allowing you to launch the server as a daemon:
scripts/init/debian/gogs (recently fixed with issue 519)
scripts/init/centos/gogs
That would allow the process to remain while the session is closed.
You have other options in issues 172.
This is not a Go-specifioc problem, what is happening is that the Go program is still attached to your terminal and when you log out, the kernel will trigger a SIGHUP to every binary still connected to that terminal session.
Your best option is probably to use nohup ./gogs web.
Second-best option would be to rewrite main, so that it intercepts and handles SIGHUP, stopping it from killing your program. However, doing so requires handling quite a few things properly (you really should close stdin, stdout and stderr; make sure all your logging is done through the log library, ...)

Got a minus one from a read call

I connect to a database with read only access using SQL developer. It's a TNS connection. I use a tnsnames.ora, forwarding port script and SQL Developer.
In the past, occasionally, when connecting, I get a error message
Got a minus one from a read call.
Vendor Code 0
If I do a reboot, it goes away. Another friend suggested changed the forwarding port which worked for him.
I recently upgraded to a new computer and now it seems that I am getting the error message consistently. Reboot or changing forwarding port does not help at all.
The port forwarding script contains something like this
putty -L (port):(machine name):1521
Does anybody have any idea? Thanks.
My port forwarding script forwards multiple ports. Somehow separating them into 2 smaller file, this error went away.
Check your sqlnet.ora file and comment if there is any entry like the below.
tcp.validnode_checking = yes
tcp.invited_nodes=(<hostname_1>, <hostname_2>)
Now reload your listener and check the connectivity from SQL Developer.
lsnrctl reload <SID>

Oracle 10g express home page is not coming up

I installed Oracle 10g express. Installation went well, But the home page is not coming up.
I can connect using sqlplus but not with Sql Developer.
I checked tnsnames.ora and listener.ora everything looks fine.
Listener is also started. I can always reinstall and see. But I thought better inquire the cause.
Regarding the home page. This is the address that comes up in browser. Localhost:8080
http://127.0.0.1:8080/apex
I did a netstat to see whether there is any port conflict for 8080, but that port is not in use.
Have anybody faced this issue?
Yes. It is practically a FAQ on the XE Oracle forum.
Firstly, can you connect to Oracle using
sqlplus user/pass
If so, Oracle is up an running (which appears to be your situation, but may not be for a future reader with a similar problem). If not, you can try
sqlplus / as sysdba
startup
Once Oracle is up, check that the listener can see the Oracle instance by
sqlplus user/pass#xe
If not, then either the listener is not up, or the 'listener does not know of the service'. Make sure the listener is started (lsnrctl, then start). Make sure the database is registered with the listener
sqlplus / as sysdba
alter system register;
Now you should be able to connect using the '#xe' syntax. Worthwhile verifying the embedded PL/SQL gateway is set up to use the 8080 port
select dbms_xdb.GETHTTPPORT from dual;
On Windows you can use netstat -ab to see if tnslsnr.exe is listening on the port.
Then I'd suggest looking at browser settings (specifically any proxy settings that might be forwarding your request to a machine that has no idea what to do with it) and firewalls (which could well be set to ignore or hide any access to the port).
I had the same problem. I tried this and it sorted out my problem...
1. goto start->run
2.type services.msc and hit enter
3.In the applet that opened, scroll down(in right pane) to figure out the option of "OracleServiceXE" and right click on it. 4. In general tab do->>> startup type "Automatic" and click the "start button".
5. Repeat step 4. for the option "OracleXETNSListener".
close the window.
now, i hope, the problem should be solved....
Check your windows firewall,If it is on it blocks the opening of the homepage.Either you shut down the windows firewall or allow these following ports :
1521: Oracle database listener
2030: Oracle Services for Microsoft Transaction Server
8080: HTTP port for Oracle XML DB and the Oracle Database XE graphical user interface
See software requirements in the below URL:
http://download.oracle.com/docs/cd/B25329_01/doc/install.102/b25143/toc.htm#BABEBCDB
It worked for me!
Try this ( I'm assuming Windows system )
using
netstat
without anyother parameter would tell you if port 8080 is already open.
Also you can try this:
telnet localhost 8080
If the server answers ( the screen goes blank [or black] ) then the server is up and running.
Try using your hostname instead of localhost.
See if you're using a proxy and not skipping the local addresses.
Also you can see what's the executable that starts the home page and see if it could start successfully.
Thanks for the response guys.
I finally figured out how to solve the issue, but not really the root cause.
Problem 1 - Can not login to oracle admin console.
It was the problem with not adding 127.0.0.1 in the IE intranet sites.
Go to tools>internet options>security>local intranet sites>advanced>
add http://127.0.0.1:8080/apex in the list.
It works fine after this.
But if I go back to the same place again and see the sites, I cant find the url I added sometimes back... Dont know why that is happening. May be some company security is messing up.
Anyways the admin console is now coming up.
Problem 2 - Cannot connect using SQL Developer.
After I did the fix for problem 1, this is also magically working.
I still don't know how security settings in IE affects SQL Developer?
Any comments on this?
hey guys one important fact if u r using IE7 (explorer7) then u wd face certain problem in using 10g, such as not displaying home page.
For Windows 8 simply click on Get Started With OracleXE.... When internet explorer opens up, select the View on the desktop option in the Page View icon (icon with a wrench).
You should now be able to view your page.
I had a similar problem, I was able to connect to SQLPLUS using terminal but on access in browser as it was showing error as you have described. So, I went back to terminal and mounted my database using
startup
and it resolved my problem. This might be the case.

Getting login failed for sa when I haven't changed the password

I've been developing a winforms app tied to sql server. I haven't rebooted in a while. Today i rebooted and now I can't log into sql. I used every account I know and their passwords including one that was working just before i rebooted and i get a 'Login failed' . I did take the database I use offline just before starting and I do have backups before then.
thoughts on what happened? Is there a way to bring the database back online OR somehow find out what passwords are? I even tried using windows authenication with me as an admin on the box AND sa (Yes, bad) and still no dice.
:-/ That's a rough place to be ... I wish you luck. Check out this blog post, not sure if you're using sql 2k5 or not, but if so, it may be helpful:
http://blogs.msdn.com/raulga/archive/2007/07/12/disaster-recovery-what-to-do-when-the-sa-account-password-is-lost-in-sql-server-2005.aspx
Have you checked to make sure that the service is actually running? Also are you trying to connect using IPC, TCPIP or named pipes? Whichever way make sure it's enabled in the configuration tools.
Since admin's on the box are SQL admins the only thing I can think of is that the service is not running.