Postgres 9.1 foreign data wrapper interface

Postgres 9.1 support so called "Foreign data wrappers". These are similar to MySQL federated-x storage engine and with their help you can access data from different data sources, for example comma separated text files, MySQL servers, Redis :) and more.

"Official" example is with /etc/passwd file:

After the extention is installed, you can do following:

CREATE FOREIGN TABLE passwd (
	username text		,
	pass text		,
	uid int4		,
	gid int4		,
	gecos text		,
	home text		,
	shell text
) SERVER file_server
OPTIONS (
	format 'text'		,
	filename '/etc/passwd'	,
	delimiter ':'		, 
	null ''
);

After the foreign table is created, you can do query:

$ select * from passwd order by uid asc limit 3;
username  | pass | uid | gid | gecos  | home      | shell
----------+------+-----+-----+--------+-----------+-----------
root      | x    |   0 |   0 | root   | /root     | /bin/bash
daemon    | x    |   1 |   1 | daemon | /usr/sbin | /bin/sh
bin       | x    |   2 |   2 | bin    | /bin      | /bin/sh
(3 rows)

All commands such \dt, \d passwd etc will work.

More information can be found on www.depesz.com.

Foreign data wrapper for Redis

We plane to test this wrapper soon, here are something like preview:

Foreign data wrapper for Redis can be found here Redis_fdw.

Example usage:

CREATE SERVER redis_server 
FOREIGN DATA WRAPPER redis_fdw 
OPTIONS (
	address '127.0.0.1'	,
	port '6379'
);

CREATE FOREIGN TABLE redis_db0 (
	key text		,
	value text
)SERVER redis_server
OPTIONS (
	database '0'
);

After that you can qury the table redis_db0.

Wrapper currently support only single keys (e.g. similar to PostgreSQL memcached extention), but possibilities are still unlimited :) Here are some of them we can think of:

Conclusion:

PostgreSQL Foreign data wrapper interface could be very useful, especialy memcached, Redis and MySQL wrapper. If you are using PostgreSQL you really should check what they can offer you.


blog comments powered by Disqus





Articles library

Redis as session handler in PHP

How to use Redis for session handler in PHP in a way similar to msession or PostgreSQL sessions
Date: 2011-07

Tags: system administration php


Lazy starter script on Linux such Redhat CentOS or Fedora

How to quickly made Redis to start after Linux boot.
Date: 2011-07

Tags: system administration


Redis vs Memcached comparison

Here is basic comparison of Redis Memcached and Memcachedb.
Date: 2011-07

Tags: memcached


Why RDBMS and SQL are difficult...

...while sometimes NoSQL solution may be easier and way faster? This arcle deals with incremental counters and how they needs to be implemented properly in RDBMS-es such MySQL
Date: 2011-07
Updated: 2011-09-30

Tags: anti-pattern programming mysql


Seamless migration from one Redis server to another

How to use replication to migrate Redis server without service interruption
Date: 2011-07

Tags: system administration


Redis swap issue while save

Explanation why your server load average may spike and server to swap memory when running redis
Date: 2011-08-21

Tags: system administration


Amazon EC2 and Amazon ElastiCache service

Memcached at Amazon first impressions
Date: 2011-08-23

Tags: system administration memcached cloud


Understanding hash-max-zipmap-entries and 'hash of hashes' optimization

Explanation of config parameters such hash-max-zipmap-entries and how we can make huge memory savings in new Redis 2.2
Date: 2011-08-28

Tags: optimization system administration programming php


NoSQL database design example

This article explains how we made our article section
Date: 2011-09-02

Tags: database design programming mysql


Redis save and backup script

Simple backup script for Redis
Date: 2011-09-28

Tags: system administration optimization


Postgres 9.1 foreign data wrapper interface

Postgres 9.1 gives you ability to access data from different data sources including Redis
Date: 2011-10-20

Tags: programming mysql pgsql memcached optimization


Redis high traffic connection issue

Explanation on 'Cannot assign requested address' connection error
Date: 2011-11-12

Tags: optimization system administration scaling


Redis too many open files error on high traffic sites

Explanation on 'Accepting client connection: accept: Too many open files'
Date: 2011-12-21

Tags: system administration memcached security


PHP Redis bug with PHP 5.4

Description of bug PHP Redis bug
Date: 2012-07-02

Tags: system administration php


Case Study: Using Redis intersect on very large sets

Intersection of 2 x 120M MySQL records
Date: 2012-08-29

Tags: programming mysql optimization cloud php


Getting started with Python and Redis on CentOS 6.X

How to install and test Redis client for Python on CentOS
Date: 2013-03-21

Tags: system administration python


GeoIP in Redis

Put Maxmind's GeoIP in Redis for best berformance for cient apps written in PHP or Python
Date: 2013-03-24

Tags: programming mysql optimization php scaling python


Redis database file examination

Examination of Redis rdb file in order to find huge memory consumption
Date: 2013-08-23

Tags: optimization system administration


© Jul.2011 - 2017, E-Nick.org