intall postgresql 9.1 on CentOS

http://people.planetpostgresql.org/devrim/index.php?/archives/48-What-is-new-in-PostgreSQL-9.0-RPMs.html php

# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpmhtml

Important note: In order to use PGDG repository properly, you may need to exclude postgresql packages from the repository of the distro. Here are the steps:     As root, cd /etc/yum.repos.d     Edit distro's .repo file:         On Fedora, edit fedora.repo and fedora-updates.repo, [fedora] sections         On CentOS, edit CentOS-Base.repo, [base] and [updates] sections.         On Red Hat, edit edit /etc/yum/pluginconf.d/rhnplugin.conf [main] section.     Add     exclude=postgresql*     to the bottom of the section. That is enough for excluding distro packages. CentOS6: X64 rpm -ivh http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-4.noarch.rpm i386 rpm -ivh http://yum.pgrpms.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpm CentOS5 rpm -ivh http://yum.pgrpms.org/9.1/redhat/rhel-5.0-i386/pgdg-centos91-9.1-4.noarch.rpm yum install postgresql91 postgresql91-libs postgresql91-contrib postgresql91-devel postgresql91-test yum update libevent compat-libevent14 若是是經過EPEL安裝的pg9.1可把路徑添加到環境變量中修改 ~/.bash_profile: PATH=$PATH:$HOME/bin:/usr/pgsql-9.1/bin 初始化pgsql: # sudo -u postgres /usr/pgsql-9.1/bin/initdb -E utf8 --locale=zh_CN.UTF8 /data1/pgsql91/data 或者 # su postgres # initdb -E utf8 --locale=C -D /usr/local/pgsql/data # /usr/pgsql-9.1/bin/initdb -E utf8 --locale=zh_CN.UTF8 -D /var/lib/pgsql/9.1/data    #或者 2. 啓動數據庫 i參數容許遠程鏈接,或者修改 /pgsql/data/postgresql.conf 修改listen #service postgresql start $pg_ctl -o "-i" -D /usr/local/pgsql/data -l logfile start $postgres -D /usr/local/pgsql/data -i & #pg_ctl -o "-i" -D /usr/local/pgsql/data -l logfile start 3. 修改管理員口令 $ sudo -upostgres psql -U postgres postgres=# ALTER USER postgres WITH PASSWORD 'new-passwd'; 3.建立用戶 管理員用戶 bash> createuser -Ps issence -U postgres bash> createuser -APRS chery -U postgres 嚮導添加用戶命令格式 createuser 是 SQL 命令 CREATE USER的封裝。 命令:createuser [-a] [-A] [-d] [-D] [-e] [-P] [-h 主機名] [-p port] 用戶名 參數說明: shell>sudo -upostgres createuser -P issence [-a]:容許建立其餘用戶,至關於建立一個超級用戶; [-A]:不容許此用戶建立其餘用戶; [-d]:容許此用戶建立數據庫; [-D]:不容許此用戶建立數據庫; [-e]:將執行過程顯示到Shell上; [-P]:建立用戶時,同時設置密碼; [-h 主機名]:爲某個主機上的Postgres建立用戶; [-p port]:與-h參數一同使用,指定主機的端口。 -r, --createrole          role can create new roles -R, --no-createrole       role cannot create roles -s, --superuser           role will be superuser -S, --no-superuser        role will not be superuser  PostgreSQL 建立賬號,數據庫,權限 建立用戶 issence,密碼 pass,建立數據庫 db_name,賦予 issence 在 數據庫db_name 上的全部權限(只有這3個create,tmp, connect)。 # su postgres $ psql postgres# CREATE USER issence WITH PASSWORD 'pass'; postgres# CREATE DATABASE db_name; postgres# GRANT ALL ON DATABASE db_name TO issence; postgres# GRANT SELECT,UPDATE ON tb_table TO mark;        # 授予表權限(select,update,insert,drop...)給某用戶,一次只能一個表 postgres# REVOKE SELECT ON tb_table FROM mark;    # 取消用戶的表權限(select,update,insert,drop...) postgres# GRANT CONNECT ON DATABASE db_name TO PUBLIC; 更改數據庫用戶口令: postgres=# ALTER USER hm WITH PASSWORD 'xx'; 建立數據庫: createdb and createuser 在後面都必須加上用戶名,若是不加的話psql會認爲你登陸系統的名字就是執行這個操做的用戶 除非當前是 su postgres, 若是在初始化集羣時已經設置默認編碼則這兒能夠省略: # createdb db_test -U postgres -O issence shell> createdb db_test -O issence 或者pg命令行 postgres=# CREATE DATABASE mychery OWNER = issence; # createdb db_test -U postgres -E UTF8 --locale=zh_CN.UTF8 shell> createdb db_macro -E utf8 --locale=zh_CN.UTF8  --owner=issence -Upostgres 管上述哪一種方法都只能獲得部分恢復了的數據庫。另外,你能夠將整個恢復過程當成一個單獨的事務,這樣就可以保證要麼所有恢復成功, 要麼所有回滾。能夠經過向 psql 傳遞 -1 或 --single-transaction 命令行參數達到此目的。 使用這個模式的時候即便一個很微小的錯誤也將致使已經運行了好幾個小時的恢復過程回滾。儘管如此,這種模式也比手動清除哪些不完整的恢復數據強。 psql -Uissence dbname < infile 恢復: # gzip -cd db.sql.gz | psql -1 -Upostgres -d newdb -f - # gzip -dc mychery-20111213.sql.gz | psql -Upostgres -d uc - 5. 建立數據庫 在PostgreSQL服務啓動後,使用postgres用戶即可以成功的運行psql命令鏈接數據庫了。 可是這時候使用其餘Linux用戶仍然不可以使用psql進入PostgreSQL數據庫,會出現以下錯誤: psql: FATAL: Ident authentication failed for user "postgres" 這是由於PostgreSQL數據庫安裝的時候只建立了一個數據庫用戶postgres,默認密碼爲空。(注意這裏的postgres是數據庫用戶,跟Linux系統用戶是兩個概念) 並且默認的鑑權策略是"ident"鑑權,即默認配置下只有使用postgres系統用戶纔可使用postgres數據庫用戶來登錄。 咱們須要把鑑權方式改成密碼鑑權。 首先編輯 /usr/local/pgsql/data/pg_hba.conf,作以下修改: 把其中全部的"ident sameuser"更改成md5(即便用md5密碼加密鑑權)而且遠程鏈接時只容許數據庫hm用戶 host    all         hm         0.0.0.0/0           md5 重啓服務: #service postgresql restart #/etc/init.d/postgresql-9.1 restart $pg_ctl  -D /usr/local/pgsql/data reload $pg_ctl  -D /usr/local/pgsql/data restart 使用pg_restore -j參數並行恢復,pg_dump備份必須使用參數Fc. -j不能和-1參數同時使用 pg_dump mychery -Ft > mychery.dump pg_restore -d mychery -j5 mychery.dump
相關文章
相關標籤/搜索