Add new attachment

Only authorized users are allowed to upload new attachments.

This page (revision-52) was last changed on 10-Sep-2010 17:52 by Maianti Alberto  

This page was created on 14-Apr-2010 14:30 by Administrator

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Difference between version and

At line 1 changed 4 lines
!!Installazione
- Installare i seguenti pacchetti:
- postgresql
- postgresql-server a
!!INSTALLAZIONE
Installare i pacchetti postgresql postgresql-client postgresql-contrib
!!TUNING
Per un tuning di base di postgres si può utilizzare questa utility: [pg-tune|http://pgfoundry.org/projects/pgtune/]
Per una macchina con circa 4GB una configurazione "decente" di postgres potrebbe essere questa:
At line 7 changed 2 lines
rcpostgresql start
chkconfig postgresql on
maintenance_work_mem = 288MB # pgtune wizard 2010-02-24
checkpoint_completion_target = 0.7 # pgtune wizard 2010-02-24
effective_cache_size = 3584MB # pgtune wizard 2010-02-24
work_mem = 24MB # pgtune wizard 2010-02-24
wal_buffers = 4MB # pgtune wizard 2010-02-24
checkpoint_segments = 8 # pgtune wizard 2010-02-24
shared_buffers = 960MB # pgtune wizard 2010-02-24
max_connections = 200 # pgtune wizard 2010-02-24
}}}
/%
At line 10 changed 2 lines
su postgres
psql postgres
Se si aumentano le connessioni e lo shared_buffers di postgres è possibile/probabile che serva aumentare anche la shared memory di linux questo è possibile attraverso questi comandi:
%%prettify
{{{
cp /etc/sysctl.conf /etc/sysctl.conf-orig
vi /etc/sysctl.conf
}}}
/%
Aggiungere la riga con il valore appropriato:
%%prettify
{{{
kernel.shmmax = 104857600
}}}
/%
Salvare il file e far ricaricare i parametri al kernel con:
%%prettify
{{{
sysctl -p
}}}
/%
!!PROBLEMONE SU ENCODING / LOCALE
Attenzione alla creazione del database con ENCODING ISO-8859-1 per caratteri strani:\\
il problema nasce dal fatto che postgres 8.3 non mi fa cambiare il locale del server se non creando un nuovo cluster con il comando:
%%prettify
{{{
# backup configurazione originale
mv /var/lib/postgresql/8.3/main /var/lib/postgresql/8.3/main_original
# mi sposto nella directory ...
cd /usr/lib/postgresql/8.3/bin/
#creo cartella main
mkdir main
#permessi
chown postgres:postgres main -R
#creo nuova configurazione
./initdb --locale=it_IT.ISO-8859-1 -E=LATIN1 -D /var/lib/postgresql/8.3/main
#ricreo link simbolici certificati in /var/lib/postgresql/8.3/main
ln -s /etc/postgresql-common/root.crt root.crt
ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem server.crt
ln -s /etc/ssl/private/ssl-cert-snakeoil.key server.key
#modifico file postgresql.conf
vi /etc/postgresql/8.3/main/postgresql.conf
#Sostituisco UTF8 con ISO-8859-1
....
# These settings are initialized by initdb, but they can be changed.
lc_messages = 'it_IT.ISO-8859-1' # locale for system error message
# strings
lc_monetary = 'it_IT.ISO-8859-1' # locale for monetary formatting
lc_numeric = 'it_IT.ISO-8859-1' # locale for number formatting
lc_time = 'it_IT.ISO-8859-1' # locale for time formatting
....
}}}
riavvio Postgres.
!!CONFIGURAZIONE BASE
{{{
shell di postgress:
su postgres psql postgres
At line 93 added one line
#creare super utente (da valutare)
At line 15 changed one line
CREATE ROLE
#creare utente
At line 17 changed one line
CREATE ROLE
#creare database
At line 19 changed 2 lines
CREATE DATABASE
postgres=
eventualmente per settare encoding diverso (default è UTF-8) usare\\
ENCODING = encoding (ad esempio 'ISO8859-1')
#creare schema
postgres= create schema nomeschema;
#abilitare connessioni in entrata
editare /etc/postgresql/8.3/main/postgresql.conf
listen_addresses = '*'
password_encryption = on
#editare /etc/postgresql/8.3/main/pg_hba.conf (client authentication)
# TYPE DATABASE USER CIDR-ADDRESS METHOD
local database user auth-method [auth-option]
host database user CIDR-address auth-method [auth-option]
hostssl database user CIDR-address auth-method [auth-option]
hostnossl database user CIDR-address auth-method [auth-option]
host database user IP-address IP-mask auth-method [auth-option]
hostssl database user IP-address IP-mask auth-method [auth-option]
hostnossl database user IP-address IP-mask auth-method [auth-option]
#auth-method
trust accetta connessioni senza pwd
reject non accetta connessioni
md5 MD5-encrypted password for authentication
password pwd scambiata in chiaro
krb5 usa kerberos 5 per autenticare il client
ident ottiene il nome utente del sistema operativo dal client e controla se è abilitato alla connessione
ldap autentica usando server LDAP
pam Pluggable Authentication Modules
At line 132 added one line
At line 23 changed one line
settare uno schema(db2prod):
settare uno schema(TUOSCHEMA):
At line 26 changed one line
SET search_path TO db2prod,public;
SET search_path TO TUOSCHEMA,public;
At line 39 changed 2 lines
! Configurazioni
#editare /etc/postgresql/8.3/main/pg_hba.conf ed aggiungere le proprie regole
!!Comandi per backup db
__Dump del db con pg_dump__
At line 43 changed 4 lines
ad esempio per accesso tuo utente:
local all dbuser trust
da che rete:
host all all 192.168.0.0/24 trust
//singola tabella
pg_dump -c -U DBUSER DBNAME --table SCHEMA.TABLE -Fc > dbtable.dump
//intero db di uno schema
pg_dump -c -U DBUSER DBNAME --schema=SCHEMA -Fc > dbschema.dump
//intero db (tutti gli schemi)
pg_dump -c -U DBUSER DBNAME -Fc > dbname.dump
At line 163 added 71 lines
L'opzione -c indica a pg_dump di creare anche le istruzioni per il drop delle tabelle.\\
L'opzione --table serve per indicare di quale tabella fare il backup senza viene fatto il backup dell'intero DB.\\
L'opzione -F serve per il formato output del file (c custom, t tar).\\
L'opzione -U serve a specificare l'utente con il quale ci si collega al DB.\\
Il dump senza -F crea il salvataggio in text plain.
NB Per il restore del db da plainText utilizzare psql non pg_restore che funziona solo per formati custom o tar.
__Restore del db con pg_restore__
''__Solo per formati custom o tar (opzione -Fc o -Ft sul dump)__''\\
%%prettify
{{{
//restore singola tabella
pg_restore -c -U DBUSER -d DBNAME -t TABLE -v -Fc db.dump
ATTENZIONE: sulla singola tabella sembra che non ricrei gli indici (e quindi nemmeno le primary key)
//restore singolo schema
pg_restore -c -U DBUSER -d DBNAME --schema=SCHEMA -v -Fc db.dump
//restore db completo
pg_restore -c -U DBUSER -d DBNAME -Fc db.dump
}}}
L'opzione -c indica a pg_restore di eliminare le tabelle (drop) e ricrearla.\\
L'opzione -v è per il verbose.\\
L'opzione -F serve per il formato input del file (c custom, t tar).\\
L'opzione -d serve per specificare il dbname.\\
L'opzione -v = verbose.\\
L'opzione --data-only è per importare i soli dati e non ricrea table.\\
''__Caso Formato text plain :__''
%%prettify
{{{ psql -U DBUSER DBNAME -f dbname.dump
}}}
!!Import/export di dati
%%prettify
{{{
export da pslq
\f ','
\a
\t
\o outputfile.csv
select ..... (your sql select statement)
\o
import da psql
copy SCHEMA.TABLE from 'TABLE.vsc' using delimiters ',' CSV;
se in fase di import (copy) da comando di linea (psql) ottieni un errore tipo
ERROR: must be superuser to COPY to or from a file
usare da linea di comando linux
cat TUOFILE.csv | psql -U DBUSER -d DBNAME -c "copy SCHEMA.TABLE from stdin delimiter ',' CSV";
}}}
!!Gestione utenti
loggandosi come utente pgsql postgres faccio alter user:
%%prettify
{{{
alter user
}}}
Version Date Modified Size Author Changes ... Change note
52 10-Sep-2010 17:52 7.124 kB Maianti Alberto to previous
51 10-Sep-2010 17:51 7.084 kB Maianti Alberto to previous | to last
50 10-Sep-2010 17:50 7.176 kB Maianti Alberto to previous | to last
49 14-Apr-2010 14:30 5.957 kB RaffaelePedrini to previous | to last
48 14-Apr-2010 14:30 5.694 kB RaffaelePedrini to previous | to last
47 14-Apr-2010 14:30 5.564 kB RaffaelePedrini to previous | to last
46 14-Apr-2010 14:30 5.555 kB RaffaelePedrini to previous | to last
45 14-Apr-2010 14:30 5.441 kB RaffaelePedrini to previous | to last
44 14-Apr-2010 14:30 5.52 kB RaffaelePedrini to previous | to last
43 14-Apr-2010 14:30 5.145 kB RaffaelePedrini to previous | to last
42 14-Apr-2010 14:30 4.95 kB RaffaelePedrini to previous | to last
41 14-Apr-2010 14:30 4.949 kB RaffaelePedrini to previous | to last
« This page (revision-52) was last changed on 10-Sep-2010 17:52 by Maianti Alberto