CentOS 6.5安裝與配置PostgreSQL9.2

來源:互聯網
上載者:User

標籤:切換使用者   成功   add   gpo   password   itdb   最新   su -   com   

參考:http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html

 

1、這裡採用yum安裝測試

使用PostgreSQL Yum Repository 來安裝最新版本的PostgreSQL。

[[email protected] ~]# rpm -i http://download.postgresql.org/pub/repos/yum/9.2/redhat/rhel-6.5-x86_64/pgdg-redhat92-9.2-8.noarch.rpm

[[email protected] ~]# yum install postgresql92-server postgresql92-contrib

[[email protected] ~]# rpm -qa |grep postgresql 查看安裝

[[email protected] ~]# useradd postgres 建立啟動使用者

[[email protected] ~]# /etc/init.d/postgresql-9.2 initdb 初始化並啟動資料庫

[[email protected] ~]# su - postgres 切換使用者

[[email protected] ~]$ psql -l 查看錶

資料庫列表

名稱 | 擁有者 | 字元編碼 | 校對規則 | Ctype | 存取許可權

-----------+----------+----------+-------------+-------------+-----------------------

postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |

template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +

| | | | | postgres=CTc/postgres

template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +

| | | | | postgres=CTc/postgres

(3 行記錄)

 

2、建立資料庫並授權

參考:https://www.2cto.com/database/201708/671319.html

[[email protected] ~]$ psql 登入

psql (9.2.24)

輸入 "help" 來擷取協助資訊.

postgres=# alter user postgres with password ‘postgres‘; 修改postgre的密碼

postgres=# CREATE DATABASE sina OWNER postgres; 建立資料庫提示:CREATE DATABASE

postgres=# GRANT ALL PRIVILEGES ON DATABASE sina to postgres; 授權成功提示:GRANT

postgres=# \q 退出

[[email protected] ~]$

[[email protected] ~]$ psql -U postgres -d sina -h 127.0.0.1 -p 5432 登入測試

使用者 postgres 的口令:

psql (9.2.24)

輸入 "help" 來擷取協助資訊.

sina=# \l

 

3、開啟遠端連線:

參考:http://www.cnblogs.com/jevonsea/archive/2013/01/24/2874184.html

修改2個設定檔

[[email protected] ~]# vim /var/lib/pgsql/9.2/data/postgresql.conf

將該檔案中的listen_addresses項值設定為“*”。

[[email protected] ~]# vim /var/lib/pgsql/9.2/data/pg_hba.conf

在該設定檔的host all all 127.0.0.1/32 md5行下添加以下配置,或者直接將這一行修改為以下配置

host all all 0.0.0.0/0 md5

如果不希望允許所有IP遠端存取,則可以將上述配置項中的0.0.0.0設定為特定的IP值。

 

4、基本建庫建表操作

參考:http://www.yiibai.com/html/postgresql/2013/080439.html

建立表語句的基本文法如下:

CREATE TABLE DEPARTMENT( ID INT PRIMARY KEY NOT NULL, DEPT CHAR(50) NOT NULL, EMP_ID INT NOT NULL );

  

CentOS 6.5安裝與配置PostgreSQL9.2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.