GentooPostgreSQL Guide.docx
- 文档编号:23473192
- 上传时间:2023-05-17
- 格式:DOCX
- 页数:14
- 大小:21.21KB
GentooPostgreSQL Guide.docx
《GentooPostgreSQL Guide.docx》由会员分享,可在线阅读,更多相关《GentooPostgreSQL Guide.docx(14页珍藏版)》请在冰豆网上搜索。
GentooPostgreSQLGuide
PostgreSQLGuide
窗体顶端
Content:
窗体底端
1. Introduction
PostgreSQLintroduction
Whentalkingtomostdevelopersaboutthedifferentdatabasesolutionstouse,twomajordatabaseswillusuallyformtheanswer.OnewouldbeMySQL,andtheotheriswhatthisdocumentwillreferto,PostgreSQL.Theadvantagesofoneovertheotherisasomewhatlongwindeddebate,howeveritisjusttosaythatPostgreSQLhashadamorefirmgraspontruerelationaldatabasestructurethanMySQL.MostofthestandardfeaturessuchasFOREIGNKEYwasonlyjustaddedinMySQL5.However,whateverthecasemaybe,thisdocumentassumesthatyouhaveselectedPostgreSQLasthedatabasetouse.Thefirstplacetostartistheemergeprocess.Inthenextsection,theinstallationprocessthroughemergewillbedescribed,aswellasthebasicconfiguration.
PostgreSQLinstallation
Tobegin,wemustfirstemergethePostgreSQLpackage.Todoso,runthefollowingcodetofirstensurethattheoptionsforitareproperlyset:
CodeListing 1.1:
CheckingthePostgreSQLbuildoptions
#emerge-pvpostgresql
ThesearethepackagesthatIwouldmerge,inorder:
Calculatingdependencies...done!
[ebuildN]dev-db/postgresql-8.0.4-doc-kerberos+nls+pam+perl-pg-intdatetime+python+readline(-selinux)+ssl-tcl+xml+zlib0kB
Here'salistofwhatthedifferentbuildoptionsindicate:
USEFlag
Meaning
doc
ThisUSEflagenablesordisablestheinstallationofdocumentationoutsideofthestandardmanpages.Theonegoodtimetodisablethisoptionisifyouarelowonspace,oryouhavealternatemethodsofgettingaholdofthedocumentation(online,etc.)
kerberos
Whenconnectingtothedatabase,withthisoptionenabled,theadminhastheoptionofusingkerberostoauthenticatetheirusers/servicestothedatabase.
nls
Ifthisoptionisenabled,PostgreSQLcanutilizetranslatedstringsfornon-Englishspeakingusers.
pam
Ifthisoptionisenabled,andtheadminconfiguresthePostgreSQLconfigurationfileproperly,users/serviceswillbeabletologintoaPostgreSQLdatabaseusingPAM(PluggableAuthenticationModule).
perl
Ifthisoptionisenabled,perlbindingsforPostgreSQLwillbebuilt.
pg-intdatetime
Ifthisoptionisenabled,PostgreSQLwillsupport64bitintegerdatetypes.
python
Ifthisoptionisenabled,PostgreSQLwillbebuiltwithpythonbindings.
readline
Ifthisoptionisenabled,PostgreSQLwillsupportreadlinestylecommandlineediting.Thisincludescommandhistoryandisearch.
selinux
Ifthisoptionisenabled,anselinuxpolicyforPostgreSQLwillbeinstalled.
ssl
Ifthisoptionisenabled,PostgreSQLwillutilizetheOpenSSLlibrarytoencrypttrafficbetweenPostgreSQLclientsandservers.
tcl
Ifthisoptionisenabled,PostgreSQLwillbuildtclbindings.
xml
Ifthisoptionisenabled,XPATHstylexmlsupportwillbebuilt.MoreinformationonusingxmlsupportwithPostgreSQLcanbefoundon:
PostgreSQLandXML.
zlib
Thisisn'treallyusedbyPostgreSQLitself,butbypg_dumptocompressthedumpsitproduces.
Onceyou'vecustomizedPostgreSQLtomeetyourspecificneeds,goaheadandstarttheemerge:
CodeListing 1.2:
Emerge-ingPostgreSQL
#emergepostgresql
(Outputshortened)
>>>/usr/lib/libecpg.so.5->libecpg.so.5.0
>>>/usr/bin/postmaster->postgres
*Makesurethepostgresuserin/etc/passwdhasanaccountsetupwith/bin/bashastheshell
*
*Executethefollowingcommand
*emerge--config=postgresql-8.0.4
*tosetuptheinitialdatabaseenvironment.
*
>>>Regenerating/etc/ld.so.cache...
>>>dev-db/postgresql-8.0.4merged.
Asshownbytheeinfooutput,thereissomepostsetupthatmustbedone.ThenextchapterwilllookattheactualconfigurationofPostgreSQL.
2. PostgreSQLconfiguration
Settinguptheinitialdatabaseenvironment
Asnotedintheearlieremergeoutput,theinitialdatabaseenvironmentmustbesetup.However,beforethisisdone,onethingneedstobeconsidered.Unlike,sayMySQL,PostgreSQL's"root"passwordisthepasswordoftheactualuser.However,onlytheuseriscreatedbytheebuildnotthepassword.Sobeforewecanbegin,thepasswordmustbesetforthepostgresuser:
CodeListing 2.1:
Settingthepassword
#passwdpostgres
NewUNIXpassword:
RetypenewUNIXpassword:
passwd:
passwordupdatedsuccessfully
Nowthatthisissetup,thecreationoftheinitialdatabaseenvironmentcanoccur:
CodeListing 2.2:
Configuringthedatabaseenvironmentwithemerge--config
#emerge--config=postgresql-8.0.4
Configuringpkg...
*Creatingthedatadirectory...
*Initializingthedatabase...
Thefilesbelongingtothisdatabasesystemwillbeownedbyuser"postgres".
Thisusermustalsoowntheserverprocess.
ThedatabaseclusterwillbeinitializedwithlocaleC.
fixingpermissionsonexistingdirectory/var/lib/postgresql/data...ok
creatingdirectory/var/lib/postgresql/data/global...ok
creatingdirectory/var/lib/postgresql/data/pg_xlog...ok
creatingdirectory/var/lib/postgresql/data/pg_xlog/archive_status...ok
creatingdirectory/var/lib/postgresql/data/pg_clog...ok
creatingdirectory/var/lib/postgresql/data/pg_subtrans...ok
creatingdirectory/var/lib/postgresql/data/base...ok
creatingdirectory/var/lib/postgresql/data/base/1...ok
creatingdirectory/var/lib/postgresql/data/pg_tblspc...ok
selectingdefaultmax_connections...100
selectingdefaultshared_buffers...1000
creatingconfigurationfiles...ok
creatingtemplate1databasein/var/lib/postgresql/data/base/1...ok
initializingpg_shadow...ok
enablingunlimitedrowsizeforsystemtables...ok
initializingpg_depend...ok
creatingsystemviews...ok
loadingpg_description...ok
creatingconversions...ok
settingprivilegesonbuilt-inobjects...ok
creatinginformationschema...ok
vacuumingdatabasetemplate1...ok
copyingtemplate1totemplate0...ok
WARNING:
enabling"trust"authenticationforlocalconnections
Youcanchangethisbyeditingpg_hba.conforusingthe-Aoptionthe
nexttimeyouruninitdb.
Success.Youcannowstartthedatabaseserverusing:
/usr/bin/postmaster-D/var/lib/postgresql/data
or
/usr/bin/pg_ctl-D/var/lib/postgresql/data-llogfilestart
*
*Youcanuse/etc/init.d/postgresqlscripttorunPostgreSQLinsteadofpg_ctl.
*
Nowtheinitialdatabaseenvironmentissetup.Thenextsectionwilllookatverifyingtheinstallandsettingupuserstoaccessthedatabase.
PostgreSQLdatabasesetup
NowthatPostgreSQLissetup,it'sagoodideaatthispointtoverifytheinstallation.First,makesuretheservicestartsupok:
CodeListing 2.3:
StartingupthePostgreSQLservice
#/etc/init.d/postgresqlstart
*StartingPostgreSQL...[ok]
Oncethisisverifiedworking,it'salsoagoodideatoaddittothedefaultrunlevelsoitstartsatboot:
CodeListing 2.4:
Addingtothedefaultrunlevel
#rc-updateaddpostgresqldefault
*postgresqladdedtorunleveldefault
Nowthattheservicehasstarted,it'stimetotrysettingupatestdatabase.Tostartout,let'screateatestdatabasebyusingthecreatedbcommand.We'llalsopassalongthe-Uoptiontosettheuser(itdefaultstothecurrentusernameifyoudon't),andthe-Woptiontorequestthepasswordwecreatedearlier.Finallywegiveitthenameofthedatabasewewanttocreate:
CodeListing 2.5:
Creatingadatabasewithcreatedb
$createdb-Upostgres-Wtest
Password:
CREATEDATABASE
Thedatabasewassuccessfullycreated,andwecanconfirmthatthedatabasecanrunbasictasks.We'llgoaheadanddropthisdatabase(removeit)withthedropdbcommand:
CodeListing 2.6:
Droppingadatabasewithdropdb
$dropdb-Upostgres-Wtest
Password:
DROPDATABASE
Rightnow,onlythepostgresusercanruncommands.Obviouslythisisnotthesortofsetuponewouldlikeinamulti-userenvironment.Thenextsectionwilllookatworkingwithuseraccounts.
Settingupdatabaseuseraccounts
Asmentionedearlier,havingtologinasthepostgresuserissomewhatundesirableinamult-userenvironment.Inmostcasestherewillbevarioususersandservicesaccessingtheserver,andeachhavedifferentpermissionrequirements.So,tohandlethis,thecreateusercommandcanbeused.ThiscommandisanalternativetorunningafewSQLqueries,andisalotmoreflexiblefromanadminstandpoint.We'llgoaheadandcreatetwousers,a'superuser'thatcanaddotherusersandadministerthedb,andastandarduser:
CodeListing 2.7:
Settingupthesuperuser
(replacechriswiththeusernameyou'dliketouse)
$createuser-a-d-P-E-Upostgres-Wchris
Enterpasswordfornewuser:
Enteritagain:
Password:
CREATEUSER
There,we'vecreatedthesuperuser.Thecommandlineoption-aspecifiesthatthisusercanaddotherusers.-dmeansthatthisusercancreatedatabases.-Plet'syouenterapasswordfortheuserand-Ewillencryptitforsecuritypurposes.Nowthen,we'lltestthisnewuser'spermissionsoutbysettingupourstandarduser:
CodeListing 2.8:
Settingupthestandarduser
(replacechriswiththeusernameyou'vejustcreated)
$createuser-A-D-P-E-Uchris-Wtestuser
Enterpasswordfornewuser:
Enteritagain:
Password:
CREATEUSER
Success!
Ournewuserwascreatedusingthepreviouslycreatedsuperuser.The-Aand-Doptionsdotheoppositeof-aand-d,andinsteaddenytheusertheabilitytocreateotherusersanddatabases.Nowthatthereareuserstoworkwith,thenextchapterwilllookatusingthenewdatabase.
3. UsingPostgreSQL
Settinguppermissions
Nowthereisauserthatcancreatedatabasesandaddotherusers,andthemainpostgresuserthatcandoanything.Theusercreatedearliercancurrentlylogintotheserver,andthat
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- GentooPostgreSQL Guide