Changes

Jump to: navigation, search

PostgreSQL Adapter Project - Resources

8,436 bytes added, 19:53, 26 January 2014
no edit summary
<big><big> Postgre Project - Resources</big></big>{{NexJ_Express IndexAdmon/obsolete}} [[Category: NexJ Express PostgreSQL]]
==Java==
:Mapping Objects to Relational Databases @ [http://www.agiledata.org/essays/mappingObjects.html#MappingMetaData agiledata.org]
: Converting Charsets [http://codex.wordpress.org/Converting_Database_Character_Sets]
: ACID
::In computer science, ACID (atomicity, consistency, isolation, durability) is a set of properties that guarantee database transactions are processed reliably. In the context of databases, a single logical operation on the data is called a transaction. For example, a transfer of funds from one bank account to another, even though that might involve multiple changes (such as debiting one account and crediting another), is a single transaction. [http://en.wikipedia.org/wiki/ACID]
: MVCC
:: Multiversion concurrency control (abbreviated MCC or MVCC), in the database field of computer science, is a concurrency control method commonly used by database management systems to provide concurrent access to the database and in programming languages to implement transactional memory.[http://en.wikipedia.org/wiki/Multiversion_concurrency_control]
: Binary vs Integer for primary key
:: [http://stackoverflow.com/questions/4037796/binary-vs-integer-as-primary-key]
===Persistence===
==PostgreSQL Specifications==
* PostgreSQL 8Installation (v 9.9.1 for J2EE/JDBC applications -1): [http://wikiwww.postgresql.org/images/a/acdownload/Pg_8.1_J2EE_v1.0.pdf]* Installation: -> for [http://www.postgresqlenterprisedb.orgcom/downloadproducts/pgdownload.do#windows windows]
* Tutorial @ [http://www.postgresql.org/docs/9.0/static/index.html PostgreSQl Documentation]
* Guide to report problems [http://wiki.postgresql.org/wiki/Guide_to_reporting_problems]
* PostgreSQL 8.1 for J2EE/JDBC applications [http://wiki.postgresql.org/images/a/ac/Pg_8.1_J2EE_v1.0.pdf]
* [http://www.postgresql.org/files/documentation/books/aw_pgsql/node200.html Reference Manual]
 
===Connection to the driver===
* JDBC Interface
 
: 1- XA JDBC driver for Postgre (needed for NexJ Express Model)
:: XA Data Source, as for what they mean: XA are for distributed transactions (as per the Open Group specificitions) and non-XA are not (transactions must be single-database). [http://www.theserverside.com/discussions/thread.tss?thread_id=21385]
:: Hierarchy for package [http://jdbc.postgresql.org/development/privateapi/org/postgresql/xa/package-tree.html org.postgresql.xa] - src of the hirearchy [http://grepcode.com/file/repository.jboss.com/maven2/postgresql/postgresql/8.3-603.jdbc3/org/postgresql/core/ConnectionFactory.java?av=f]
:: [http://jdbc.postgresql.org/todo.html Bugs]
:: Postgresql Limited XA Support[http://www.atomikos.com/Documentation/KnownProblems#Postgresql_Limited_XA_Support] - PostgreSQL XA support is limited in what it can do; using Postgresql is not recommended and not supported. If you do choose to use it, see this forum post for some of the problems.
: [http://www.postgresql.org/docs/8.4/static/app-psql.html psql]
: [http://www.postgresql.org/docs/9.0/interactive/app-pg-ctl.html working with server]
: psql [http://www.postgresonline.com/special_feature.php?sf_name=postgresql83_psql_cheatsheet&outputformat=html cheatsheet]
* GUI
: PGAdimn [http://www.pgadmin.org/visualtour.php Visual tour]
* Creating database [http://www.postgresql.org/files/documentation/books/aw_pgsql/node227.html]
: @ [http://www.postgresql.org/docs/9.0/interactive/creating-cluster.html PostgreSQL documentation] - [http://www.postgresql.org/docs/9.0/interactive/manage-ag-createdb.html]
: To create a <code>user</code> along with <code>password</code>: <code> CREATE USER test WITH PASSWORD 'test'; </code>
: To create a <code>table</code>, first you need to crate a <code> shema </code> inside the database with particular user name <code> CREATE SCHEMA TEST AUTHORIZATION TEST;</code>
* Issuing a Query and Processing the Result @ [http://jdbc.postgresql.org/documentation/84/query.html PostgreSQL Documentation]
: fetch size, cursor,...
===Mapping Data Types, Metadata===
* Mapping Overview
: Because data types in SQL and data types in the Java programming language are not identical, there needs to be some mechanism for transferring data between an application using Java types and a database using SQL types. [http://download.oracle.com/javase/1.3/docs/guide/jdbc/getstart/mapping.html]
: Mapping - Postgre [http://postgresql.1045698.n5.nabble.com/PostgreSQL-data-types-mapped-Java-classes-for-JDBC-td3205204.html]
* Data Types
: Bytea - Binary - hex
::A binary string is a sequence of bytes. Unlike character strings, which usually contain text data, binary strings are used to hold non-traditional data such as pictures, voice, or mixed media. [http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0008472.htm] & [http://www.enterprisedb.com/docs/en/8.3R2/jdbc/Postgres_Plus_Advanced_Server_JDBC_Connector_Guide-24.htm]
:: PostgreSQL can not store values of more than several thousands bytes within any data-type except large objects, nor can binary data be easily entered within single quotes. Instead, large objects (BLOB) are used to store very large values and binary data. From PostgreSQL documentation “String Functions and Operators”[6] we catch the function ENCODE(data bytea, type text). This function encodes binary data to an ASCII-only representation. The supported types are: base64, hex, escape.[http://lab.lonerunners.net/blog/binary-data-fetching-through-sqli]
:: [http://www.enterprisedb.com/docs/en/8.3R2/jdbc/Postgres_Plus_Advanced_Server_JDBC_Connector_Guide-24.htm Using BYTEA Data with Java]
:: Binary operations and functions: ENCODE & DECODE [http://www.postgresql.org/docs/current/static/functions-string.html]
:: Example [http://stackoverflow.com/questions/3103242/inserting-text-string-with-hex-into-postgresql-as-a-bytea]
<source lang = java>
CREATE TABLE mytable (testcol BYTEA);
 
INSERT INTO mytable (testcol)
VALUES (DECODE('013d7d16d7ad4fefb61bd95b765c8ceb', 'hex'))
 
SELECT ENCODE(testcol, 'hex') FROM mytable; // prints: 013d7d16d7ad4fefb61bd95b765c8ceb
SELECT testcol FROM mytable; // prints: \x013d7d16d7ad4fefb61bd95b765c8ceb
</source>
: Why using 'BINARY strings' instead of INTEGER unique identifiers [http://www.xcitestudios.com/blog/2010/01/31/mysql-and-binary16-the-reasonsbenefitsdrawbacks-mysql/]
: Compare JDBC data types with PostgreSQL types [http://db.apache.org/ddlutils/databases/postgresql.html]
: bit & bit varying - for storing binaries [http://www.postgresql.org/docs/8.1/static/datatype-bit.html]
: BLOBs [http://www.postgresql.org/files/documentation/books/aw_pgsql/node96.html]
: Serial - Auto_Increment - Sequence
:: A sequence is a special kind of database object designed for generating unique numeric identifiers. It is typically used to generate artificial primary keys. Sequences are similar, but not identical, to the AUTO_INCREMENT concept in MySQL. Sequences are most commonly used via the serial pseudotype.[http://neilconway.org/docs/sequences/] - [http://www.postgresql.org/docs/8.1/interactive/datatype.html#DATATYPE-SERIAL]
:: Adding sequence [http://pointbeing.net/weblog/2008/03/mysql-versus-postgresql-adding-an-auto-increment-column-to-a-table.html]
===Functions===
* Functions & Operators
: String literals and string functions in postgreSQL @ [http://www.postgresql.org/docs/current/static/functions-string.html PostgreSQl Documentation]
: Pattern Matching [http://pgsqld.active-venture.com/functions-matching.html
: postgre [http://sql-info.de/postgresql/postgres-gotchas.html gotchas]
 
* Issuing a Query and Processing the Result @ [http://jdbc.postgresql.org/documentation/84/query.html PostgreSQL Documentation]
: fetch size, cursor,...
* Localization
: Character set support -
::The character set support in PostgreSQL allows you to store text in a variety of character sets (also called encodings), including single-byte character sets such as the ISO 8859 series and multiple-byte character sets such as EUC (Extended Unix Code), UTF-8, and Mule internal code. All supported character sets can be used transparently by clients, but a few are not supported for use within the server (that is, as a server-side encoding). The default character set is selected while initializing your PostgreSQL database cluster using initdb. It can be overridden when you create a database, so you can have multiple databases each with a different character set. An important restriction, however, is that each database's character set must be compatible with the database's LC_CTYPE (character classification) and LC_COLLATE (string sort order) locale settings. For C or POSIX locale, any character set is allowed, but for other locales there is only one character set that will work correctly. (On Windows, however, UTF-8 encoding can be used with any locale.) Note! Not all client APIs support all the listed character sets. For example, the PostgreSQL JDBC driver does not support MULE_INTERNAL, LATIN6, LATIN8, and LATIN10. [http://www.postgresql.org/docs/current/static/multibyte.html]
: BLOBs [http://www.postgresql.org/files/documentation/books/aw_pgsql/node96.html]
==MySQL Specifications==
* [http://www.mysql.com/downloads/connector/j/ Mysql Connector]
* [http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html MySQL Configuration properties]
 
* '''IMP!''' Some optimization [http://www.petefreitag.com/item/613.cfm Hints]
* Retrieving AUTO_INCREMENT Column Values [http://dev.mysql.com/doc/refman/5.0/en/connector-j-usagenotes-basic.html#connector-j-usagenotes-last-insert-id]
* Binary - Hex
:[http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_unhex]
: The BINARY and VARBINARY types are similar to CHAR and VARCHAR, except that they contain binary strings rather than non-binary strings. That is,they contain byte strings rather than character strings. This means that they have no character set, and sorting and comparison are based on the numeric values of the bytes in the values.(From MySQL Manual)
: In MySQL SQL syntax the function HEX() can be used to get the hexadecimal value of one field of any data-type. [http://lab.lonerunners.net/blog/binary-data-fetching-through-sqli]
: Example
<source lang = java>
CREATE TABLE mytable (testcol BINARY(16));
 
INSERT INTO mytable (testcol)
VALUES (0x013d7d16d7ad4fefb61bd95b765c8ceb);
 
SELECT hex(testcol) FROM mytable; // prints: 013d7d16d7ad4fefb61bd95b765c8ceb
 
</source>
* SQL mode
: If strict SQL mode is not enabled and you assign a value to a BINARY or VARBINARY column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated.
: ANSI_QUOTES
::Treat “”” as an identifier quote character (like the “`” quote character) and not as a string quote character. You can still use “`” to quote identifiers with this mode enabled. With ANSI_QUOTES enabled, you cannot use double quotation marks to quote literal strings, because it is interpreted as an identifier.
 
* Storage Engine:
:PostgreSQL is a unified database server with a single storage engine. MySQL has two layers, an upper SQL layer and a set of storage engines. [http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL]
: InnoDB is a fully ACID transactional storage engine using MVCC (Multi-Version Concurrency Control) technology. It's the normal choice for most modern applications using MySQL. [http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL#MySQL:InnoDB]
: In some distributions, the default storage engine is MyISAM, which is not transaction safe. Setting the default engine to a transactional engine such as '''InnoDB''' is, however, trivial. MySQL has a query cache that does simple string matching before the parser to see whether a query has been processed recently and rapidly returns the result to the client application if it has, without the need to do any of the traditional database work. This is of considerable value to many read-mostly workloads. Cached queries are removed whenever any table involved in the query is changed so its usefulness declines as the rate of data changes increases. The query cache runs on a single thread and must consider each select, so it may eventually become a performance bottleneck at some point beyond 8 cores, but that's not usually the case. It can be turned off easily to check this and to see whether its small overhead is worthwhile for the particular workload. MySQL also supports network protocol-level compression which is an option that can be turned on by the client if the server allows it. This compresses everything to and from the server.
* LikeEscape:[http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like]
: Because MySQL uses C escape syntax in strings (for example, “\n” to represent a newline character), you must double any “\” that you use in LIKE strings. For example, to search for “\n”, specify it as “\\n”. To search for “\”, specify it as “\\\\”; this is because the backslashes are stripped once by the parser and again when the pattern match is made, leaving a single backslash to be matched against.
mysql> SELECT filename, filename LIKE '%\\\\' FROM t1;</code> ( Will have the same result as above)
*The current versions are MySQL 5.1 and PostgreSQL 8.4.
#PostgreSQL is a unified database server with a single storage engine. MySQL has two layers, an upper SQL layer and a set of storage engines. [http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL]
==PostgreSQL - MySQL Compare==
#MySQL began development with a focus on speed while PostgreSQL began development with a focus on features and standards. Thus, MySQL was often regarded as the faster of the two.[http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL#Beginnings]
# Both PostgreSQL and MySQL support Not-Null, Unique, Primary Key and Foreign Key constraints. However MySQL silently ignores the CHECK constraint
#MySQL supports stored procedures, per se; PostgreSQL supports stored functions, which are in practice very similar.
#Alter table - Postgres supports ALTER TABLE to some extent. You can ADD COLUMN, RENAME COLUMN and RENAME TABLE. MySQL has all options in ALTER TABLE - you can ADD column, DROP it, RENAME or CHANGE its type on the fly - very good feature for busy servers, when you don't want to lock the entire database to dump it, change definition and reload it back.
#Diagnostic Log - By default, PostgreSQL logs to stderr, meaning that it's highly installation specific where the dianostic information is put; on this author's system, the default ends up in /var/lib/pgsql/pgstartup.log. The default can be set to something more reasonable (such as syslog on unix, eventlog on Windows) by adjusting thelog_destination configuration parameter.
# Architecture
: PostgreSQL is a unified database server with a single storage engine. MySQL has two layers, an upper SQL layer and a set of storage engines. When comparing the two it's typically necessary to specify which storage engines are being used with MySQL because that greatly affects suitability, performance and sometimes feature availability. The most commonly used storage engines in MySQL are InnoDB for full ACID support and high performance on large workloads with lots of concurrency and MyISAM for lower concurrency workloads or higher concurrency read-mostly workloads that don't need ACID properties. Applications can combine multiple storage engines as required to exploit the advantages of each. [http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL#Architecture]
#Automatic key generation -
:PostgreSQL doesn't support the standard's IDENTITY attribute. PostgreSQL's best offering for a column with auto-generated values is to declare a column of 'type' SERIAL:
)
</source>
===Links===: Compare architecture @ [http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL Wiki]
: Compare SQL Implemenations[http://troels.arvin.dk/db/rdbms/ ]
: Compare Postgre and MySQL [http://www-css.fnal.gov/dsg/external/freeware/pgsql-vs-mysql.html]
: Comparison based on Postgre website [http://wiki.postgresql.org/wiki/Why_PostgreSQL_Instead_of_MySQL:_Comparing_Reliability_and_Speed_in_2007]
: Compare Data types [http://www.linuxnetworks.de/doc/index.php/OpenDBX/DBMS_Datatypes]
: Compare MySQL, Oracle, PostgreSQL [http://www-css.fnal.gov/dsg/external/freeware/mysql-vs-pgsql.html
: Converting MySQL to PostgreSQL -> data types & Functions & Command-line [http://en.wikibooks.org/wiki/Converting_MySQL_to_PostgreSQL]

Navigation menu