Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6666430
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Mysql/postgreSQL

2017-06-25 19:49:16

环境:
OS:CentOS-7
DB:9.5

1.下载
二进制版本下载地址:
对应相应的操作系统下载相应的版本
我这里下载的是postgresql-9.5.7-1-linux-x64-binaries.tar.gz

2.创建Postgres用户
[root@redis01 soft]# useradd postgres 
[root@redis01 soft]# passwd postgres

3.解压缩
[root@redis01 soft]# tar  -zxvf postgresql-9.5.7-1-linux-x64-binaries.tar.gz
[root@redis01 soft]# mv pgsql /opt/

4.创建数据库目录
[root@redis01 9.5]# mkdir -p /opt/pgsql/9.5/data

5.更改目录权限
[root@redis01 opt]# chown -R postgres:postgres /opt/pgsql

6.切换到postgrep用户添加环境变量
vim ~/.bash_profile
export PG_HOME=/opt/pgsql
export PGDATA=/opt/pgsql/9.5/data
export PATH=$PATH:$PG_HOME/bin

7.初始化数据库
[postgres@redis01 bin]$ su - postgres
[postgres@redis01 bin]$ cd /opt/pgsql/bin
[postgres@redis01 bin]$./initdb -D /opt/pgsql/9.5/data

[postgres@redis01 bin]$ ./initdb -D /opt/pgsql/9.5/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /opt/pgsql/9.5/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /opt/pgsql/9.5/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok


WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.


Success. You can now start the database server using:

    ./pg_ctl -D /opt/pgsql/9.5/data -l logfile start

8.启动数据库
[postgres@redis01 9.5]$ cd /opt/pgsql/9.5
[postgres@redis01 9.5]$ mkdir logs
[postgres@redis01 bin]$ cd /opt/pgsql/bin
[postgres@redis01 bin]$ ./pg_ctl -D /opt/pgsql/9.5/data -l /opt/pgsql/9.5/logs/postgres.log start

9.修改postgres用户的访问密码并测试建库建表
PostgreSQL 数据库默认会创建一个postgres的数据库用户作为数据库的管理员,默认密码为空,我们需要修改为指定的密码,这里设定为postgres.
su - postgres
psql
# ALTER USER postgres WITH PASSWORD 'postgres';
# select * from pg_shadow ;
# create database hxl;
# \c hxl

project=# create table person(id integer, name text);
project=# insert into person values (1, 'hxl');
project=# select * from person;

10.配置postgresql允许远程访问
只需要修改data目录下的pg_hba.conf和postgresql.conf这两个文件:
pg_hba.conf:配置对数据库的访问权限;
postgresql.conf:配置PostgreSQL数据库服务器的相应的参数

vim /opt/pgsql/9.5/data/pg_hba.conf
找到IPv4添加如下两项
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0               md5


重新加载配置文件
su - postgres
pg_ctl reload

修改postgresql.conf
vim /opt/pgsql/9.5/data/postgresql.conf

listen_addresses = '*'   # what IP address(es) to listen on;


-- The End --
阅读(3051) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~