Translations of this page?:

Postgres

Installation

  • On windows install using installer or unpack zip and manually initialize cluster and setup service
  • On OpenBSD use pkg_add postgresql 1)
  • When installing PostgreSQL always select UTF-8 or Latin1 as default encoding 2)
  • each database can have its own encoding, but changing default 7-bit C_ASCII encoding for a server or existing database is a pain.

Documentation

Initialization

  • Before you can do anything you need to initialize the catalog cluster (and asign super user password):
    • initdb -D c:\postgresql\8.4\data -U postgres -W3)
    • make sure the postgres service user has write/modify access to the data folder
  • Then add the following:
    • pg_hba.conf: host all all 0.0.0.0/0 md5
    • postgresql.conf: uncomment connection settings (listen_addresses = '*', port = 5432, max_connections = 100)

How to reset lost Superuser password

  • see this blog post (at the bottom)
  • Assuming that your superuser role name is 'postgres' do this
    • add the following to pg_hba.conf: local all postgres trust and restart postgres
    • login locally as psql -U postgres -d template1
    • run alter user postgres with encrypted password 'newpass';
    • remove line from pg_hba.conf and restart.
  • if you don't know your superuser name add local all all trust and create new user instead.

Windows Service

  • pg_ctl register [ -N servicename ] [ -U username ] [ -P password ] [ -D datadir ] [ -w ] [ -o options ]
  • pg_ctl unregister [ -N servicename ]

Couldn't install it with -U/P so had to do this and then change service properties and add description via registry (see below):

  • pg_ctl register -N Postgres-8.4 -D C:\PostgreSQL\8.4\data

Configuration

Backup

  • create pgpass.conf file under profile of the user who will be running the script
    • e.g. c:\Documents and Settings\username.domain\Application Data\postgresql\pgpass.conf
    • localhost:5432:*:postgres:XXXXXXXXXXX
      
  • create backup script
    • pg_dumpall.exe -U postgres -h localhost -p 5432 -c -o  | gzip > c:\backup\postgres_alldb.bak.gz
      xcopy /y c:\backup\postgres_alldb.bak.gz \\backup\db\hostname\postgres\
      
  • for individual databases use pg_dump
  • pg_dump.exe -i -h localhost -p 5432 -F t -b -v -f "c:\backup\dbname.backup" dbname
    gzip -f dbname.backup
    xcopy /y c:\backup\dbname.backup.gz \\backup\db\hostname\postgres\
    
  • see also

« start

1) or postgresql-client postgresql-server
2) Latin1 should be fine for defaults because our database work only with 8-bit character data
3) if you don't specify -U option superuser name will be the name of the user running initdb!
 
postgres.txt · Last modified: 2009/08/06 19:14 by Alex Popov
 
Except where otherwise noted, content on this wiki is licensed under the following license:Public Domain
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki