Installing Postgres from scratch:

Fedora 3/4

install packages downloaded from postgresql web site located in /u2/programs/databases_and_odbc/ on sam (do not use yum install, it will install ancient garbage 5-10 years old)

rpm --install /u2/programs/postgres_and_odbc/postgresql-libs-8.1.3-1PGDG.i686.rpm
rpm --install /u2/programs/postgres_and_odbc/postgresql-devel-8.1.3-1PGDG.i686.rpm
rpm --install /u2/programs/postgres_and_odbc/postgresql-8.1.3-1PGDG.i686.rpm
rpm --install /u2/programs/postgres_and_odbc/postgresql-server-8.1.3-1PGDG.i686.rpm

Debian 3.1

install packages gathered from nowhere ;-) and located in /u2/programs/databases_and_odbc/Debian on sam

dpkg -i --force-all .....deb

set password for system user postgres then use postgres system account for the rest of setup

If /var do not have enough space or not supposed to hold user data create directory somewhere and move /var/lib/pgsql/data and /var/lib/pgsql/backups there.

/etc/init.d/postgresql stop
mkdir /u/Database/postgresql
[root@sam ccdev]# mv /var/lib/pgsql/data /u/Database/postgresql
[root@sam ccdev]# mv /var/lib/pgsql/backups /u/Database/postgresql
[root@sam ccdev]# ln -s /u/Database/postgresql/backups /var/lib/pgsql/backups
[root@sam ccdev]# ln -s /u/Database/postgresql/data /var/lib/pgsql/data
/etc/init.d/postgresql start

create default table if does not exist, try psql without args, if complains:

createdb

set password for default database user postgres:

psql
$alter user postgres password 'sql';
$\q

setup/change identification method

vi /var/lib/pgsql/data/pg_hba.conf 
--change ident to password (unless you have any better idea (for example
--how to use ident service or use encripted passwords ;-)

restart postmaster:

/etc/init.d/postgresql stop
/etc/init.d/postgresql start

Backup/Restore database

Backup database

Optional, to make sure that there are no open session and we will not backup leftover junk:
bash>psql -U ccc dbname
>vacuum analyze freeze #make sure that there are no open session for this company
>\q
cp /ccdev/company_name/*.idx /backup_dir_name/  #copy index files
to dump whole database run 
>pg_dumpall -U username > filename
to dump company run 
>pg_dump -U username  -Fc  -f filename dbname
where username will be db owner or superuser, postgres by default
filename - name of dump file
dbname - name of database to dump (normaly company name lowercase, but can be any, can be found in /etc/odbc.ini,
To dump database into sql asci text (definately not the best for restoring but can be very useful otherwise)
>pg_dump -f /backup_dir_name/dbfile_name.aaa dbname

Restore database

Extended Postgres documentation available on sam:/usr/share/doc/postgresql-8.1.3/html/index.html


CategorySql

PostgresDatabase (last edited 2013-09-18 06:09:34 by localhost)