Posts

ROLLUP Analytical function in PostgreSQL.

Currently, there is no version of PG, which supports the rollup. However, people look for this analytical function features. ROLLUP queries result can be achieve using the UNION of Queries. First Let's Understand what does rollup do: If SQL Query has col1,col2,col3,aggregate(col4) then rollup Processing would be something like this. 1. Show the aggregate of col4 as per the col1,col2,col3 2. Then rollup will do the subtotal and will show the result as per the as aggregate of based on col1,col2 3. Then it will show the aggregate/subtotal as per the col1. 4. And at end Total/Sum In short, it creates progressively higher-level subtotals, moving from right to left through the list of grouping columns. Finally, it creates a grand total. In PG, this can be achieve by writing a SubQueries and and UNION those. So, if the rollup query is something like given below: select col1,col2,col3,agg(col4) from relation group by rollup(col1,col2,col3) Then in PG above can be writte

PG_REORG Utility for VACUUM FULL online

pg_reorg is a utility made by NTT for reorganizing the table structure. Concept is simple, if you have all the require pointers and data in same page, then accessing those is much more faster. This is what pg_reorg provides to a user. Following are some options, which pg_reorg provides. -o [ —order-by] columns: This option makes pg_reorg to oraganise the table data as per the mentioned column. At the backend pg_reorg will creates a new table using CTAS and SELECT Query include ORDER BY clause with columns mentioned with -o. -n [—no-order] tablename: When this option is being used, then pg_reorg, does the VACUUM FULL ONLINE. Now, question is how it must be doing. Simple Concept, create a new table using CTAS and create a trigger on current table to track the DML. As the New table got created play those tracked DML on new table. It works well. This option is only for table which has primary key. pg_reorg by default does the CLUSTER of tables and it follows same concept, i.e wit

Slony Vs PG9.0 Built in Streaming Replication.

People Generally asked such kind of Questions as PG9.0 Comes with Streaming Replication. Following are some points which people need to think before deciding which replication, they should follow: 1. Slony has a some overhead on database than the Streaming replication+HotStandby in 9.0 2. All the changes must be apply via SLONIK Command 3. Slony gives advantage of replicating some tables and allows to ignore others 4. Slony also gives the advantage of replication between Different version of PG and PG on different OS.

PG9.0:: Monitoring Hot Standby

Now PG9.0 is in Market with new feature of Hot Standby and Streaming Replication. So, I have started to explore the way of monitoring the Hot Standby. I was in process of writing my own code for Monitoring the Hot Standby. For this purpose I have written a shell script to find the way of calculating lag. In pgpool-II, Developer has used following formula to calculate the lagging: lsn = xlogid * 16 * 1024 * 1024 * 255 + xrecoff; Following is an explanation of meaning of xlogid and xrecoff: postgres=# select pg_current_xlog_location(); pg_current_xlog_location -------------------------- 0/13000078 (1 row) 0: is xlogid and xrecoff is 13000078 With this, Concept of implementation of finding the lagging is to calculate the replication lag by comparing the current WAL write location on the primary with the last WAL location received/replayed by the standby. These can be find using pg_current_xlog_location function on the primary and the pg_last_xlog_receive_location/pg_last_xl

pgFouine: PostgreSQL Log Analyzer

Image
PgFouine is a interesting PostgreSQL Analyzer Tool which is available for Generating the Reports in html format. Advantage of using this tool is that user gets report in text or HTML format, which is easy to analyze. Using pgFouine user can make following types of Reports: 1. Error Reports 2. Slow Query reports 3. Vacuum Verbose Reports etc... Installation of pgFouine is simple. Download the source from following location: http://pgfoundry.org/frs/download.php/2575/pgfouine-1.2.tar.gz and then extract the pgfouine source using following command: tar zxvf pgfouine-1.2.tar.gz. Please note, before using pgfouine user has to make sure that it has php installed on his server. pgFouine has some restriction over analyzing the log file. It analyzes the PostgreSQL logfiles, if the log_line_prefix has following format: log_line_prefix = 'user=%u,db=%d ' ( Filter on database with user with syslog ) log_line_prefix = '%t [%p]: [%l-1] ' ( For standard errors) log_l

Physical Standby Vs Hot Standby

Some thoughts always come in mind about standby terminologies. Once, Someone has asked question about Physical Standby of Oracle10g. Is Oracle10g Physical Standby a Hot Standby Or WarmStandby? Till Oracle 10g, Physical Standby of Oracle is a standby which has two mode: 1. Managed Recovery Mode 2. Read Only Mode. It cannot be in both mode at same time. If the standby is in recovery mode then, it's a Warm Standby and when its read only mode then, then it's lagging from Primary and would be able to response SELECT queries. Either way, till Oracle 10g physical standby was not meeting the requirement of Hot Standby. It was playing the role of Warm Standby. However, from Oracle 11g, Physical Standby can be Recovery mode and read only mode, both at the same time, which now fulfill the definition of Hot Standby. With the complexity of managing the Standby, licensing thing comes in Picture. PG9.0 onwards, PostgreSQL now has Cold Standby, Warm Standby and Hot Standby, with zero cost.

Hot Standby in PostgreSQL 9.0:

Image
As per definition of Hot Standby, its a method of redundancy in which primay and secondary (Backup Server) runs simultaneously. The data is mirrored to secondary so that both should contain identical data in real time. With this user, would be able to execute the Query against Database while secondary is in archive recovery mode. This is what introduce in PG9.0. In-built Hot Standby. PostgreSQL Community always try to make the things simpler as much as possible, same they have proven in Hot Standby Implementation. Following are the steps of configuring Hot Standby: 1. Make sure following parameters are set in Configuration file, postgresql.conf of Primary: wal_level = ‘hot_standby’ archive_mode = on archive_command = ‘cp %p /Library/PostgreSQL/9.0/data/archivelog/%f’ 2. After setting the above parameters, Now take the hot backup of PG9.0 Instance. Steps of Hot Backup is simple: a) Execute following command in Primary: select pg_start_backup(‘Hot Standby Backup’); b) Take the fi