Podstawy administracji Bazami danych – PostgresSQL

Założenia

System operacyjy Centos, RHEL 5 lub 6

Baza PostgreSQL 8 lub 9

Instalacja

Najprostszym (i IMO najlepszym) rozwiązaniem jest skorzystanie z gotowych pakietów rpm zawierających repozytoria YUMa dla kilku popularnych dystrybucji (Centos, RHEL, Fedora, Scientific Linux).

Wchodzimy na strone: http://yum.postgresql.org/repopackages.php, wybieramy pakiet dla naszej dystrybucji,w moim przypadku bÄ™dzie to:http://yum.postgresql.org/9.1/redhat/rhel-5-i386/pgdg-centos91-9.1-4.noarch.rpm, pakiet instalujemy poleceniem rpm -Uvh nazwa_pakietu

rpm -Uvh pgdg-centos91-9.1-4.noarch.rpm
Przygotowywanie…          ########################################### [100%]

1:pgdg-centos91
########################################### [100%]

Mamy juz zainstalowane repozytoria z pakietami dla postgresa. teraz instalujemy sam serwer postgersa.

yum install postgresql91-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: sunsite.icm.edu.pl
* epel: ftp.icm.edu.pl
* extras: sunsite.icm.edu.pl
* updates: sunsite.icm.edu.pl
Setting up Install Process
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
–> Running transaction check
—> Package postgresql91-server.i386 0:9.1.3-1PGDG.rhel5 set to be updated
–> Processing Dependency: postgresql91 = 9.1.3-1PGDG.rhel5 for package: postgresql91-server
–> Running transaction check
—> Package postgresql91.i386 0:9.1.3-1PGDG.rhel5 set to be updated
–> Processing Dependency: postgresql91-libs = 9.1.3-1PGDG.rhel5 for package: postgresql91
–> Running transaction check
—> Package postgresql91-libs.i386 0:9.1.3-1PGDG.rhel5 set to be updated
–> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================================================================
Package                                                    Arch                                        Version                                                  Repository                                     Size
=====================================================================================================================================================================================================================
Installing:
postgresql91-server                                        i386                                        9.1.3-1PGDG.rhel5                                        pgdg91                                        5.2 M
Installing for dependencies:
postgresql91                                               i386                                        9.1.3-1PGDG.rhel5                                        pgdg91                                        1.6 M
postgresql91-libs                                          i386                                        9.1.3-1PGDG.rhel5                                        pgdg91                                        218 k

Transaction Summary
=====================================================================================================================================================================================================================
Install       3 Package(s)
Upgrade       0 Package(s)

Total download size: 7.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): postgresql91-libs-9.1.3-1PGDG.rhel5.i386.rpm                                                                                                                                           | 218 kB     00:00
(2/3): postgresql91-9.1.3-1PGDG.rhel5.i386.rpm                                                                                                                                                | 1.6 MB     00:02
(3/3): postgresql91-server-9.1.3-1PGDG.rhel5.i386.rpm                                                                                                                                         | 5.2 MB     00:07
———————————————————————————————————————————————————————————————————————
Total                                                                                                                                                                                636 kB/s | 7.0 MB     00:11
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : postgresql91-libs                                                                                                                                                                             1/3
Installing     : postgresql91                                                                                                                                                                                  2/3
Installing     : postgresql91-server                                                                                                                                                                           3/3

Installed:
postgresql91-server.i386 0:9.1.3-1PGDG.rhel5

Dependency Installed:
postgresql91.i386 0:9.1.3-1PGDG.rhel5                                                                  postgresql91-libs.i386 0:9.1.3-1PGDG.rhel5

Complete!

Konfiguracja

Na początku trzeba zainicjować  bazę danych

/etc/init.d/postgresql-9.1 initdb

Inicjowanie bazy danych:                                   [  OK  ]

Edytujemy plik /var/lib/pgsql/9.1/data/pg_hba.conf i zmieniamy linie

host    all             all             127.0.0.1/32            ident

na

host    all             all             127.0.0.1/32            md5

I tak samo będziemy musieli zrobić z każdym ip, który będziemy się logować‚ do tego serwera.

Start bazy:

/etc/init.d/postgresql-9.1 start

Uruchamianie usługi postgresql-9.1:                        [  OK  ]

Zakłaadanie użytkownika

W shellu przechodzimy na użytkownika postgres

su - postgres

i wydajemy polecenie

createuser -P nazwa_uzytkownika

Zakładanie bazy

W shellu przechodzimy na użytkownika postgres

su - postgres

i wydajemy polecenie

createdb -O nazwa_uzytkownika nazwa_bazy

Logowanie

W shellu przechodzimy na użytkownika postgres

su - postgres

i wydajemy polecenie

psql -U nazwa_uzytkownika -h 127.0.0.1 nazwa_bazy

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *