Alex Rivera | Logout

Hidden Features of PostgreSQL

Asked 2009-04-17T17:16:28.050
79

I'm surprised this hasn't been posted yet. Any interesting tricks that you know about in Postgres? Obscure config options and scaling/perf tricks are particularly welcome.

I'm sure we can beat the 9 comments on the corresponding MySQL thread :)

Edit
Report

3 Answers

6

Materialized Views are pretty easy to setup:

CREATE VIEW my_view AS SELECT id, AVG(my_col) FROM my_table GROUP BY id;
CREATE TABLE my_matview AS SELECT * FROM my_view;

That creates a new table, my_matview, with the columns and values of my_view. Triggers or a cron script can then be setup to keep the data up to date, or if you're lazy:

TRUNCATE my_matview;
INSERT INTO my_matview SELECT * FROM my_view;
answered 2009-06-22T00:15:01.420
6

You don't need to learn how to decipher "explain analyze" output, there is a tool: http://explain.depesz.com

answered 2012-06-19T09:57:56.593
3

pgcrypto: more cryptographic functions than many programming languages' crypto modules provide, all accessible direct from the database. It makes cryptographic stuff incredibly easy to Just Get Right.

answered 2009-04-18T01:31:48.063

Your Answer