Difference between revisions of "Working with PostgreSQL"

From edegan.com
Jump to navigation Jump to search
imported>Ed
imported>Ed
Line 26: Line 26:
 
  effective_cache_size = 2GB #Use a large chunk of available RAM
 
  effective_cache_size = 2GB #Use a large chunk of available RAM
  
Then restart the server:
+
Then restart the server (on windows use the 'services' control panel):
 +
 
 
  pg_ctl restart
 
  pg_ctl restart
  

Revision as of 13:48, 22 February 2011

Basic Configuration

Add PostgreSQL to the path if it isn't already:

Control Panel->System->Advanced->Environmental Variables
Add: C:\Program Files\PostgreSQL\9.0\bin

To use PLPerl on windows, you will need to be careful to mix and match the right versions of PostgreSQL and Perl.

Perl version 5.10.1 (a 64bit build is available from ActiveState) works with PostgreSQL 9.0.1 (64bit build 1500). To see your PostgreSQL version type:

psql -c "select version();" template1

To see your perl version type:

perl -v

With these two versions together you should be able to add plperl to template1 (which all new dbs will inherit) with the command:

createlang plperl template1

There is a list of commands/client applications, with links to documentation, which is useful.

You will almost surely want to 'performance tune' your postgresql database, as the default settings are near useless. In particular edit postgresql.conf (which is in the data directory of your install) to change:

shared_buffers = 512MB	#Use about 10-15% of available RAM	
effective_cache_size = 2GB #Use a large chunk of available RAM

Then restart the server (on windows use the 'services' control panel):

pg_ctl restart

Create a user using pgAdmin or the createuser command:

createuser ed_egan

And then create a database again using pgAdmin or the createdb command:

createdb -O ed_egan DBName 

Dumping and Restoring a Database

This can be done in pgAdmin, but the commands are:

To dump a db:

pg_dump mydb > db.backup

To reload this database:

pg_restore -d DBName db.backup

Working with psql

To connect your psql client to a db type (for localhost don't specify the host):

psql -h host DBName

Useful commands are:

\q Quits

SQL Commands

There is a list of SQL commands that may help.