I am working on IntelliJ IDEA 14.1.4, Recently we connected database to the Client and it was working okay, until some recent times when we start getting error
[2015-09-28 10:12:55] locked by transaction: #console:Oracle - <<DBName>>#localhost
Now we can't perform any transaction as we keep getting the same error. We tried googling the error but could not find anything to solve the problem. Any help would be appreciated!!!
I had this happen after a previous query I ran failed -- using PyCharm, not IntelliJ, but it is the same JetBrains system. I did not have Auto-commit turned on. Pycharm couldn't recover from the failed query for some reason, and it left an unresolved transaction active in the database. I disconnected from the database (hit the red stop button in the database window), and then I was able to resume with new queries with no problem. You might also try the rollback button at the top of the window with your SQL statements if reconnecting would cause you problems.
Putting up answer for the same comment.
I think there should be some row lock on the DB. if you have an Oracle DBA, check out for table/row lock. It can happen if the transaction exception occurred and rollback didn't happen properly or a transaction is still open for a longer time.
You can execute the following query to check for the same if transaction is pending.
SELECT COUNT(*)
FROM v$transaction t, v$session s, v$mystat m
WHERE t.ses_addr = s.saddr
AND s.sid = m.sid;
Additional resources :
Oracle: How to find out if there is a transaction pending?
How to find locked rows in Oracle
Consult with your DBA after your initial research. I'm not aware about releasing locks.
Related
I am trying to update one particular record in mysql table from java code. Update function doing lots of different activities including the update operation within the same transaction.
But here the same table row is not getting updated from outside (MySQL Workbench) or other transaction until the transaction for update gets committed. Its generating the following error.
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
Is there any work around to fix the issue? Please suggest.
The following delete statement is working fine in SQL developer but when executed using JDBC api executeUpdate() is not working.
After removing the where clause its working fine.
Delete from Tab1
where TRUNC(CREATED_TS) <= TRUNC(ADD_MONTHS(SYSDATE,-3))
I am not able to figure out the problem as no exception or error is printed.Only code execution is getting hanged at the executeUpdate() method.
Database : Oracle 11g
Java: 1.6
Since there is no Exception or Stack Trace one can only guess.
Probably the Exception is being swallowed in the Java code. Have a look at that and Print it if possible.
where TRUNC(CREATED_TS) <= TRUNC(ADD_MONTHS(SYSDATE,-3)) will prevent index on CREATED_TS (if there was one) from being used and may slow down the process. And a timeout may have occurred. I would check the connection/statement timeout settings on the Java side of the setup.
The issue was not with the delete SQL.The issue was with another session in which there was some uncommitted changes.Because of that the delete SQL from java code was getting hanged indefinitely. On issuing a commit on the another session ,java api executeUpdate() responded and it started working fine.
The question is similar to the issue as in the below link:
Oracle database is hanging infinitly in UPDATE queries
I am running a postgres query that takes more than two hours.
This query is executed using hibernate in a java program.
After about 1.5 hours the query stops showing up in the server status in pg_admin.
Since, the query disappeared from the list of active queries on the database, I am expecting a success or a timeout exception. But, I get none.(No exception) and my thread in stuck in the wait state.
I know the query has not finished because it was supposed to do some inserts in a table and I cannot find the expected rows in the table.
I am using pgbouncer for the connection pooling and the query_timeout is disabled.
Had it been a hibernate timeout I should have got an exception.
OS parameters on the DB machine and Client machine(Machine running java program)
tcp_keepalive_time is 7200 (seconds)
tcp_keepalive_intvl = 75
tcp_keepalive_probes = 9 (number of probes)
Both the machines run RHEL operating system.
I am unable to put my finger on the issue.
I found that the issue was caused due to the TCP connection getting dropped and the client still hanging waiting for the response.
I altered the following parameters at OS level:-
/proc/sys/net/ipv4/tcp_keepalive_time = 2700
Default value was 7200.
This causes a keep alive check at every 2700 seconds instead of 7200 seconds.
I am sure you would have already looked at the following resources:
PostgreSQL Timeout Docs
PgBouncer timeout (you already mention).
Hibernate timeout parameters, if any.
Once that is done, (just like triaging permission issues during a new installation, ) I recommend that you try the following SQL, from different scenarios (given below) and ascertain what is actually causing this timeout:
SELECT pg_sleep(7200);
Login to the server (via psql) and see whether this SQL times-out.
Login to the PgBouncer (again via psql) and see whether PgBouncer times out.
Execute this SQL via Hibernate (via PgBouncer), and see whether there is a timeout.
This should allow you to clearly isolate the cause for this.
Our Postgresql application is getting Hibernate error: org.hibernate.util.JDBCExceptionReporter - ERROR: deadlock detected. One of the ways recommended to deal with this problem is setting transaction timeout
(Hibernate Reference Documentation) :
sess.getTransaction().setTimeout(3)
How this value of 3 seconds is defined?
If your queries are deadlocking, look into why they are deadlocking and fix that. The error message in the PostgreSQL server error log tells you about the transactions that deadlocked. If that alone isn't enough, set log_statement = 'all', add a log_line_prefix to identify transactions or use csv logging, and analyze the log files to see what's happening.
If you're stuck you can hand-recreate the deadlock and take a look at pg_locks for additional information about what's going on; see the lock monitoring wiki article.
If the deadlock detection timeout is too long for you, lower PostgreSQL's deadlock detection timeout, don't add statement timeout hacks in the application. See the documentation on lock management.
My application that uses Spring JDBC, has a "Select For Update...wait 1" sql which issues a lock on the table row. I do a commit after that so that the lock gets removed. This is working in the jetty (Jetty data source is org.apache.commons.dbcp.BasicDataSource) but not in tomcat (org.apache.tomcat.dbcp.dbcp.BasicDataSource).
I commit as shown below: getJdbcTemplate().getDataSource().getConnection().commit()
Any help, appreciated !!