CentOS 6.5安装与配置PostgreSQL9.2
參考:http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html
?
1、這里采用yum安裝測試
使用PostgreSQL Yum Repository 來安裝最新版本的PostgreSQL。
[root@test-slave ~]# rpm -i http://download.postgresql.org/pub/repos/yum/9.2/redhat/rhel-6.5-x86_64/pgdg-redhat92-9.2-8.noarch.rpm
[root@test-slave ~]# yum install postgresql92-server postgresql92-contrib
[root@test-slave ~]# rpm -qa |grep postgresql 查看安裝
[root@test-slave ~]# useradd postgres 創建啟動用戶
[root@test-slave ~]# /etc/init.d/postgresql-9.2 initdb 初始化并啟動數據庫
[root@test-slave ~]# su - postgres 切換用戶
[postgres@test-slave ~]$ 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
[postgres@test-slave ~]$ 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 退出
[postgres@test-slave ~]$
[postgres@test-slave ~]$ 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個配置文件
[root@test-slave ~]# vim /var/lib/pgsql/9.2/data/postgresql.conf
將該文件中的listen_addresses項值設定為“*”。
[root@test-slave ~]# 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 );
??
轉載于:https://www.cnblogs.com/sunnyyangwang/p/8053085.html
總結
以上是生活随笔為你收集整理的CentOS 6.5安装与配置PostgreSQL9.2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: npm打包前端项目太慢问题分析以及暂时解
- 下一篇: [译]NectarJS:编译JavaSc