Postgresql

From Elvanör's Technical Wiki
Revision as of 17:22, 2 October 2009 by Elvanor (talk | contribs)
Jump to navigation Jump to search

Installation on Gentoo

  • The ebuilds that should be used are dev-db/postgresql-server-*, since they are newer and modularized instead of monolithic (old ebuilds are dev-db/postgresql).
  • There can be a problem with the postgres USE flag of php. It can pull in libpq which would block the modularized postgresql-server package. The solution is to build postgresql-server first (removing libpq if already installed), then rebuild PHP. This will probably be done automatically once postgresql-server is stabilized.
  • Similarly you need a version of psycopg (Python driver for Postgresql) that does not depend on libpq (2.0.10 is fine but unstable at the time of this writing).

Initial configuration

  • By default on Gentoo the socket file (on /var/run/postgresql directory) allows only reading (and writing) to the postgres user. This means that other users (like apache via mod_php) cannot connect to the DB via the UNIX socket. This implies that to make phppgadmin works (for instance) you have to explicitely write "localhost" as the server name in the configuration file.
  • This means also that if you want to give commands when using another user, never forget to add the -h localhost option (which will prevent the use of the local socket and will use TCP).

Updating

  • You should dump the tables *before* you upgrade to another version (for example from 8.3 to 8.4). You can then restore the tables in the new version - but the initial dump should be done on the previous one.

Management

  • Use the following command to copy a database to another one in the same server (the source DB must NOT be used):
create database newdb template olddb;

This is a Postgresql command, not standard SQL.

  • The following command (shell program) will create a database (using the openerp user):
createdb -U openerp new_db_name
  • You can drop via dropdb.