Skip to main content

Posts

Showing posts with the label database

Useful PostgreSQL Queries

I have been actively using PostgreSQL for the last 7 years. As with many databases engines, PostgreSQL provides us with many capabilities when it comes to helping developers identify slow performing queries. This article focuses on several useful (primarily administrative queries) for PostgreSQL which may be helpful in debugging you database performance issues. Queries Show Running Queries Often times it is useful to see which queries are running and how long they have been running from. The below is a sample query to find 'active' queries and information about them.  SELECT pid, client_addr, query_start, age(query_start, clock_timestamp()), usename, query, state, wait_event_type, -- Only available in >9.6 wait_event -- Only available in >9.6 FROM pg_stat_activity WHERE query != ' ' AND query NOT ILIKE '%pg_stat_activity%' AND state = 'active' ORDER BY query_start desc; Particularly useful attribute ...

Oracle Data Tricks

Oracle is not a very friendly enviornment to deal with date types. I always find myself googling around to find a proper method to deal with date arithmetics. The below is a method I came across that helps adding and subtracting years, months, and days from a date type. Enjoy! update employee set SERVICE_DATE = add_months(SERVICE_DATE, -1200) where employee_id in (select e.EMPLOYEE_ID from INTERFACE_EXTRACT et, danaher.employee e where et.NUMBER = e.EMPLOYEE_ID and et.HIRE_DATE != e.SERVICE_DATE and to_number(to_char(e.SERVICE_DATE, 'YYYY'), '9999') > 2010) The above query for example sets the SERVICE_DATE column to be 1200 months earlier. The return value of the add_months function is of type date .

Geronimo and Mysql Driver

I was trying to deploy Alfresco Content Management system into Geronimo. I downloaded the community war version and simply used the deploy script of Geronimo located in GERONIMO_HOME/bin/ to deploy the war file. As soon As I started Alfresco through Geronimo console, I ran into problems with Alfresco not being able to load MySQL Driver. Needless to say, MySQL database was chosen for this deployment. I ended up solving the problem by deploying MySQL driver into Geronimo. You can do this easily through the Geronimo console. On the left navigation of the console, there is a link called Common Libs below the Services folder. When you click on this, you will see an html form that lest you choose the jar file (in this case mysql-connector.jar). With in the form, you can give groupId, artificatId and version to the file. Once you submit the form, mysql connector will be deployed into Geronimo. What you need to do next is to create a geronimo-web.xml file and place it under WEB-INF directory o...

Oracle and Varchar2 size problem

I recently ran into a problem with Oracle version 9i. I was trying to insert a value into a varchar2(3200) column when I got the below exception. javax.servlet.ServletException: java.sql.SQLException: ORA-01461: canbind a LONG value only for insert into a LONG column The size of the text that I was trying to insert was actually lesser than the limit of 3200 characters. Yet Oracle thought the value that was being inserted was too large for the column. After reading some forums and articles, I found out that the problem was due to encoding of the characters. When content is saved, the saved sized of the content is actually more than the actual size of the content due to some data encoding conversion (to UTF8). This probably depends on the encoding of your database. You can run the following command to find your database's encoding. select * from nls_database_parameters where parameter='NLS_CHARACTERSET' If your database's encoding is set to UTF8, you should see something ...