Tải bản đầy đủ - 0 (trang)
Chapter 18. Introduction to PostgreSQL Administration

Chapter 18. Introduction to PostgreSQL Administration

Tải bản đầy đủ - 0trang

systemandhardware.Youmaywanttochooseacluster

configurationtopreventproblemsintheeventofasinglepoint

offailure.

High-performancemeansthatausershouldbeabletoperform

requiredtaskswithinanacceptableamountoftime.Ahighperformancedatabaseshouldalsofeelresponsive.

Inthischapter,I'llintroduceyoutosomeofthetasksthata

PostgreSQLadministratormustperform.Theremaining

chapterscovereachtopicingreaterdetail.



Security

APostgreSQLadministratorisresponsibleforensuringthat

authorizeduserscandowhattheyneedtodo.Anadministrator

isalsoresponsibleformakingsurethatauthorizeduserscando

onlywhattheyneedtodo.Anothercriticaljobistokeep

intrudersawayfromtheuser'sdata.

TherearetwoaspectstoPostgreSQLsecurityauthenticationand

access.Authenticationensuresthatauserisinfactwhohe

claimstobe.Afteryouaresatisfiedthatauserhasprovenhis

identity,youmustensurethathecanaccessthedatathathe

needs.

Eachuser(orgroup)requiresaccesstoaspecificsetof

resources.Forexample,anaccountingclerkneedsaccessto

vendorandcustomerrecords,butmaynotrequireaccessto

payrolldata.Apayrollclerk,ontheotherhand,needsaccessto

payrolldata,butnottocustomerrecords.Oneofyourjobsas

anadministratoristogranttheproperprivilegestoeachuser.

Anotheraspectofsecurityingeneralistheproblemofsecuring

PostgreSQL'sruntimeenvironment.Dependingonyoursecurity

requirements(thatis,thesensitivityofyourdata),itmaybe

appropriatetoinstallnetworkfirewalls,securerouters,and

possiblyevenbiometricaccesscontrols.Securingyourruntime

environmentisaproblemthatisnotuniquetoPostgreSQL,and

Iwon'texplorethattopicfurtherinthisbook.

Chapter21,"Security,"showsyouhowtograntandrevokeuser

privilegesandalsocovershowtopreventtamperingby

intruders.



UserAccounts

Asanadministrator,youareresponsibleforcreating,

maintaining,anddeletinguseraccounts.Yourfirstchallengewill

bedecidinghowtomaprealpeopleintoPostgreSQLidentities.

OneoptionistohaveeachuserconnecttoPostgreSQLwitha

uniqueidentity.That'susuallyagoodpolicytostartwith,butin

somecircumstancesmaynotbepractical.Forexample,ifyou

arerunningawebsitethatusesPostgreSQLasthebackend

database,youmaynotwanttocreateauniqueuseraccountfor

everypersonwhoconnectstoyourwebsite.Agoodwayto

solvethissortofproblemistocreateuniqueidentitiesforthe

userswhoyouknow,andageneric(oranonymous)identityfor

unknownguests.

Youhavetoknowhowtocreateuseraccountsandusergroups.

Youalsoneedtochooseauthenticationmethods.Exceptinthe

caseofanonymousguestaccounts,youwillwantauserto

provehisorheridentityinsomefashion.PostgreSQLoffers

manyauthenticationmethods,rangingfromtrust(which

meansthatyoutrustthatthehostoperatingsystemhas

alreadyauthenticatedtheuser)topassword-based

authenticationtoKerberosauthentication.Whichauthentication

method(s)youchoosewilldependonhowsensitiveyourdatais

andhowsecureyoufeelthehostenvironmentis.

Chapter19,"GeneralPostgreSQLAdministration,"showsyou

howtomaintainuseraccountsandusergroups.Chapter21,

"Security"showsyouhowtochooseauthenticationmethods.



BackupandRestore

Okay,I'lladmitit.AfewyearsagoIlosttwomonths'worthof

developmentworkwhenmyharddrivecrashed.Ihadnot

backedupmysourcecode.Thatwasapainfullesson.

Fortunately,softwareisalwaysbetterthesecondtimeyou

createit.Thatisnottrueformostdata.Imaginelosingtwo

months'worthofcustomertransactions.

Databasebackupsarecriticallyimportant.Sometypesofdata

canbere-created,butit'susuallyeasiertoloadanarchivetape

thantoremanufacturelostdata.

Youmayalreadyhaveabackupplaninplaceforarchiving

filesystemdata.Thatmaynotbeagoodsolutionforbackingup

datahostedinaPostgreSQLdatabase.Foronething,youmust

shutdownthedatabaseserverifyouchoosetoarchivethe

filesystem.

PostgreSQLprovidesasetofutilitiesthatyoucanuseto

archiveandrestoreindividualtablesorentiredatabases.You

canusetheseutilitiesonaliveserver(thatis,youdon'thave

toshutdownthedatabasefirst).Usingthepg_dumpand

pg_dumpallutilities,youcanalsocompressarchivedataonthe-fly.

Chapter19showsyouhowtousethepg_dumpandpg_dumpall

utilitiesandhowtorecoverdatafromanarchive.

Timeforanotherconfession.Nottoolongago,Ineededto

recoversomecodefromanarchivethathadbeencreatedthe

previousnight.(Yes,Ididsomethingstupid,andtheeasiest

waytoundoitwastorestorefrombackup.)Iwassurprisedto

findthat,eventhoughanarchivehadbeenmadetheprevious

night,IcouldnotreadfromthetapebecauseIhadbeenusing

thewrongcommandstocreatethearchives.It'snotenoughto



haveagoodbackupplantestyourrestoreproceduresaswell.



ServerStartupandShutdown

ThereareavarietyofwaystostartandstopthePostgreSQL

server.Inearlierchapters,youusedthepg_ctlcommandto

performserverstartupandshutdown.pg_ctlisashellscript

thatcontrolsthepostmaster;insomecircumstances,youmay

wanttobypasspg_ctlandinteractdirectlywiththe

postmaster.You'lllearnhowtodothatinthenextchapter.

Inmostcases,youwillwantthepostmastertostartwhenyour

hostsystemboots.You'llalsowantthepostmastertoshut

downgracefullywheneverthehostispowereddown.The

methodyouusetoaccomplishthisvarieswiththehost

operatingsystem.InChapter19,"GeneralPostgreSQL

Administration,"you'lllearnhowtoarrangeforboot-time

startupandgracefulshutdownforafewofthemorecommon

operatingsystems.



Tuning

Chapter4,"Performance,"coveredthebasicsofperformance

analysisandquerytuninginPostgreSQL.Asanadministrator,

youneedtoensurethatyourusersaregettingthebestpossible

performancefromthedatabase.Applicationdevelopersare

usuallyresponsiblefortuningtheinteractionbetweentheir

applicationandthedatabase,buttheadministratoris

responsiblefortheperformanceofthedatabaseasawhole.

PostgreSQLprovidesanumberofconfigurationparametersthat

controlthequeryplannerandoptimizer.Startingwithrelease

7.2,PostgreSQLalsooffersperformance-monitoringtoolsthat

youcanusetowatchforpoorperformancebeforeyourusers

complain.

Ifyouareanadministrator,it'sagoodideatoreviewthe

materialinChapter4.Understandingperformancemonitoring

andtuningwillhelpnarrowyourfocuswhenyouaretracking

downaperformanceproblem.

Youshouldalsoformulateaplanforperiodicroutine

maintenance.Forexample,youdecidethatyoushouldVACUUM

andVACUUMANALYZEalltableseveryweekend.Youmayalso

wanttoCLUSTERimportanttablesonaregularbasis.



InstallingUpdates

ThePostgreSQLdatabaseisconstantlyevolving.Asa

PostgreSQLadministrator,youwilloccasionallyneedtoupgrade

anexistingdatabasetoanewrelease.Fortunately,upgrading

anexistingdatabaseisusuallyasimpleprocess.

Inmostcases,theonlyworkrequiredtomovetoanewrelease

istodumptheentiredatabasecluster(usingpg_dumpall),

installthenewsoftware,andrestorefromthedump.Installing

anewreleasethiswayisnearlyidenticaltoperforminga

backupandrestoreoperation.Forsomeupgradepaths,you

don'tevenneedtodump/restorethenewreleaseincludesa

pg_upgradeutilitythatupgradesyourdatainplace.



Localization

Localizationofteninvolvestheadministrator.Inmany

organizations,youwillfindthatdifferentusersspeakdifferent

languages.AuserwhospeaksFrenchpreferstoseemessages

andhelptextinFrench.AuserwhospeaksGermanprefersto

interactwiththedatabase(asmuchaspossible)usingthe

Germanlanguage.Youalsomightfindthatyouneedtostore

dataincharactersetsotherthanASCII.

PostgreSQLcanaccommodatebothoftheseissues.PostgreSQL

canbelocalizedintodifferentlanguagesanddifferentcultural

preferences.PostgreSQLcanalsostoredatausingavarietyof

characterencoding.Chapter20,

"Internationalization/Localization,"providesanin-depth

discussionoftheissuesinvolvedinprovidinglocalizedaccessto

yourusers.



Summary

ThisshortintroductiontoPostgreSQLadministrationshouldgive

youanoverviewofthetasksthatyoumighthavetoperformas

aPostgreSQLAdministrator.Thenextfewchaptersfillinthe

details.I'llstartbydescribingthealternativesforstartingand

stoppingaPostgreSQLserver.Next,I'llshowyouhowto

manageuseraccounts.ThenI'llmoveontothetopicofbackup

andrestoreprocedures.Laterchapterswillcover

internationalization,localization,andsecurity.



Chapter19.PostgreSQLAdministration

ThischapterexplorestheroleofthePostgreSQLadministrator.

Youstartbylookingattheon-diskorganizationofatypical

PostgreSQLinstallation.Next,you'llseehowtoinstall

PostgreSQLfromsourcecodeorfromprebuiltbinariesonUnix

andWindowshosts.Afterthat,you'lllearnhowtocreatenew

databaseclustersandnewdatabases.Wewillalsotalkabout

managinguseraccountsandmanagingusergroups.Then,you

willseehowtoarrangeforthedatabaseservertostartup

automaticallywhenyoubootyoursystem(andhowtoshut

downgracefullywhenyouhaltyoursystem).We'llfinishthis

chapterbydiscussingyouroptionsforbackupandrecovery.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 18. Introduction to PostgreSQL Administration

Tải bản đầy đủ ngay(0 tr)

×