Showing posts with label postgres. Show all posts
Showing posts with label postgres. Show all posts

Saturday, July 19, 2008

Not working for EDB anymore

Well, I am no longer working for EnterpriseDB. It was fun while it lasted but it's over so I am moving on. I found a new job, locally. It's pure Oracle and I will get to use Real Application Clusters in a production environment. That's something I haven't done in the past so I am looking forward to it. It's also a java, .net and Oracle Forms shop and they are doing some interesting things with telecommunications and SMS.


From now on, I will only need to travel for conferences. No more trips to New Jersey. That's kind of a drag as I was almost at elite status on Continental. I have two more conferences this year and it just might be enough. I may even take a trip on my own just to get the miles. One of the trips is from Tampa to San Francisco, and back, so that will get me very close. The other is to Virginia and back.


I am a database geek and I will be keeping an eye on EDB just as I did in the past. I will probably post here at the EDB blog about as frequently as I have been (not often). Or, I may let this one die and just do any EDB posting on my postgres blog. That actually makes the most sense. I think I will cross post this one there and make this my last dedicated posting on this blog.


I also plan to keep up with Postgres, for personal knowledge, just as I do MySQL. I actually want to install GridSQL and see how it performs for a variety of different applications.


On the upside, I can now call EnterpriseDB Postgres Plus Advanced Server, PP AS, without marketing having fit. ;-) Heck, if I think of it as Advanced Server Software, I can call it the PP ASS. heh But I would never do that.


So, I can guess I can close out this blog now. Later.


LewisC




Technorati : , ,

Thursday, May 29, 2008

Wavemaker Provides EnterpriseDB Support

EnterpriseDB News at Blogspot


Chris Keene, the CEO for Wavemaker just blogged that combining Wavemaker and EnterpriseDB just got easier. Wavemaker has a new version that has out of the box support for both Postgres and EnterpriseDB.


I wrote a couple of weeks ago about my first day of Wavemaker training. I still haven't found time to start day two but now that Wavemaker supports EnterpriseDB, I'll probably redo day 1 using Advanced Server instead of MySQL. I could have done it before since it already supported Postgres and EnterpriseDB via a manual configuration. But now I'll want to see how easy it is with the automatic support.


If you want a little bit more info on Wavemaker, I also posted about my first look with it.


Wavemaker is an open source AJAX GUI builder for almost any relational database. You can get it, for free, here.


Thanks,


LewisC




Technorati : , , , , ,

Tuesday, May 27, 2008

Learn EDB: Basic Encryption

LewisC's An Expert's Guide To Oracle Technology


An ITToolbox user recently asked a question on the EnterpriseDB discussion group, Oracle equilant UTL_I18N.STRING_TO_RAW IN ENTERPRISEDB.


Basically, Sreenivas asked which functions in EnterpriseDB could be used to implement dbms_crypto, hex_to_raw, string_to_raw, etc. I believe he is using EnterpriseDB Postgres Plus Advanced Server which is the product that gives Oracle Compatibility. The short answer to his question is that right now, there are no compatibility functions for those. The long answer is that you can re-implement that functionality using native PG functionality.


If you look at Sreenivas's message you can see how his existing code works. I posted a simple example in response which I am reposting below. The PG docs suggest that you use PGP based encryption rather than what they call raw encryption. I think it depends on exactly what you're doing, personally. Anyway, raw encryption was closer to what Sreenivas was doing so that was what I based my example on.


I've used DBMS_CRYPTO in Oracle quite a bit but this is my first use of encrypt/decrypt in PG. If you have any suggestions for improving it, I'd like to hear them.


Hi Sreenivas,




I saw your post on the edb forum but and planned to write a blog entry on this topic.


The thing is that there isn't a one to one translation in EDB yet. The easiest thing is to rewrite your procedure and use built-ins that are available.




It is recommended that you use the PGP function in postgres as opposed to the raw encryption functions for better security. However, raw encryption more closely matches what you are trying to do. Below is an example of using raw encryption with AES.


You don't need to convert to hex as you'll be using bytea which is easily converted from and to a string. If you really need international support, check out the pg decode function (which is different from Oracle's decode). http://www.postgresql.org/docs/current/static/funct ions-string.html




Here is a very simple example that you can use to build your procedure:



declare

original_data text := 'I am going to be encrypted';
data bytea;
cipher bytea;
crypto_type text;
encrypted_data bytea;
final_string text;

begin

-- conversion to bytea, could use cast too
data := original_data;

--set cipher key
cipher := 'not a strong key, use pgp instead';

-- select type: aes or blowfish (bf)
crypto_type := 'aes';

-- encrypt the data
select encrypt(data, cipher, crypto_type) into encrypted_data;

dbms_output.put_line('Encrypted: ' || encrypted_data );

-- decrypt the data
select decrypt(encrypted_data, cipher, crypto_type) into final_string;

dbms_output.put_line('Decrypted: ' || final_string );

end;

Hope this helps,


LewisC




Del.icio.us : , , ,

Monday, May 12, 2008

Bind Variables in Postgres Plus Advanced Server

Bind variables are used to ease code maintenance and to save memory and processing on the server. When you save memory and processing power, you improve the overall performance of the server. The inner details of how this saves memory has been enumerated in other places on the web. This article is designed to help developers users bind variables when running queries against Postgres Plus Advanced Server.


What are bind variables?


The easiest way to think of a bind variable is to consider it just another variable. Instead of it being a variable to be used by your application (and whatever language you happen to be using), think of it as a variable to be used by SQL. Better yet, think of it as a parameter to be used by SQL.


Why do you use parameters in your functions and procedures? Take a look at this very simple SPL procedure:



PROCEDURE start_program IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello World');
END;

Now, that procedure works just fine. When the program starts, it calls start_program and it displays a message that the program is starting. Now we decide to add a message just before the program ends:



PROCEDURE end_program IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Goodbye World');
END;

This works fine technically but violates the rules of modularity in coding. We can parameterize the message so that we can reuse a single procedure and reduce the maintenance workload we have.



PROCEDURE print_message
(p_message IN VARCHAR2)
IS
BEGIN
DBMS_OUTPUT.PUT_LINE(p_message);
END;

Now when the program starts, we just call print_message('Hello World'); and when the program ends, we call print_message('Goodbye World');


If you've been programming any amount of time, the reasons for doing this are more than obvious. You get a large maintenance bonus by maintaining fewer lines of code. You might even get a performance bonus (depending on the language) by using less memory.


So, using a bind variable in a database is like using a parameter to a procedure. Only, instead of you doing the maintaining, the database does less maintenance. If you send a bunch of nearly indeitical queries to the server like:



SELECT last_name, first_name
FROM employees
WHERE employee_id = 101;

and



SELECT last_name, first_name
FROM employees
WHERE employee_id = 102;

There are two queries in memory. If you select 10000 employees (which a batch program might easily do), that's a whole lot queries that are basically duplicates. The database has to keep track of those and that takes time and memory. The database already has plenty to do keeping track of permissions, users, log files, etc. Why give it more to do?


The way to write a query with bind variables changes depending on the language and tool. The most common that you might see are named variables beginning with a colon (:) or a question mark (?). EnterpriseDB's SPL uses named variables with a bind for dynamic SQL, as does it's toolset.


Binds in SPL


In general, you don't need to use bind variables in PL/SQL. PL/SQL binds up your variables for you. The only times you need to do it manually are when you are manually parsing SQL using "EXECUTE IMMEDIATE".


If I am using EXECUTE IMMEDIATE, I would write a query like this:



DECLARE
v_empno emp.empno%TYPE;
v_query_string VARCHAR2(2001);


v_name emp.ename%TYPE;

v_job emp.job%TYPE;
BEGIN


v_query_string :=
'SELECT ename, job
FROM emp
WHERE empno = :e_id';


v_empno := 7876;


EXECUTE IMMEDIATE v_query_string
INTO v_name, v_job
USING v_empno;


DBMS_OUTPUT.PUT_LINE('Name: ' || v_name ||
', Job: ' || v_job );


END;

Example:



Connected to EnterpriseDB 8.3.0.12 (localhost:5444/edb) AS enterprisedb

EDB*Plus: Release 8.3 (Build 14)
Copyright (c) 2008, EnterpriseDB Corporation. All rights reserved.


QL> set serveroutput on
SQL> DECLARE
2 v_empno emp.empno%TYPE;
3 v_query_string VARCHAR2(2001);
4 v_name emp.ename%TYPE; v_job emp.job%TYPE;
5 BEGIN
6 v_query_string :=
7 'SELECT ename, job
8 FROM emp
9 WHERE empno = :e_id';
10 v_empno := 7876;
11 EXECUTE IMMEDIATE v_query_string
12 INTO v_name, v_job
13 USING v_empno;
14 DBMS_OUTPUT.PUT_LINE('Name: ' || v_name ||
15 ', Job: ' || v_job );
16
17 END;
18
19 /


Name: ADAMS, Job: CLERK


EDB-SPL procedure successfully completed.


SQL>

You could actually rewrite this several different ways but this example shows the gist of it. Notice that the select list does not include any binds. Advanced Server knows to send the selected columns out as bind variables.


Also, notice that the name of the bind variable (:e_id) does not need to match the SPL variable (v_employee_id). If we do think of bind variables as parameters to SQL, that makes sense. SQL only cares about the data coming in and going back out. The calling program (Advanced Server in this case) is responsible for correctly mapping inputs and outputs. The SQL engine just agrees to send the data is the agreed upon order (left to right).


Binds in Java


Java is a bit more verbose but most of this code is connecting to the database. The parts in bold are the important parts.



import java.sql.*;
import oracle.jdbc.pool.*;


class prog2 {


public static void main (String args []) throws SQLException
{


String url = "jdbc:oracle:oci8:@//192.168.1.7:1521/ORCL";
OracleDataSource ods = new OracleDataSource();


ods.setURL(url);
ods.setUser("hr");
ods.setPassword("hr");


Connection conn = ods.getConnection();


PreparedStatement cmd = conn.prepareStatement
("SELECT first_name, last_name FROM employees WHERE employee_id = ?");



cmd.setString(1, "101");


ResultSet rs = cmd.executeQuery();


rs.next();


System.out.println ("Last Name: " +
rs.getString(1) +
", First Name: " +
rs.getString(2));


conn.close();


}
}

Binds in C#


C# is about as verbose as Java but remember that most of this code is C# infrastructure code and creating the connection. The parts in bold is the pertinent code.



using System;
using System.Data.OracleClient;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
OracleConnection conn =
new OracleConnection(
"User id=hr;Password=hr;Data Source=remoorcl"
);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;

String query = "SELECT last_name, first_name " +
"FROM employees " +
"WHERE employee_id = :e_id";

cmd.CommandText = query;

int vEmpId = 101;
OracleParameter prm = new OracleParameter(":e_id", vEmpId);
cmd.Parameters.Add(prm);


OracleDataReader dataReader = cmd.ExecuteReader();

dataReader.Read();

Console.WriteLine("Last Name: " +
dataReader.GetOracleString(0) +
", First Name: " +
dataReader.GetOracleString(1));

conn.Close();
}
}
}

Summary


This post got much larger than I intended. Anyway, the important part is that it really is not complicated to use bind variables and I think it is much less complicated than trying to string together pieces of text and needing to quote char data and format date data. A bind variable is just a parameter that allows SQL to reuse statements. This helps performance and reduces memory consumption as well as making your code more maintainable.


LewisC








Technorati : , , , , ,

Wednesday, April 23, 2008

Combined Forums for Postgres and EnterpriseDB Issues

In the past, your basic support for postgres has been mail groups. I've never been a big fan of mail groups. You have to subscribe to the group and usually you get tons of stuff you don't really want. Worst of all, you either have to sort through it or filter it to a folder. I never seem to be able to keep up with the stuff I am interested in due to the clutter.

EnterpriseDB has had forums for a while but recently combined the postgres and advanced server forums into a single location. GridSQL also has it's own forum. You can ask pretty much any question you might have. The forums are monitored by EnterpriseDB employees and there are also some very knowledgeable users out there.

LewisC



Tuesday, January 15, 2008

Wednesday, October 3, 2007

EnterpriseDB Wins One From MySQL

Do you do GEO? If you do, you've probably at least heard of PostGIS, the Postgres GIS extension. PostGIS just gave EnterpriseDB a big win over its open source competition.

FortiusOne leads the market towards the next generation of Web mapping. Its breakthrough Intelligent Mapping technologies offer rich information visualization on maps and unprecedented access to geographic data. FortiusOne innovations include: high-speed Web-based geographic analysis tools, a flexible and scalable Web services platform supporting the special needs of geographic data, and an innovative application of social networking techniques to geographic knowledge creation.

FortiusOne's main product is GeoCommons. GeoCommons houses a large geospatial database with more than two billion attributes, 35,000 variables, and 1,500 datasets. As a fast-growing startup, FortiusOne required a low-cost, powerful database solution to run GeoCommons. Originally, FortiusOne selected MySQL; however, when FortiusOne was preparing to deploy the first public beta of GeoCommons, they encountered major performance roadblocks.



FortiusOne has migrated GeoCommons from MySQL to EnterpriseDB Advanced Server and improved overall system performance by 80%.

“We slammed into a brick wall with MySQL,” said Chris Ingrassia, chief technology officer, FortiusOne. “As an example, MySQL’s rather limited and incomplete spatial support dramatically impacted performance. We were looking for an affordable database solution, but we required enterprise-class features and performance that MySQL simply couldn’t deliver. Plus, philosophically we want to support open source-based technologies like EnterpriseDB.”


The PostGIS geospatial extensions to PostgreSQL played a key role in FortiusOne’s selection of EnterpriseDB Advanced Server, a PostgreSQL-based solution, and dramatically improved performance. FortiusOne needed to run complex spatial queries against large datasets quickly and efficiently, and found the MySQL spatial extensions to be far less complete and comprehensive than PostGIS. EnterpriseDB Advanced Server processes some of GeoCommons’ database-intensive rendering requests in one-thirtieth of the time required by MySQL. During peak loads, GeoCommons processes more than one hundred thousand complex requests per hour, requiring true enterprise-class performance and scalability.

“EnterpriseDB occupies that crucial middle ground between MySQL and Oracle,” continued Ingrassia. “EnterpriseDB is priced competitively with MySQL, but provides significantly better performance and advanced features you just don’t find in most open source databases.”


You can get additional information about GeoCommons at the GeoCommons FAQ. Checkout some cool screenshots at the FortiusOne screenshot page.


Software Blogs - Blog Catalog Blog Directory Software blogs Top Blog Sites Blog Flux Directory Lewis Cunningham